From a56098e14a2475336ede85d3894cedac725c0ec5 Mon Sep 17 00:00:00 2001
From: Nils Christian Ehmke <nie@informatik.uni-kiel.de>
Date: Tue, 16 Dec 2014 10:57:32 +0100
Subject: [PATCH] Added time units

---
 src/main/java/kieker/gui/model/DataModel.java | 50 ++++++++++++++++++-
 .../importer/ImportAnalysisConfiguration.java | 18 +++++--
 .../gui/view/AggregatedTracesSubView.java     | 30 +++++++----
 src/main/java/kieker/gui/view/MainView.java   |  3 +-
 .../java/kieker/gui/view/RecordsSubView.java  |  2 +-
 .../java/kieker/gui/view/TracesSubView.java   | 13 ++---
 6 files changed, 93 insertions(+), 23 deletions(-)

diff --git a/src/main/java/kieker/gui/model/DataModel.java b/src/main/java/kieker/gui/model/DataModel.java
index d62de2cd..0c87a696 100644
--- a/src/main/java/kieker/gui/model/DataModel.java
+++ b/src/main/java/kieker/gui/model/DataModel.java
@@ -5,7 +5,9 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Observable;
+import java.util.concurrent.TimeUnit;
 
+import kieker.common.record.misc.KiekerMetadataRecord;
 import kieker.gui.model.domain.AggregatedExecutionEntry;
 import kieker.gui.model.domain.ExecutionEntry;
 import kieker.gui.model.domain.RecordEntry;
@@ -14,7 +16,7 @@ import teetime.framework.Analysis;
 
 /**
  * A container for data used within this application.
- * 
+ *
  * @author Nils Christian Ehmke
  */
 public final class DataModel extends Observable {
@@ -22,6 +24,7 @@ public final class DataModel extends Observable {
 	private List<RecordEntry> records = Collections.emptyList();
 	private List<ExecutionEntry> traces = Collections.emptyList();
 	private List<AggregatedExecutionEntry> aggregatedTraces;
+	private String shortTimeUnit;
 
 	public DataModel() {}
 
@@ -38,10 +41,51 @@ public final class DataModel extends Observable {
 		this.traces = analysisConfiguration.getTracesList();
 		this.aggregatedTraces = analysisConfiguration.getAggregatedTraces();
 
+		final List<KiekerMetadataRecord> metadataRecords = analysisConfiguration.getMetadataRecords();
+		if (metadataRecords.size() == 1) {
+			final KiekerMetadataRecord metadataRecord = metadataRecords.get(0);
+			this.shortTimeUnit = this.convertToShortTimeUnit(TimeUnit.valueOf(metadataRecord.getTimeUnit()));
+		} else {
+			this.shortTimeUnit = this.convertToShortTimeUnit(null);
+		}
+
 		this.setChanged();
 		this.notifyObservers();
 	}
 
+	private String convertToShortTimeUnit(final TimeUnit timeUnit) {
+		final String result;
+
+		switch (timeUnit) {
+		case DAYS:
+			result = "d";
+			break;
+		case HOURS:
+			result = "h";
+			break;
+		case MICROSECONDS:
+			result = "us";
+			break;
+		case MILLISECONDS:
+			result = "ms";
+			break;
+		case MINUTES:
+			result = "m";
+			break;
+		case NANOSECONDS:
+			result = "ns";
+			break;
+		case SECONDS:
+			result = "s";
+			break;
+		default:
+			result = "";
+			break;
+		}
+
+		return result;
+	}
+
 	public List<RecordEntry> getRecordsCopy() {
 		return new ArrayList<>(this.records);
 	}
@@ -54,4 +98,8 @@ public final class DataModel extends Observable {
 		return new ArrayList<>(this.aggregatedTraces);
 	}
 
+	public String getShortTimeUnit() {
+		return this.shortTimeUnit;
+	}
+
 }
diff --git a/src/main/java/kieker/gui/model/importer/ImportAnalysisConfiguration.java b/src/main/java/kieker/gui/model/importer/ImportAnalysisConfiguration.java
index 7ec90878..d68162cd 100644
--- a/src/main/java/kieker/gui/model/importer/ImportAnalysisConfiguration.java
+++ b/src/main/java/kieker/gui/model/importer/ImportAnalysisConfiguration.java
@@ -22,6 +22,7 @@ import java.util.Vector;
 
 import kieker.common.record.IMonitoringRecord;
 import kieker.common.record.flow.IFlowRecord;
+import kieker.common.record.misc.KiekerMetadataRecord;
 import kieker.gui.model.domain.AggregatedExecutionEntry;
 import kieker.gui.model.domain.ExecutionEntry;
 import kieker.gui.model.domain.RecordEntry;
@@ -35,7 +36,7 @@ import teetime.framework.pipe.PipeFactoryRegistry.PipeOrdering;
 import teetime.framework.pipe.PipeFactoryRegistry.ThreadCommunication;
 import teetime.stage.CollectorSink;
 import teetime.stage.InitialElementProducer;
-import teetime.stage.InstanceOfFilter;
+import teetime.stage.MultipleInstanceOfFilter;
 import teetime.stage.className.ClassNameRegistryRepository;
 import teetime.stage.io.filesystem.Dir2RecordsFilter;
 
@@ -49,12 +50,15 @@ public final class ImportAnalysisConfiguration extends AnalysisConfiguration {
 	private final List<RecordEntry> recordsList = new Vector<>(100000);
 	private final List<ExecutionEntry> tracesList = new Vector<>(100000);
 	private final List<AggregatedExecutionEntry> aggregatedTraces = new Vector<>(100000);
+	private final List<KiekerMetadataRecord> metadataRecords = new Vector<>(100000);
 
 	public ImportAnalysisConfiguration(final File importDirectory) {
 		// Create the stages
 		final InitialElementProducer<File> producer = new InitialElementProducer<>(importDirectory);
 		final Dir2RecordsFilter reader = new Dir2RecordsFilter(new ClassNameRegistryRepository());
-		final InstanceOfFilter<IMonitoringRecord, IFlowRecord> typeFilter = new InstanceOfFilter<>(IFlowRecord.class);
+
+		final MultipleInstanceOfFilter<IMonitoringRecord> typeFilter = new MultipleInstanceOfFilter<>();
+
 		final Cloner<IFlowRecord> fstDistributor = new Cloner<>();
 		final RecordSimplificator recordSimplificator = new RecordSimplificator();
 		final CollectorSink<RecordEntry> recordCollector = new CollectorSink<>(this.recordsList);
@@ -63,12 +67,14 @@ public final class ImportAnalysisConfiguration extends AnalysisConfiguration {
 		final CollectorSink<ExecutionEntry> traceCollector = new CollectorSink<>(this.tracesList);
 		final TraceAggregator traceAggregator = new TraceAggregator();
 		final CollectorSink<AggregatedExecutionEntry> aggregatedTraceCollector = new CollectorSink<>(this.aggregatedTraces);
+		final CollectorSink<KiekerMetadataRecord> metadataCollector = new CollectorSink<>(this.metadataRecords);
 
 		// Connect the stages
 		final IPipeFactory pipeFactory = AnalysisConfiguration.PIPE_FACTORY_REGISTRY.getPipeFactory(ThreadCommunication.INTRA, PipeOrdering.ARBITRARY, false);
 		pipeFactory.create(producer.getOutputPort(), reader.getInputPort());
 		pipeFactory.create(reader.getOutputPort(), typeFilter.getInputPort());
-		pipeFactory.create(typeFilter.getOutputPort(), fstDistributor.getInputPort());
+
+		pipeFactory.create(typeFilter.getOutputPortForType(IFlowRecord.class), fstDistributor.getInputPort());
 		pipeFactory.create(fstDistributor.getFirstOutputPort(), recordSimplificator.getInputPort());
 		pipeFactory.create(recordSimplificator.getOutputPort(), recordCollector.getInputPort());
 		pipeFactory.create(fstDistributor.getSecondOutputPort(), traceReconstructor.getInputPort());
@@ -77,6 +83,8 @@ public final class ImportAnalysisConfiguration extends AnalysisConfiguration {
 		pipeFactory.create(sndDistributor.getSecondOutputPort(), traceAggregator.getInputPort());
 		pipeFactory.create(traceAggregator.getOutputPort(), aggregatedTraceCollector.getInputPort());
 
+		pipeFactory.create(typeFilter.getOutputPortForType(KiekerMetadataRecord.class), metadataCollector.getInputPort());
+
 		// Make sure that the producer is executed by the analysis
 		super.addThreadableStage(producer);
 	}
@@ -93,4 +101,8 @@ public final class ImportAnalysisConfiguration extends AnalysisConfiguration {
 		return this.aggregatedTraces;
 	}
 
+	public List<KiekerMetadataRecord> getMetadataRecords() {
+		return this.metadataRecords;
+	}
+
 }
diff --git a/src/main/java/kieker/gui/view/AggregatedTracesSubView.java b/src/main/java/kieker/gui/view/AggregatedTracesSubView.java
index 320ad3ef..8e67a8b2 100644
--- a/src/main/java/kieker/gui/view/AggregatedTracesSubView.java
+++ b/src/main/java/kieker/gui/view/AggregatedTracesSubView.java
@@ -86,19 +86,19 @@ public class AggregatedTracesSubView implements Observer {
 		trclmnOperation.setWidth(100);
 		trclmnOperation.setText("Operation");
 
-		final TreeColumn trclmnCalls = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnCalls = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnCalls.setWidth(100);
 		trclmnCalls.setText("Number of Calls");
 
-		final TreeColumn trclmnMinimalDuration = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnMinimalDuration = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnMinimalDuration.setWidth(100);
 		trclmnMinimalDuration.setText("Minimal Duration");
 
-		final TreeColumn trclmnAverageDuration = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnAverageDuration = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnAverageDuration.setWidth(100);
 		trclmnAverageDuration.setText("Average Duration");
 
-		final TreeColumn trclmnMaximalDuration = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnMaximalDuration = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnMaximalDuration.setWidth(100);
 		trclmnMaximalDuration.setText("Maximal Duration");
 
@@ -228,9 +228,13 @@ public class AggregatedTracesSubView implements Observer {
 	private void updateDetailComposite() {
 		final AggregatedExecutionEntry trace = this.aggregatedTracesSubViewModel.getCurrentActiveTrace();
 
-		this.lblMinimalDurationDisplay.setText(Long.toString(trace.getMinDuration()));
-		this.lblMaximalDurationDisplay.setText(Long.toString(trace.getMaxDuration()));
-		this.lblAverageDurationDisplay.setText(Long.toString(trace.getAvgDuration()));
+		final String minDuration = (Long.toString(trace.getMinDuration()) + " " + this.model.getShortTimeUnit()).trim();
+		final String maxDuration = (Long.toString(trace.getMaxDuration()) + " " + this.model.getShortTimeUnit()).trim();
+		final String avgDuration = (Long.toString(trace.getAvgDuration()) + " " + this.model.getShortTimeUnit()).trim();
+
+		this.lblMinimalDurationDisplay.setText(minDuration);
+		this.lblMaximalDurationDisplay.setText(maxDuration);
+		this.lblAverageDurationDisplay.setText(avgDuration);
 
 		this.lblExecutionContainerDisplay.setText(trace.getContainer());
 		this.lblComponentDisplay.setText(trace.getComponent());
@@ -283,12 +287,16 @@ public class AggregatedTracesSubView implements Observer {
 				final int lastPointPos = operationString.lastIndexOf('.', operationString.length() - 5);
 				operationString = operationString.substring(lastPointPos + 1);
 			}
+
+			final String minDuration = (Long.toString(executionEntry.getMinDuration()) + " " + AggregatedTracesSubView.this.model.getShortTimeUnit()).trim();
+			final String maxDuration = (Long.toString(executionEntry.getMaxDuration()) + " " + AggregatedTracesSubView.this.model.getShortTimeUnit()).trim();
+			final String avgDuration = (Long.toString(executionEntry.getAvgDuration()) + " " + AggregatedTracesSubView.this.model.getShortTimeUnit()).trim();
+
 			if (parent != null) {
-				item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, "",
-					Long.toString(executionEntry.getMinDuration()), Long.toString(executionEntry.getAvgDuration()), Long.toString(executionEntry.getMaxDuration()) });
+				item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, "", minDuration, avgDuration, maxDuration });
 			} else {
-				item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, Integer.toString(executionEntry.getCalls()),
-					Long.toString(executionEntry.getMinDuration()), Long.toString(executionEntry.getAvgDuration()), Long.toString(executionEntry.getMaxDuration()) });
+				item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, Integer.toString(executionEntry.getCalls()), minDuration, avgDuration,
+					maxDuration });
 			}
 
 			if (executionEntry.isFailed()) {
diff --git a/src/main/java/kieker/gui/view/MainView.java b/src/main/java/kieker/gui/view/MainView.java
index 2efbea43..9aab701e 100644
--- a/src/main/java/kieker/gui/view/MainView.java
+++ b/src/main/java/kieker/gui/view/MainView.java
@@ -49,7 +49,6 @@ public class MainView implements Observer {
 			final TracesSubView tracesSubView, final AggregatedTracesSubView aggregatedTracesSubView) {
 		this.dataModel = dataModel;
 		this.mainViewModel = mainViewModel;
-
 		this.recordsSubView = recordsSubView;
 		this.tracesSubView = tracesSubView;
 		this.aggregatedTracesSubView = aggregatedTracesSubView;
@@ -65,6 +64,8 @@ public class MainView implements Observer {
 		this.shell.open();
 		this.shell.layout();
 
+	
+
 		while (!this.shell.isDisposed()) {
 			if (!display.readAndDispatch()) {
 				display.sleep();
diff --git a/src/main/java/kieker/gui/view/RecordsSubView.java b/src/main/java/kieker/gui/view/RecordsSubView.java
index 9749046d..57e9966b 100644
--- a/src/main/java/kieker/gui/view/RecordsSubView.java
+++ b/src/main/java/kieker/gui/view/RecordsSubView.java
@@ -95,7 +95,7 @@ public final class RecordsSubView implements Observer {
 		}
 	}
 
-	private static class DataProvider implements Listener {
+	private class DataProvider implements Listener {
 
 		@Override
 		@SuppressWarnings("unchecked")
diff --git a/src/main/java/kieker/gui/view/TracesSubView.java b/src/main/java/kieker/gui/view/TracesSubView.java
index f6a54950..737ee89a 100644
--- a/src/main/java/kieker/gui/view/TracesSubView.java
+++ b/src/main/java/kieker/gui/view/TracesSubView.java
@@ -87,11 +87,11 @@ public class TracesSubView implements Observer {
 		trclmnOperation.setWidth(100);
 		trclmnOperation.setText("Operation");
 
-		final TreeColumn trclmnDuration = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnDuration = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnDuration.setWidth(100);
 		trclmnDuration.setText("Duration");
 
-		final TreeColumn trclmnPercent = new TreeColumn(this.tree, SWT.NONE);
+		final TreeColumn trclmnPercent = new TreeColumn(this.tree, SWT.RIGHT);
 		trclmnPercent.setWidth(100);
 		trclmnPercent.setText("Percent");
 
@@ -219,8 +219,10 @@ public class TracesSubView implements Observer {
 	private void updateDetailComposite() {
 		final ExecutionEntry trace = this.tracesSubViewModel.getCurrentActiveTrace();
 
+		final String duration = (Long.toString(trace.getDuration()) + " " + this.model.getShortTimeUnit()).trim();
+
 		this.lblTraceIdDisplay.setText(Long.toString(trace.getTraceID()));
-		this.lblDurationDisplay.setText(Long.toString(trace.getDuration()));
+		this.lblDurationDisplay.setText(duration);
 
 		this.lblExecutionContainerDisplay.setText(trace.getContainer());
 		this.lblComponentDisplay.setText(trace.getComponent());
@@ -276,8 +278,8 @@ public class TracesSubView implements Observer {
 				final int lastPointPos = operationString.lastIndexOf('.', operationString.length() - 5);
 				operationString = operationString.substring(lastPointPos + 1);
 			}
-			item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, Long.toString(executionEntry.getDuration()),
-					String.format("%.1f%%", executionEntry.getPercent()), traceID });
+			final String duration = (Long.toString(executionEntry.getDuration()) + " " + TracesSubView.this.model.getShortTimeUnit()).trim();
+			item.setText(new String[] { executionEntry.getContainer(), componentName, operationString, duration, String.format("%.1f%%", executionEntry.getPercent()), traceID });
 
 			if (executionEntry.isFailed()) {
 				final Color colorRed = Display.getCurrent().getSystemColor(SWT.COLOR_RED);
@@ -287,7 +289,6 @@ public class TracesSubView implements Observer {
 			item.setData(executionEntry);
 			item.setItemCount(executionEntry.getChildren().size());
 		}
-
 	}
 
 }
-- 
GitLab