lttng: Copy the project settings in the examples plugin too
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tracing.examples / src / org / eclipse / linuxtools / tracing / examples / ui / viewers / histogram / NewHistogramViewer.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Alexandre Montplaisir - Initial API and implementation
11 * Bernd Hufmann - Updated to new TMF chart framework
12 *******************************************************************************/
13 package org.eclipse.linuxtools.tracing.examples.ui.viewers.histogram;
14
15 import java.util.Arrays;
16 import java.util.List;
17
18 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
19 import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsModule;
20 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
21 import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager;
22 import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.barcharts.TmfBarChartViewer;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Display;
26 import org.swtchart.Chart;
27 import org.swtchart.IAxis;
28 import org.swtchart.ISeries;
29 import org.swtchart.LineStyle;
30
31 /**
32 * Histogram Viewer implementation based on TmfBarChartViewer.
33 *
34 * @author Alexandre Montplaisir
35 * @author Bernd Hufmann
36 */
37 public class NewHistogramViewer extends TmfBarChartViewer {
38
39 /**
40 * Creates a Histogram Viewer instance.
41 * @param parent
42 * The parent composite to draw in.
43 */
44 public NewHistogramViewer(Composite parent) {
45 super(parent, null, null, null, TmfBarChartViewer.MINIMUM_BAR_WIDTH);
46
47 Chart swtChart = getSwtChart();
48
49 IAxis xAxis = swtChart.getAxisSet().getXAxis(0);
50 IAxis yAxis = swtChart.getAxisSet().getYAxis(0);
51
52 /* Hide the grid */
53 xAxis.getGrid().setStyle(LineStyle.NONE);
54 yAxis.getGrid().setStyle(LineStyle.NONE);
55
56 /* Hide the legend */
57 swtChart.getLegend().setVisible(false);
58
59 addSeries("Number of events", Display.getDefault().getSystemColor(SWT.COLOR_BLUE).getRGB()); //$NON-NLS-1$
60 }
61
62 @Override
63 protected void readData(final ISeries series, final long start, final long end, final int nb) {
64 if (getTrace() != null) {
65 final double y[] = new double[nb];
66
67 Thread thread = new Thread("Histogram viewer update") { //$NON-NLS-1$
68 @Override
69 public void run() {
70 double x[] = getXAxis(start, end, nb);
71 final long yLong[] = new long[nb];
72 Arrays.fill(y, 0.0);
73
74 /* Add the values for each trace */
75 for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) {
76 /* Retrieve the statistics object */
77 final TmfStatisticsModule statsMod =
78 trace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID);
79 if (statsMod == null) {
80 /* No statistics module available for this trace */
81 continue;
82 }
83 statsMod.waitForInitialization();
84 final ITmfStatistics stats = statsMod.getStatistics();
85 if (stats == null) {
86 /*
87 * Should not be null after waitForInitialization()
88 * is called.
89 */
90 throw new IllegalStateException();
91 }
92 List<Long> values = stats.histogramQuery(start, end, nb);
93
94 for (int i = 0; i < nb; i++) {
95 yLong[i] += values.get(i);
96 }
97 }
98
99 for (int i = 0; i < nb; i++) {
100 y[i] += yLong[i]; /* casting from long to double */
101 }
102
103 /* Update the viewer */
104 drawChart(series, x, y);
105 }
106 };
107 thread.start();
108 }
109 return;
110 }
111 }
This page took 0.065906 seconds and 6 git commands to generate.