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
.linuxtools
.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
.linuxtools
.statesystem
.core
.ITmfStateSystem
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.analysis
.TmfAbstractAnalysisModule
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfAnalysisException
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfAnalysisModuleWithStateSystems
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 * Analysis module to compute the statistics of a trace.
32 * @author Alexandre Montplaisir
35 public class TmfStatisticsModule
extends TmfAbstractAnalysisModule
36 implements ITmfAnalysisModuleWithStateSystems
{
38 /** ID of this analysis module */
39 public static final 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 void setTrace(ITmfTrace trace
) throws TmfAnalysisException
{
92 super.setTrace(trace
);
95 * Since these sub-analyzes are not built from an extension point, we
96 * have to assign the trace ourselves. Very important to do so before
99 totalsModule
.setTrace(trace
);
100 eventTypesModule
.setTrace(trace
);
104 protected boolean executeAnalysis(IProgressMonitor monitor
) throws TmfAnalysisException
{
105 ITmfTrace trace
= getTrace();
107 /* This analysis's trace should not be null when this is called */
108 throw new IllegalStateException();
111 IStatus status1
= totalsModule
.schedule();
112 IStatus status2
= eventTypesModule
.schedule();
113 if (!(status1
.isOK() && status2
.isOK())) {
118 /* Wait until the two modules are initialized */
119 totalsModule
.waitForInitialization();
120 eventTypesModule
.waitForInitialization();
122 ITmfStateSystem totalsSS
= totalsModule
.getStateSystem();
123 ITmfStateSystem eventTypesSS
= eventTypesModule
.getStateSystem();
125 if (totalsSS
== null || eventTypesSS
== null) {
126 /* Better safe than sorry... */
127 throw new IllegalStateException();
130 fStatistics
= new TmfStateStatistics(totalsSS
, eventTypesSS
);
132 /* fStatistics is now set, consider this module initialized */
133 fInitialized
.countDown();
136 * The rest of this "execute" will encompass the "execute" of the two
139 if (!(totalsModule
.waitForCompletion(monitor
) &&
140 eventTypesModule
.waitForCompletion(monitor
))) {
147 protected void canceling() {
149 * FIXME The "right" way to cancel state system construction is not
154 ITmfStatistics stats
= fStatistics
;
160 private void cancelSubAnalyses() {
161 totalsModule
.cancel();
162 eventTypesModule
.cancel();
165 // ------------------------------------------------------------------------
166 // ITmfStateSystemAnalysisModule
167 // ------------------------------------------------------------------------
170 public ITmfStateSystem
getStateSystem(String id
) {
172 case TmfStatisticsTotalsModule
.ID
:
173 return totalsModule
.getStateSystem();
174 case TmfStatisticsEventTypesModule
.ID
:
175 return eventTypesModule
.getStateSystem();
182 public Iterable
<ITmfStateSystem
> getStateSystems() {
183 List
<ITmfStateSystem
> list
= new LinkedList
<>();
184 list
.add(totalsModule
.getStateSystem());
185 list
.add(eventTypesModule
.getStateSystem());