1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Alexandre Montplaisir - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
;
15 import java
.util
.LinkedList
;
16 import java
.util
.List
;
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
;
33 * Analysis module to compute the statistics of a trace.
35 * @author Alexandre Montplaisir
38 public class TmfStatisticsModule
extends TmfAbstractAnalysisModule
39 implements ITmfAnalysisModuleWithStateSystems
{
41 /** ID of this analysis module */
42 public static final String ID
= "org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"; //$NON-NLS-1$
44 /** The trace's statistics */
45 private ITmfStatistics fStatistics
= null;
47 private final TmfStateSystemAnalysisModule totalsModule
= new TmfStatisticsTotalsModule();
48 private final TmfStateSystemAnalysisModule eventTypesModule
= new TmfStatisticsEventTypesModule();
53 public TmfStatisticsModule() {
55 this.registerOutput(new TmfAnalysisViewOutput(TmfStatisticsView
.ID
));
59 * Get the statistics object built by this analysis
61 * @return The ITmfStatistics object
63 public ITmfStatistics
getStatistics() {
67 // ------------------------------------------------------------------------
68 // TmfAbstractAnalysisModule
69 // ------------------------------------------------------------------------
72 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
73 ITmfTrace trace
= getTrace();
75 /* This analysis's trace should not be null when this is called */
76 throw new IllegalStateException();
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
84 totalsModule
.setTrace(trace
);
85 eventTypesModule
.setTrace(trace
);
87 IStatus status1
= totalsModule
.schedule();
88 IStatus status2
= eventTypesModule
.schedule();
89 if (!status1
.isOK() || !status2
.isOK()) {
94 * The "execute" of this trace will encompass the "execute" of the two
97 if (!totalsModule
.waitForCompletion(monitor
) ||
98 !eventTypesModule
.waitForCompletion(monitor
)) {
102 ITmfStateSystem totalsSS
= totalsModule
.getStateSystem();
103 ITmfStateSystem eventTypesSS
= eventTypesModule
.getStateSystem();
105 if (totalsSS
== null || eventTypesSS
== null) {
106 /* Better safe than sorry... */
107 throw new IllegalStateException();
110 fStatistics
= new TmfStateStatistics(trace
, totalsSS
, eventTypesSS
);
115 protected void canceling() {
117 * FIXME The "right" way to cancel state system construction is not
120 totalsModule
.cancel();
121 eventTypesModule
.cancel();
123 ITmfStatistics stats
= fStatistics
;
129 // ------------------------------------------------------------------------
130 // ITmfStateSystemAnalysisModule
131 // ------------------------------------------------------------------------
134 public ITmfStateSystem
getStateSystem(String id
) {
136 case TmfStatisticsTotalsModule
.ID
:
137 return totalsModule
.getStateSystem();
138 case TmfStatisticsEventTypesModule
.ID
:
139 return eventTypesModule
.getStateSystem();
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
;
156 public Iterable
<ITmfStateSystem
> getStateSystems() {
157 List
<ITmfStateSystem
> list
= new LinkedList
<>();
158 list
.add(totalsModule
.getStateSystem());
159 list
.add(eventTypesModule
.getStateSystem());