tmf: Move the trace statistics to the analysis framework
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui / src / org / eclipse / linuxtools / tmf / ui / views / statistics / TmfStatisticsModule.java
1 /*******************************************************************************
2 * Copyright (c) 2013 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 *******************************************************************************/
12
13 package org.eclipse.linuxtools.tmf.ui.views.statistics;
14
15 import java.util.LinkedList;
16 import java.util.List;
17
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.IStatus;
20 import org.eclipse.linuxtools.tmf.core.analysis.TmfAbstractAnalysisModule;
21 import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException;
22 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems;
23 import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem;
24 import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule;
25 import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics;
26 import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics;
27 import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsEventTypesModule;
28 import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsTotalsModule;
29 import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace;
30 import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput;
31
32 /**
33 * Analysis module to compute the statistics of a trace.
34 *
35 * @author Alexandre Montplaisir
36 * @since 3.0
37 */
38 public class TmfStatisticsModule extends TmfAbstractAnalysisModule
39 implements ITmfAnalysisModuleWithStateSystems {
40
41 /** ID of this analysis module */
42 public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"; //$NON-NLS-1$
43
44 /** The trace's statistics */
45 private ITmfStatistics fStatistics = null;
46
47 private final TmfStateSystemAnalysisModule totalsModule = new TmfStatisticsTotalsModule();
48 private final TmfStateSystemAnalysisModule eventTypesModule = new TmfStatisticsEventTypesModule();
49
50 /**
51 * Constructor
52 */
53 public TmfStatisticsModule() {
54 super();
55 this.registerOutput(new TmfAnalysisViewOutput(TmfStatisticsView.ID));
56 }
57
58 /**
59 * Get the statistics object built by this analysis
60 *
61 * @return The ITmfStatistics object
62 */
63 public ITmfStatistics getStatistics() {
64 return fStatistics;
65 }
66
67 // ------------------------------------------------------------------------
68 // TmfAbstractAnalysisModule
69 // ------------------------------------------------------------------------
70
71 @Override
72 protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException {
73 ITmfTrace trace = getTrace();
74 if (trace == null) {
75 /* This analysis's trace should not be null when this is called */
76 throw new IllegalStateException();
77 }
78
79 /*
80 * Since these sub-analyzes are not built from an extension point, we
81 * have to assign the trace ourselves. Very important to do so before
82 * calling schedule()!
83 */
84 totalsModule.setTrace(trace);
85 eventTypesModule.setTrace(trace);
86
87 IStatus status1 = totalsModule.schedule();
88 IStatus status2 = eventTypesModule.schedule();
89 if (!status1.isOK() || !status2.isOK()) {
90 return false;
91 }
92
93 /*
94 * The "execute" of this trace will encompass the "execute" of the two
95 * sub-analyzes.
96 */
97 if (!totalsModule.waitForCompletion(monitor) ||
98 !eventTypesModule.waitForCompletion(monitor)) {
99 return false;
100 }
101
102 ITmfStateSystem totalsSS = totalsModule.getStateSystem();
103 ITmfStateSystem eventTypesSS = eventTypesModule.getStateSystem();
104
105 if (totalsSS == null || eventTypesSS == null) {
106 /* Better safe than sorry... */
107 throw new IllegalStateException();
108 }
109
110 fStatistics = new TmfStateStatistics(trace, totalsSS, eventTypesSS);
111 return true;
112 }
113
114 @Override
115 protected void canceling() {
116 /*
117 * FIXME The "right" way to cancel state system construction is not
118 * available yet...
119 */
120 totalsModule.cancel();
121 eventTypesModule.cancel();
122
123 ITmfStatistics stats = fStatistics;
124 if (stats != null) {
125 stats.dispose();
126 }
127 }
128
129 // ------------------------------------------------------------------------
130 // ITmfStateSystemAnalysisModule
131 // ------------------------------------------------------------------------
132
133 @Override
134 public ITmfStateSystem getStateSystem(String id) {
135 switch (id) {
136 case TmfStatisticsTotalsModule.ID:
137 return totalsModule.getStateSystem();
138 case TmfStatisticsEventTypesModule.ID:
139 return eventTypesModule.getStateSystem();
140 default:
141 return null;
142 }
143 }
144
145 @Override
146 public String getStateSystemId(ITmfStateSystem ss) {
147 if (ss.equals(totalsModule.getStateSystem())) {
148 return TmfStatisticsTotalsModule.ID;
149 } else if (ss.equals(eventTypesModule.getStateSystem())){
150 return TmfStatisticsEventTypesModule.ID;
151 }
152 return null;
153 }
154
155 @Override
156 public Iterable<ITmfStateSystem> getStateSystems() {
157 List<ITmfStateSystem> list = new LinkedList<>();
158 list.add(totalsModule.getStateSystem());
159 list.add(eventTypesModule.getStateSystem());
160 return list;
161 }
162 }
This page took 0.03663 seconds and 6 git commands to generate.