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; } } }
@Override public String toString() { LoggingObjectInterface loggingObject = LoggingRegistry.getInstance().getLoggingObject( logChannelId ); String subject = null; if ( loggingObject != null ) { subject = loggingObject.getObjectName() + "(" + loggingObject.getObjectType() + ")"; } else { subject = "-"; } return subject + " - " + getKey() + " @ " + StringUtil.getFormattedDateTime( date, true ) + " : " + type.toString(); }
snapshot.getMetric().getDescription() + ( snapshot.getSubject() == null ? "" : ( " - " + snapshot.getSubject() ) ); MetricsSnapshotInterface lastSnapshot = last.get( key ); if ( lastSnapshot == null ) { MetricsInterface metric = lastSnapshot.getMetric(); if ( metric.getType() == MetricsSnapshotType.START && snapshot.getMetric().getType() == MetricsSnapshotType.STOP ) { long extraDuration = snapshot.getDate().getTime() - lastSnapshot.getDate().getTime(); new MetricsDuration( lastSnapshot.getDate(), metric.getDescription(), lastSnapshot.getSubject(), logChannelId, extraDuration ); } else { metricsDuration.setDuration( metricsDuration.getDuration() + extraDuration ); metricsDuration.incrementCount(); if ( metricsDuration.getEndDate().getTime() < snapshot.getDate().getTime() ) { metricsDuration.setEndDate( snapshot.getDate() );
while ( iterator.hasNext() ) { MetricsSnapshotInterface snapshot = iterator.next(); if ( snapshot.getMetric().equals( metric ) ) { if ( snapshot.getMetric().getType() == MetricsSnapshotType.START ) { if ( start != null ) { durations.add( new MetricsDuration( start.getDate(), snapshot.getMetric().getDescription(), snapshot .getSubject(), logChannelId, null ) ); long duration = snapshot.getDate().getTime() - start.getDate().getTime(); durations.add( new MetricsDuration( start.getDate(), snapshot.getMetric().getDescription(), snapshot .getSubject(), logChannelId, duration ) ); start = null; for ( MetricsDuration duration : durations ) { String key = duration.getSubject() == null ? duration.getDescription() : duration.getDescription() + " / " + duration.getSubject(); MetricsDuration agg = map.get( key ); if ( agg == null ) { map.put( key, duration ); } else { agg.setDuration( agg.getDuration() + duration.getDuration() );
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; } }
break; case CHANNEL_ID: value = snapshot.getLogChannelId(); break; case LOG_DATE: break; case METRICS_DATE: value = snapshot.getDate(); break; case METRICS_CODE: value = snapshot.getMetric().getCode(); break; case METRICS_DESCRIPTION: value = snapshot.getMetric().getDescription(); break; case METRICS_SUBJECT: value = snapshot.getSubject(); break; case METRICS_TYPE: value = snapshot.getMetric().getType().name(); break; case METRICS_VALUE: value = snapshot.getValue(); break; default:
String key = MetricsSnapshot.getKey( metric, subject ); Map<String, MetricsSnapshotInterface> metricsMap = null; MetricsSnapshotInterface snapshot = null; snapshot = metricsMap.get( key ); if ( snapshot != null ) { if ( value[0] > snapshot.getValue() ) { snapshot.setValue( value[0] ); snapshot.setDate( new Date() ); snapshot = new MetricsSnapshot( MetricsSnapshotType.MAX, metric, subject, value[0], logChannelId ); metricsMap.put( key, snapshot ); snapshot = metricsMap.get( key ); if ( snapshot != null ) { if ( value[0] < snapshot.getValue() ) { snapshot.setValue( value[0] ); snapshot.setDate( new Date() ); snapshot = new MetricsSnapshot( MetricsSnapshotType.MIN, metric, subject, value[0], logChannelId ); metricsMap.put( key, snapshot ); snapshot = metricsMap.get( key ); if ( snapshot != null ) { snapshot.setValue( snapshot.getValue() + value[0] ); } else { snapshot = new MetricsSnapshot( MetricsSnapshotType.SUM, metric, subject, value[0], logChannelId ); metricsMap.put( key, snapshot );
@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() ); } } } } );
protected synchronized void writeMetricsInformation() throws KettleException { Preconditions.checkNotNull( log ); List<MetricsDuration> metricsList = MetricsUtil.getDuration( log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_REGISTER_EXTENSIONS_START ); if ( ( log.isDebug() ) && !metricsList.isEmpty() ) { log.logDebug( metricsList.get( 0 ).toString() ); MetricsUtil.getDuration( log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_REGISTRATION_START ); if ( ( log != null ) && ( log.isDebug() ) && !metricsList.isEmpty() ) { log.logDebug( metricsList.get( 0 ).toString() ); MetricsUtil.getDuration( log.getLogChannelId(), Metrics.METRIC_PLUGIN_REGISTRY_PLUGIN_TYPE_REGISTRATION_START ); if ( ( log != null ) && ( log.isDebug() ) && metricsList != null && !metricsList.isEmpty() ) { for ( MetricsDuration duration : metricsList ) { total += duration.getDuration(); log.logDebug( " - " + duration.toString() + " Total=" + total );
public static Long getResult( Metrics metric ) { Map<String, Map<String, MetricsSnapshotInterface>> snapshotMaps = MetricsRegistry.getInstance().getSnapshotMaps(); Iterator<Map<String, MetricsSnapshotInterface>> mapsIterator = snapshotMaps.values().iterator(); while ( mapsIterator.hasNext() ) { Map<String, MetricsSnapshotInterface> map = mapsIterator.next(); Iterator<MetricsSnapshotInterface> snapshotIterator = map.values().iterator(); while ( snapshotIterator.hasNext() ) { MetricsSnapshotInterface snapshot = snapshotIterator.next(); if ( snapshot.getMetric().equals( metric ) ) { return snapshot.getValue(); } } } return null; }
public void addSnapshot( LogChannelInterface logChannel, MetricsSnapshotInterface snapshot ) { MetricsInterface metric = snapshot.getMetric(); String channelId = logChannel.getLogChannelId(); switch ( metric.getType() ) { case START: case STOP: Queue<MetricsSnapshotInterface> list = getSnapshotList( channelId ); list.add( snapshot ); break; case MIN: case MAX: case SUM: case COUNT: Map<String, MetricsSnapshotInterface> map = getSnapshotMap( channelId ); map.put( snapshot.getKey(), snapshot ); break; default: break; } }
public static List<MetricsSnapshotInterface> getResultsList( Metrics metric ) { List<MetricsSnapshotInterface> snapshots = new ArrayList<MetricsSnapshotInterface>(); Map<String, Map<String, MetricsSnapshotInterface>> snapshotMaps = MetricsRegistry.getInstance().getSnapshotMaps(); Iterator<Map<String, MetricsSnapshotInterface>> mapsIterator = snapshotMaps.values().iterator(); while ( mapsIterator.hasNext() ) { Map<String, MetricsSnapshotInterface> map = mapsIterator.next(); Iterator<MetricsSnapshotInterface> snapshotIterator = map.values().iterator(); while ( snapshotIterator.hasNext() ) { MetricsSnapshotInterface snapshot = snapshotIterator.next(); if ( snapshot.getMetric().equals( metric ) ) { snapshots.add( snapshot ); } } } return snapshots; }
private void refreshImage( GC canvasGc ) { List<MetricsDuration> durations = MetricsUtil.getAllDurations( jobGraph.job.getLogChannelId() ); if ( Utils.isEmpty( durations ) ) {
public static List<MetricsDuration> getAllDurations( String parentLogChannelId ) { List<MetricsDuration> durations = new ArrayList<MetricsDuration>(); List<String> logChannelIds = LoggingRegistry.getInstance().getLogChannelChildren( parentLogChannelId ); for ( String logChannelId : logChannelIds ) { LoggingObjectInterface object = LoggingRegistry.getInstance().getLoggingObject( logChannelId ); if ( object != null ) { durations.addAll( getDurations( logChannelId ) ); } } return durations; }
@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 ) { continue; } System.out.println( loggingObject.getObjectType() + " : " + loggingObject.getObjectName() ); } } } } );
private void refreshImage( GC canvasGc ) { List<MetricsDuration> durations = MetricsUtil.getAllDurations( transGraph.trans.getLogChannelId() ); if ( Utils.isEmpty( durations ) ) {