1 /*******************************************************************************
2 * Copyright (c) 2013, 2014 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
.tracecompass
.tmf
.core
.statistics
;
15 import java
.util
.LinkedList
;
16 import java
.util
.List
;
17 import java
.util
.concurrent
.CountDownLatch
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.jdt
.annotation
.Nullable
;
22 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 * Analysis module to compute the statistics of a trace.
32 * @author Alexandre Montplaisir
34 public class TmfStatisticsModule
extends TmfAbstractAnalysisModule
35 implements ITmfAnalysisModuleWithStateSystems
{
37 /** ID of this analysis module */
38 public static final String ID
= "org.eclipse.linuxtools.tmf.core.statistics.analysis"; //$NON-NLS-1$
40 /** The trace's statistics */
41 private ITmfStatistics fStatistics
= null;
43 private final TmfStateSystemAnalysisModule totalsModule
= new TmfStatisticsTotalsModule();
44 private final TmfStateSystemAnalysisModule eventTypesModule
= new TmfStatisticsEventTypesModule();
46 private final CountDownLatch fInitialized
= new CountDownLatch(1);
51 public TmfStatisticsModule() {
56 * Get the statistics object built by this analysis
58 * @return The ITmfStatistics object
61 public ITmfStatistics
getStatistics() {
66 * Wait until the analyses/state systems underneath are ready to be queried.
68 public void waitForInitialization() {
71 } catch (InterruptedException e
) {}
74 // ------------------------------------------------------------------------
75 // TmfAbstractAnalysisModule
76 // ------------------------------------------------------------------------
79 public void dispose() {
81 * The sub-analyses are not registered to the trace directly, so we need
82 * to tell them when the trace is disposed.
85 totalsModule
.dispose();
86 eventTypesModule
.dispose();
90 public void setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
91 super.setTrace(trace
);
94 * Since these sub-analyzes are not built from an extension point, we
95 * have to assign the trace ourselves. Very important to do so before
98 totalsModule
.setTrace(trace
);
99 eventTypesModule
.setTrace(trace
);
103 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
104 ITmfTrace trace
= getTrace();
106 /* This analysis was cancelled in the meantime */
107 fInitialized
.countDown();
111 IStatus status1
= totalsModule
.schedule();
112 IStatus status2
= eventTypesModule
.schedule();
113 if (!(status1
.isOK() && status2
.isOK())) {
115 fInitialized
.countDown();
119 /* Wait until the two modules are initialized */
120 totalsModule
.waitForInitialization();
121 eventTypesModule
.waitForInitialization();
123 ITmfStateSystem totalsSS
= totalsModule
.getStateSystem();
124 ITmfStateSystem eventTypesSS
= eventTypesModule
.getStateSystem();
126 if (totalsSS
== null || eventTypesSS
== null) {
127 /* This analysis was cancelled in the meantime */
128 fInitialized
.countDown();
132 fStatistics
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
134 /* fStatistics is now set, consider this module initialized */
135 fInitialized
.countDown();
138 * The rest of this "execute" will encompass the "execute" of the two
141 if (!(totalsModule
.waitForCompletion(monitor
) &&
142 eventTypesModule
.waitForCompletion(monitor
))) {
149 protected void canceling() {
151 * FIXME The "right" way to cancel state system construction is not
156 ITmfStatistics stats
= fStatistics
;
162 private void cancelSubAnalyses() {
163 totalsModule
.cancel();
164 eventTypesModule
.cancel();
167 // ------------------------------------------------------------------------
168 // ITmfStateSystemAnalysisModule
169 // ------------------------------------------------------------------------
172 public ITmfStateSystem
getStateSystem(String id
) {
174 case TmfStatisticsTotalsModule
.ID
:
175 return totalsModule
.getStateSystem();
176 case TmfStatisticsEventTypesModule
.ID
:
177 return eventTypesModule
.getStateSystem();
184 public Iterable
<ITmfStateSystem
> getStateSystems() {
185 List
<ITmfStateSystem
> list
= new LinkedList
<>();
186 list
.add(totalsModule
.getStateSystem());
187 list
.add(eventTypesModule
.getStateSystem());