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;
}
}
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;
}
}
}
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;
}
});
}
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());
}
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);
}
Aggregations