Search in sources :

Example 1 with MetricsDuration

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

the class MetricsPainter method drawDurations.

private void drawDurations(List<MetricsDuration> durations, List<MetricsDrawArea> areas, double pixelsPerMs) {
    // set top indent
    int y = 20;
    for (MetricsDuration duration : durations) {
        Long realDuration = duration.getEndDate().getTime() - duration.getDate().getTime();
        // How many pixels does it take to drawn this duration?
        // 
        int durationWidth = (int) (realDuration * pixelsPerMs);
        int x = 2 + (int) ((duration.getDate().getTime() - periodStart) * pixelsPerMs);
        getGc().setBackground(EColor.BACKGROUND);
        getGc().setForeground(EColor.LIGHTBLUE);
        getGc().fillGradientRectangle(x, y, durationWidth, barHeight, false);
        getGc().setForeground(EColor.BLACK);
        getGc().drawRectangle(x, y, durationWidth, barHeight);
        areas.add(new MetricsDrawArea(new Rectangle(x, y, durationWidth, barHeight), duration));
        LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject(duration.getLogChannelId());
        String message = duration.getDescription() + " - " + loggingObject.getObjectName() + " : " + duration.getDuration() + "ms";
        if (duration.getCount() > 1) {
            message += " " + duration.getCount() + " calls, avg=" + (duration.getDuration() / duration.getCount());
        }
        getGc().setFont(EFont.GRAPH);
        getGc().textExtent(message);
        getGc().drawText(message, x + 3, y + 4, true);
        y += barHeight + 5;
    }
}
Also used : Rectangle(org.pentaho.di.core.gui.Rectangle) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) Point(org.pentaho.di.core.gui.Point)

Example 2 with MetricsDuration

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

the class MetricsPainter method determinePeriod.

private void determinePeriod(List<MetricsDuration> durations) {
    periodStart = null;
    periodEnd = null;
    for (MetricsDuration duration : durations) {
        long periodStartTime = duration.getDate().getTime();
        if (periodStart == null || periodStartTime < periodStart) {
            periodStart = periodStartTime;
        }
        long periodEndTime = duration.getEndDate().getTime();
        if (periodEnd == null || periodEnd < periodEndTime) {
            periodEnd = periodEndTime;
        }
    }
}
Also used : MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration)

Example 3 with MetricsDuration

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

the class JobMetricsDelegate method setupContent.

public void setupContent() {
    if (metricsComposite.isDisposed()) {
        return;
    }
    // 
    for (Control control : metricsComposite.getChildren()) {
        if (!control.isDisposed()) {
            control.dispose();
        }
    }
    emptyGraph = false;
    canvas = new Canvas(metricsComposite, SWT.NONE);
    spoon.props.setLook(canvas);
    FormData fdCanvas = new FormData();
    fdCanvas.left = new FormAttachment(0, 0);
    fdCanvas.right = new FormAttachment(100, 0);
    fdCanvas.top = new FormAttachment(0, 0);
    fdCanvas.bottom = new FormAttachment(100, 0);
    canvas.setLayoutData(fdCanvas);
    metricsComposite.addControlListener(new ControlAdapter() {

        public void controlResized(ControlEvent event) {
            updateGraph();
        }
    });
    metricsComposite.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent event) {
            if (image != null) {
                image.dispose();
            }
        }
    });
    canvas.addPaintListener(new PaintListener() {

        public void paintControl(PaintEvent event) {
            if (jobGraph.job != null && (jobGraph.job.isFinished() || jobGraph.job.isStopped())) {
                refreshImage(event.gc);
                if (!Const.isRunningOnWebspoonMode()) {
                    if (image != null && !image.isDisposed()) {
                        event.gc.drawImage(image, 0, 0);
                    }
                }
            } else {
                Rectangle bounds = canvas.getBounds();
                if (bounds.width <= 0 || bounds.height <= 0) {
                    return;
                }
                event.gc.setForeground(GUIResource.getInstance().getColorWhite());
                event.gc.setBackground(GUIResource.getInstance().getColorWhite());
                event.gc.fillRectangle(new Rectangle(0, 0, bounds.width, bounds.height));
                event.gc.setForeground(GUIResource.getInstance().getColorBlack());
                String metricsMessage = BaseMessages.getString(PKG, "JobMetricsDelegate.JobIsNotRunning.Message");
                org.eclipse.swt.graphics.Point extent = event.gc.textExtent(metricsMessage);
                event.gc.drawText(metricsMessage, (bounds.width - extent.x) / 2, (bounds.height - extent.y) / 2);
            }
        }
    });
    // Refresh automatically every 5 seconds as well.
    // 
    final Timer timer = new Timer("JobMetricsDelegate Timer");
    timer.schedule(new TimerTask() {

        public void run() {
            updateGraph();
        }
    }, 0, 5000);
    // When the tab is closed, we remove the update timer
    // 
    jobMetricsTab.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent arg0) {
            timer.cancel();
        }
    });
    if (Const.isRunningOnWebspoonMode()) {
        // When the browser tab/window is closed, we remove the update timer
        jobMetricsTab.getDisplay().disposeExec(new Runnable() {

            @Override
            public void run() {
                timer.cancel();
            }
        });
    }
    // Show tool tips with details...
    // 
    canvas.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseDown(MouseEvent event) {
            if (drawAreas == null) {
                return;
            }
            for (int i = drawAreas.size() - 1; i >= 0; i--) {
                MetricsDrawArea drawArea = drawAreas.get(i);
                if (drawArea.getArea().contains(event.x, event.y)) {
                    MetricsDuration duration = drawArea.getDuration();
                    if (duration == null) {
                        continue;
                    }
                    System.out.println(duration.toString());
                    LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject(duration.getLogChannelId());
                    if (loggingObject == null) {
                        return;
                    }
                    System.out.println(loggingObject.getObjectType() + " : " + loggingObject.getObjectName());
                }
            }
        }
    });
    canvas.addControlListener(new ControlAdapter() {

        @Override
        public void controlResized(ControlEvent arg0) {
            // force a refresh
            lastRefreshTime = 0;
        }
    });
}
Also used : FormData(org.eclipse.swt.layout.FormData) MetricsDrawArea(org.pentaho.di.core.logging.MetricsPainter.MetricsDrawArea) DisposeListener(org.eclipse.swt.events.DisposeListener) PaintEvent(org.eclipse.swt.events.PaintEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) ControlAdapter(org.eclipse.swt.events.ControlAdapter) PaintListener(org.eclipse.swt.events.PaintListener) Canvas(org.eclipse.swt.widgets.Canvas) Rectangle(org.eclipse.swt.graphics.Rectangle) MouseAdapter(org.eclipse.swt.events.MouseAdapter) Point(org.pentaho.di.core.gui.Point) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Control(org.eclipse.swt.widgets.Control) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ControlEvent(org.eclipse.swt.events.ControlEvent) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) MetricsDuration(org.pentaho.di.core.metrics.MetricsDuration) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 4 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)

Example 5 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)

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