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
.NonNull
;
22 import org
.eclipse
.jdt
.annotation
.Nullable
;
23 import org
.eclipse
.tracecompass
.statesystem
.core
.ITmfStateSystem
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.exceptions
.TmfAnalysisException
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
31 * Analysis module to compute the statistics of a trace.
33 * @author Alexandre Montplaisir
35 public class TmfStatisticsModule
extends TmfAbstractAnalysisModule
36 implements ITmfAnalysisModuleWithStateSystems
{
38 /** ID of this analysis module */
39 public static final @NonNull String ID
= "org.eclipse.linuxtools.tmf.core.statistics.analysis"; //$NON-NLS-1$
41 /** The trace's statistics */
42 private ITmfStatistics fStatistics
= null;
44 private final TmfStateSystemAnalysisModule totalsModule
= new TmfStatisticsTotalsModule();
45 private final TmfStateSystemAnalysisModule eventTypesModule
= new TmfStatisticsEventTypesModule();
47 private final CountDownLatch fInitialized
= new CountDownLatch(1);
52 public TmfStatisticsModule() {
57 * Get the statistics object built by this analysis
59 * @return The ITmfStatistics object
62 public ITmfStatistics
getStatistics() {
67 * Wait until the analyses/state systems underneath are ready to be queried.
70 public void waitForInitialization() {
73 } catch (InterruptedException e
) {}
76 // ------------------------------------------------------------------------
77 // TmfAbstractAnalysisModule
78 // ------------------------------------------------------------------------
81 public void dispose() {
83 * The sub-analyses are not registered to the trace directly, so we need
84 * to tell them when the trace is disposed.
87 totalsModule
.dispose();
88 eventTypesModule
.dispose();
92 public boolean setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
93 if (!super.setTrace(trace
)) {
98 * Since these sub-analyzes are not built from an extension point, we
99 * have to assign the trace ourselves. Very important to do so before
100 * calling schedule()!
102 if (!totalsModule
.setTrace(trace
)) {
105 if (!eventTypesModule
.setTrace(trace
)) {
112 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
113 ITmfTrace trace
= getTrace();
115 /* This analysis was cancelled in the meantime */
116 fInitialized
.countDown();
120 IStatus status1
= totalsModule
.schedule();
121 IStatus status2
= eventTypesModule
.schedule();
122 if (!(status1
.isOK() && status2
.isOK())) {
124 fInitialized
.countDown();
128 /* Wait until the two modules are initialized */
129 totalsModule
.waitForInitialization();
130 eventTypesModule
.waitForInitialization();
132 ITmfStateSystem totalsSS
= totalsModule
.getStateSystem();
133 ITmfStateSystem eventTypesSS
= eventTypesModule
.getStateSystem();
135 if (totalsSS
== null || eventTypesSS
== null) {
136 /* This analysis was cancelled in the meantime */
137 fInitialized
.countDown();
141 fStatistics
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
143 /* fStatistics is now set, consider this module initialized */
144 fInitialized
.countDown();
147 * The rest of this "execute" will encompass the "execute" of the two
150 if (!(totalsModule
.waitForCompletion(monitor
) &&
151 eventTypesModule
.waitForCompletion(monitor
))) {
158 protected void canceling() {
160 * FIXME The "right" way to cancel state system construction is not
165 ITmfStatistics stats
= fStatistics
;
171 private void cancelSubAnalyses() {
172 totalsModule
.cancel();
173 eventTypesModule
.cancel();
176 // ------------------------------------------------------------------------
177 // ITmfStateSystemAnalysisModule
178 // ------------------------------------------------------------------------
181 public ITmfStateSystem
getStateSystem(String id
) {
183 case TmfStatisticsTotalsModule
.ID
:
184 return totalsModule
.getStateSystem();
185 case TmfStatisticsEventTypesModule
.ID
:
186 return eventTypesModule
.getStateSystem();
193 public @NonNull Iterable
<@NonNull ITmfStateSystem
> getStateSystems() {
194 List
<@NonNull ITmfStateSystem
> list
= new LinkedList
<>();
195 ITmfStateSystem totalsStateSystem
= totalsModule
.getStateSystem();
196 if (totalsStateSystem
!= null) {
197 list
.add(totalsStateSystem
);
199 ITmfStateSystem eventTypesStateSystem
= eventTypesModule
.getStateSystem();
200 if (eventTypesStateSystem
!= null) {
201 list
.add(eventTypesStateSystem
);