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.
69 public void waitForInitialization() {
72 } catch (InterruptedException e
) {}
75 // ------------------------------------------------------------------------
76 // TmfAbstractAnalysisModule
77 // ------------------------------------------------------------------------
80 public void dispose() {
82 * The sub-analyses are not registered to the trace directly, so we need
83 * to tell them when the trace is disposed.
86 totalsModule
.dispose();
87 eventTypesModule
.dispose();
91 public boolean setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
92 if (!super.setTrace(trace
)) {
97 * Since these sub-analyzes are not built from an extension point, we
98 * have to assign the trace ourselves. Very important to do so before
101 if (!totalsModule
.setTrace(trace
)) {
104 if (!eventTypesModule
.setTrace(trace
)) {
111 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
112 ITmfTrace trace
= getTrace();
114 /* This analysis was cancelled in the meantime */
115 fInitialized
.countDown();
119 IStatus status1
= totalsModule
.schedule();
120 IStatus status2
= eventTypesModule
.schedule();
121 if (!(status1
.isOK() && status2
.isOK())) {
123 fInitialized
.countDown();
127 /* Wait until the two modules are initialized */
128 totalsModule
.waitForInitialization();
129 eventTypesModule
.waitForInitialization();
131 ITmfStateSystem totalsSS
= totalsModule
.getStateSystem();
132 ITmfStateSystem eventTypesSS
= eventTypesModule
.getStateSystem();
134 if (totalsSS
== null || eventTypesSS
== null) {
135 /* This analysis was cancelled in the meantime */
136 fInitialized
.countDown();
140 fStatistics
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
142 /* fStatistics is now set, consider this module initialized */
143 fInitialized
.countDown();
146 * The rest of this "execute" will encompass the "execute" of the two
149 if (!(totalsModule
.waitForCompletion(monitor
) &&
150 eventTypesModule
.waitForCompletion(monitor
))) {
157 protected void canceling() {
159 * FIXME The "right" way to cancel state system construction is not
164 ITmfStatistics stats
= fStatistics
;
170 private void cancelSubAnalyses() {
171 totalsModule
.cancel();
172 eventTypesModule
.cancel();
175 // ------------------------------------------------------------------------
176 // ITmfStateSystemAnalysisModule
177 // ------------------------------------------------------------------------
180 public ITmfStateSystem
getStateSystem(String id
) {
182 case TmfStatisticsTotalsModule
.ID
:
183 return totalsModule
.getStateSystem();
184 case TmfStatisticsEventTypesModule
.ID
:
185 return eventTypesModule
.getStateSystem();
192 public @NonNull Iterable
<@NonNull ITmfStateSystem
> getStateSystems() {
193 List
<@NonNull ITmfStateSystem
> list
= new LinkedList
<>();
194 ITmfStateSystem totalsStateSystem
= totalsModule
.getStateSystem();
195 if (totalsStateSystem
!= null) {
196 list
.add(totalsStateSystem
);
198 ITmfStateSystem eventTypesStateSystem
= eventTypesModule
.getStateSystem();
199 if (eventTypesStateSystem
!= null) {
200 list
.add(eventTypesStateSystem
);