Search in sources :

Example 6 with MetricsDuration

use of org.pentaho.di.core.metrics.MetricsDuration in project pentaho-kettle by pentaho.

the class TransMetricsDelegate method refreshImage.

private void refreshImage(GC canvasGc) {
    List<MetricsDuration> durations = MetricsUtil.getAllDurations(transGraph.trans.getLogChannelId());
    if (Utils.isEmpty(durations)) {
        // In case of an empty durations or null there is nothing to draw
        return;
    }
    // Sort the metrics.
    Collections.sort(durations, new Comparator<MetricsDuration>() {

        @Override
        public int compare(MetricsDuration o1, MetricsDuration o2) {
            return o1.getDate().compareTo(o2.getDate());
        }
    });
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    if (transGraph.trans == null) {
        image = null;
        return;
    }
    // 
    if (image != null && (System.currentTimeMillis() - lastRefreshTime) < 5000) {
        return;
    }
    lastRefreshTime = System.currentTimeMillis();
    if (image != null) {
        // prevent out of memory...
        image.dispose();
        image = null;
    }
    // Correct size of canvas.
    org.eclipse.swt.graphics.Point textExtent = canvasGc.textExtent("AagKkiw");
    int height = textExtent.y + 8;
    // Make the height larger if needed for clarify
    // 
    bounds.height = Math.max(durations.size() * height, bounds.height);
    canvas.setSize(bounds.width, bounds.height);
    SWTGC gc = new SWTGC(Display.getCurrent(), new Point(bounds.width, bounds.height), PropsUI.getInstance().getIconSize());
    MetricsPainter painter = new MetricsPainter(gc, height);
    drawAreas = painter.paint(durations);
    image = (Image) gc.getImage();
    // refresh the scrolled composite
    // 
    sMetricsComposite.setMinHeight(bounds.height);
    sMetricsComposite.setMinWidth(bounds.width);
    sMetricsComposite.layout(true, true);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
    // close shop on the SWT GC side.
    // 
    gc.dispose();
}
Also used : SWTGC(org.pentaho.di.ui.spoon.SWTGC) MetricsPainter(org.pentaho.di.core.logging.MetricsPainter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.pentaho.di.core.gui.Point) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Point(org.pentaho.di.core.gui.Point)

Example 7 with MetricsDuration

use of org.pentaho.di.core.metrics.MetricsDuration in project pentaho-kettle by pentaho.

the class JobMetricsDelegate method refreshImage.

private void refreshImage(GC canvasGc) {
    List<MetricsDuration> durations = MetricsUtil.getAllDurations(jobGraph.job.getLogChannelId());
    if (Utils.isEmpty(durations)) {
        // In case of an empty durations or null there is nothing to draw
        return;
    }
    // Sort the metrics.
    Collections.sort(durations, new Comparator<MetricsDuration>() {

        @Override
        public int compare(MetricsDuration o1, MetricsDuration o2) {
            return o1.getDate().compareTo(o2.getDate());
        }
    });
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    if (jobGraph.job == null) {
        image = null;
        return;
    }
    // 
    if (image != null && (System.currentTimeMillis() - lastRefreshTime) < 5000) {
        return;
    }
    lastRefreshTime = System.currentTimeMillis();
    if (image != null) {
        // prevent out of memory...
        image.dispose();
        image = null;
    }
    // Correct size of canvas.
    // 
    org.eclipse.swt.graphics.Point textExtent = canvasGc.textExtent("AagKkiw");
    int barHeight = textExtent.y + 8;
    // Make the height larger if needed for clarify
    // 
    bounds.height = Math.max(durations.size() * barHeight, bounds.height);
    canvas.setSize(bounds.width, bounds.height);
    SWTGC gc = new SWTGC(Display.getCurrent(), new Point(bounds.width, bounds.height), PropsUI.getInstance().getIconSize());
    MetricsPainter painter = new MetricsPainter(gc, barHeight);
    // checking according to method's contract
    drawAreas = painter.paint(durations);
    image = (Image) gc.getImage();
    // refresh the scrolled composite
    // 
    // sMetricsComposite.setMinHeight(bounds.height);
    // sMetricsComposite.setMinWidth(bounds.width);
    sMetricsComposite.layout(true, true);
    // close shop on the SWT GC side.
    // 
    gc.dispose();
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : SWTGC(org.pentaho.di.ui.spoon.SWTGC) MetricsPainter(org.pentaho.di.core.logging.MetricsPainter) Rectangle(org.eclipse.swt.graphics.Rectangle) Point(org.pentaho.di.core.gui.Point) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Point(org.pentaho.di.core.gui.Point)

Example 8 with MetricsDuration

use of org.pentaho.di.core.metrics.MetricsDuration in project pentaho-kettle by pentaho.

the class MetricsIT method testBasics.

@Test
public void testBasics() throws Exception {
    LogChannel log = new LogChannel("BASICS");
    log.setGatheringMetrics(true);
    log.snap(METRIC_START);
    Thread.sleep(50);
    log.snap(METRIC_STOP);
    Queue<MetricsSnapshotInterface> snapshotList = MetricsRegistry.getInstance().getSnapshotList(log.getLogChannelId());
    assertEquals(2, snapshotList.size());
    List<MetricsDuration> durationList = MetricsUtil.getDuration(log.getLogChannelId(), METRIC_START);
    assertEquals(1, durationList.size());
    MetricsDuration duration = durationList.get(0);
    assertTrue(duration.getDuration() >= 50 && duration.getDuration() <= 100);
}
Also used : MetricsSnapshotInterface(org.pentaho.di.core.metrics.MetricsSnapshotInterface) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Test(org.junit.Test)

Example 9 with MetricsDuration

use of org.pentaho.di.core.metrics.MetricsDuration in project pentaho-kettle by pentaho.

the class MetricsIT method testTransformation.

@Test
public void testTransformation() throws Exception {
    TransMeta transMeta = new TransMeta("src/it/resources/metrics/simple-test.ktr");
    transMeta.setGatheringMetrics(true);
    Trans trans = new Trans(transMeta);
    trans.setGatheringMetrics(true);
    trans.execute(null);
    trans.waitUntilFinished();
    LogChannelInterface log = trans.getLogChannel();
    Queue<MetricsSnapshotInterface> snapshotList = MetricsRegistry.getInstance().getSnapshotList(log.getLogChannelId());
    assertTrue(snapshotList.size() >= 4);
    List<MetricsDuration> durationList = MetricsUtil.getDuration(log.getLogChannelId(), Metrics.METRIC_TRANSFORMATION_EXECUTION_START);
    assertEquals(1, durationList.size());
    MetricsDuration duration = durationList.get(0);
    assertTrue(duration.getDuration() >= 20 && duration.getDuration() <= 5000);
    assertEquals(Long.valueOf(1L), duration.getCount());
// Get all durations...
// 
// durationList = MetricsUtil.getDurations(trans.getLogChannelId());
}
Also used : MetricsSnapshotInterface(org.pentaho.di.core.metrics.MetricsSnapshotInterface) TransMeta(org.pentaho.di.trans.TransMeta) Trans(org.pentaho.di.trans.Trans) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Test(org.junit.Test)

Aggregations

MetricsDuration (org.pentaho.di.core.metrics.MetricsDuration)9 Point (org.pentaho.di.core.gui.Point)5 Rectangle (org.eclipse.swt.graphics.Rectangle)4 MetricsSnapshotInterface (org.pentaho.di.core.metrics.MetricsSnapshotInterface)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 ControlAdapter (org.eclipse.swt.events.ControlAdapter)2 ControlEvent (org.eclipse.swt.events.ControlEvent)2 DisposeEvent (org.eclipse.swt.events.DisposeEvent)2 DisposeListener (org.eclipse.swt.events.DisposeListener)2 MouseAdapter (org.eclipse.swt.events.MouseAdapter)2 MouseEvent (org.eclipse.swt.events.MouseEvent)2 PaintEvent (org.eclipse.swt.events.PaintEvent)2 PaintListener (org.eclipse.swt.events.PaintListener)2 FormAttachment (org.eclipse.swt.layout.FormAttachment)2 FormData (org.eclipse.swt.layout.FormData)2 Canvas (org.eclipse.swt.widgets.Canvas)2 Control (org.eclipse.swt.widgets.Control)2 Test (org.junit.Test)2 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)2