From: Alexandre Montplaisir Date: Tue, 12 Nov 2013 00:47:03 +0000 (-0500) Subject: tmf: Move the trace statistics to the analysis framework X-Git-Url: http://drtracing.org/?a=commitdiff_plain;h=8192f2c6a4c1e56dcd80d1b51ee0c2d2de6a41e6;p=deliverable%2Ftracecompass.git tmf: Move the trace statistics to the analysis framework By itself, this patch causes a bug where the Statistics view will not be populated unless it is re-opened *after* the trace has been loaded. The patch following this one fixes this (and unfortunately, that one depends on changes from this one, so it wasn't trivial to re-order them). Change-Id: I8b6c59d70e84fdc5971665e1e78d096e3abe30db Signed-off-by: Alexandre Montplaisir Reviewed-on: https://git.eclipse.org/r/19412 Reviewed-by: Matthew Khouzam IP-Clean: Matthew Khouzam Tested-by: Hudson CI --- diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java index 8b853ac645..385217cb23 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfExperimentTest.java @@ -37,7 +37,6 @@ import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest; import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; -import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; @@ -173,13 +172,6 @@ public class TmfExperimentTest { // State system, statistics and modules methods // ------------------------------------------------------------------------ - @Test - public void testGetStatistics() { - /* There should not be any experiment-specific statistics */ - ITmfStatistics stats = fExperiment.getStatistics(); - assertNull(stats); - } - @Test public void testGetAnalysisModules() { /* There should not be any modules at this point */ diff --git a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java index c7f059efba..e81b2396e2 100644 --- a/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java +++ b/org.eclipse.linuxtools.tmf.core.tests/src/org/eclipse/linuxtools/tmf/core/tests/trace/TmfTraceTest.java @@ -38,7 +38,6 @@ import org.eclipse.linuxtools.tmf.core.request.ITmfEventRequest.ExecutionType; import org.eclipse.linuxtools.tmf.core.request.TmfEventRequest; import org.eclipse.linuxtools.tmf.core.signal.TmfSignalManager; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; -import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.tests.TmfCoreTestPlugin; import org.eclipse.linuxtools.tmf.core.tests.shared.TmfTestTrace; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; @@ -439,13 +438,6 @@ public class TmfTraceTest { // State system, statistics and modules methods // ------------------------------------------------------------------------ - @Test - public void testGetStatistics() { - /* Should be null in unit tests */ - ITmfStatistics stats = fTrace.getStatistics(); - assertNull(stats); - } - @Test public void testGetModulesByClass() { /* There should not be any modules at this point */ diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java deleted file mode 100644 index 9c5afc166e..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderEventTypes.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexandre Montplaisir - Initial API and implementation - * Patrick Tasse - Fix javadoc - ******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.statistics; - -import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; -import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent; -import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; -import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; -import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; -import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; -import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; -import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; -import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; - -/** - * The state provider for traces statistics that use TmfStateStatistics. It - * should work with any trace type for which we can use the state system. - * - * It will store number of events seen, per event types. The resulting attribute - * tree will look like this: - * - *
- * (root)
- *   \-- event_types
- *        |-- (event name 1)
- *        |-- (event name 2)
- *        |-- (event name 3)
- *       ...
- * 
- * - * And each (event name)'s value will be an integer, representing how many times - * this particular event type has been seen in the trace so far. - * - * @author Alexandre Montplaisir - * @version 1.0 - */ -class StatsProviderEventTypes extends AbstractTmfStateProvider { - - /** - * Version number of this input handler. Please bump this if you modify the - * contents of the generated state history in some way. - */ - private static final int VERSION = 2; - - /** - * Constructor - * - * @param trace - * The trace for which we build this state system - */ - public StatsProviderEventTypes(ITmfTrace trace) { - super(trace, ITmfEvent.class ,"TMF Statistics, events per type"); //$NON-NLS-1$ - } - - @Override - public int getVersion() { - return VERSION; - } - - @Override - public StatsProviderEventTypes getNewInstance() { - return new StatsProviderEventTypes(this.getTrace()); - } - - @Override - protected void eventHandle(ITmfEvent event) { - int quark; - - /* Since this can be used for any trace types, normalize all the - * timestamp values to nanoseconds. */ - final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - - final String eventName = event.getType().getName(); - - try { - /* Special handling for lost events */ - if (event instanceof ITmfLostEvent) { - ITmfLostEvent le = (ITmfLostEvent) event; - quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); - - int curVal = ss.queryOngoingState(quark).unboxInt(); - if (curVal == -1) { - curVal = 0; - } - - TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents())); - ss.modifyAttribute(ts, value, quark); - return; - } - - /* Number of events of each type, globally */ - quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); - ss.incrementAttribute(ts, quark); - -// /* Number of events per CPU */ -// quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); -// ss.incrementAttribute(ts, quark); -// -// /* Number of events per process */ -// quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); -// ss.incrementAttribute(ts, quark); - - } catch (StateValueTypeException e) { - e.printStackTrace(); - } catch (TimeRangeException e) { - e.printStackTrace(); - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } - } -} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java deleted file mode 100644 index 894e9f500d..0000000000 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/StatsProviderTotals.java +++ /dev/null @@ -1,93 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012, 2013 Ericsson - * - * All rights reserved. This program and the accompanying materials are - * made available under the terms of the Eclipse Public License v1.0 which - * accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Alexandre Montplaisir - Initial API and implementation - * Patrick Tasse - Fix javadoc - ******************************************************************************/ - -package org.eclipse.linuxtools.tmf.core.statistics; - -import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; -import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent; -import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; -import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; -import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; -import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; -import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; -import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; -import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; - -/** - * The state provider for traces statistics that use TmfStateStatistics. It - * should work with any trace type for which we can use the state system. - * - * Only one attribute will be stored, containing the total of events seen so - * far. The resulting attribute tree will look like this: - * - *
- * (root)
- *   \-- total
- * 
- * - * @author Alexandre Montplaisir - * @version 1.0 - */ -class StatsProviderTotals extends AbstractTmfStateProvider { - - /** - * Version number of this input handler. Please bump this if you modify the - * contents of the generated state history in some way. - */ - private static final int VERSION = 2; - - /** - * Constructor - * - * @param trace - * The trace for which we build this state system - */ - public StatsProviderTotals(ITmfTrace trace) { - super(trace, ITmfEvent.class ,"TMF Statistics, event totals"); //$NON-NLS-1$ - } - - @Override - public int getVersion() { - return VERSION; - } - - @Override - public StatsProviderTotals getNewInstance() { - return new StatsProviderTotals(this.getTrace()); - } - - @Override - protected void eventHandle(ITmfEvent event) { - /* Do not count lost events in the total */ - if (event instanceof ITmfLostEvent) { - return; - } - - /* Since this can be used for any trace types, normalize all the - * timestamp values to nanoseconds. */ - final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); - - try { - /* Total number of events */ - int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL); - ss.incrementAttribute(ts, quark); - - } catch (StateValueTypeException e) { - e.printStackTrace(); - } catch (TimeRangeException e) { - e.printStackTrace(); - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } - } -} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java index 1a2ddedfc1..b43a622f5a 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStateStatistics.java @@ -18,6 +18,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; +import org.eclipse.jdt.annotation.NonNull; import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; import org.eclipse.linuxtools.tmf.core.exceptions.StateSystemDisposedException; import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; @@ -31,7 +32,6 @@ import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemFactory; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; -import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; /** * Implementation of ITmfStatistics which uses a state history for storing its @@ -49,31 +49,6 @@ import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; */ public class TmfStateStatistics implements ITmfStatistics { - // ------------------------------------------------------------------------ - // Constants - // ------------------------------------------------------------------------ - - /** - * @deprecated Do not use, it's been replaced by {@link #TOTALS_STATE_ID} - *  and {@link #TYPES_STATE_ID} - */ - @Deprecated - public static final String STATE_ID = "org.eclipse.linuxtools.tmf.statistics"; //$NON-NLS-1$ - - /** ID for the "event totals" statistics state system - * @since 2.2 */ - public static final String TOTALS_STATE_ID = "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$ - - /** ID for the "event types" statistics state system - * @since 2.2 */ - public static final String TYPES_STATE_ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$ - - /** Filename for the "event totals" state history file */ - private static final String TOTALS_STATE_FILENAME = "statistics-totals.ht"; //$NON-NLS-1$ - - /** Filename for the "event types" state history file */ - private static final String TYPES_STATE_FILENAME = "statistics-types.ht"; //$NON-NLS-1$ - // ------------------------------------------------------------------------ // Fields // ------------------------------------------------------------------------ @@ -90,50 +65,23 @@ public class TmfStateStatistics implements ITmfStatistics { // Constructors // ------------------------------------------------------------------------ - /** - * Empty constructor. The resulting TmfStatistics object will not be usable, - * but it might be needed for sub-classes. - */ - public TmfStateStatistics() { - totalsStats = null; - typesStats = null; - trace = null; - } - /** * Constructor * * @param trace * The trace for which we build these statistics - * @throws TmfTraceException - * If something went wrong trying to initialize the statistics + * @param totals + * The state system containing the "totals" information + * @param eventTypes + * The state system containing the "event types" information + * @since 3.0 */ - public TmfStateStatistics(ITmfTrace trace) throws TmfTraceException { + public TmfStateStatistics(@NonNull ITmfTrace trace, + @NonNull ITmfStateSystem totals, + @NonNull ITmfStateSystem eventTypes) { this.trace = trace; - String directory = TmfTraceManager.getSupplementaryFileDir(trace); - - final File totalsFile = new File(directory + TOTALS_STATE_FILENAME); - final ITmfStateProvider totalsInput = new StatsProviderTotals(trace); - this.totalsStats = TmfStateSystemFactory.newFullHistory(totalsFile, totalsInput, false); - - final File typesFile = new File(directory + TYPES_STATE_FILENAME); - final ITmfStateProvider typesInput = new StatsProviderEventTypes(trace); - this.typesStats = TmfStateSystemFactory.newFullHistory(typesFile, typesInput, false); - - registerStateSystems(); - } - - /** - * Old manual constructor. - * - * @param trace Trace - * @param historyFile Full history file - * @deprecated Need to use {@link #TmfStateStatistics(ITmfTrace trace, - * File fullHistoryFile, File partialHistoryFile)} now. - */ - @Deprecated - public TmfStateStatistics(ITmfTrace trace, File historyFile) { - this(); + this.totalsStats = totals; + this.typesStats = eventTypes; } /** @@ -151,22 +99,34 @@ public class TmfStateStatistics implements ITmfStatistics { * If the file could not be written to * @since 2.2 */ + @Deprecated public TmfStateStatistics(ITmfTrace trace, File totalsHistoryFile, File typesHistoryFile) throws TmfTraceException { this.trace = trace; - final ITmfStateProvider totalsInput = new StatsProviderTotals(trace); - final ITmfStateProvider typesInput = new StatsProviderEventTypes(trace); + final ITmfStateProvider totalsInput = new TmfStatisticsTotalsModule().new StatsProviderTotals(trace); + final ITmfStateProvider typesInput = new TmfStatisticsEventTypesModule().new StatsProviderEventTypes(trace); this.totalsStats = TmfStateSystemFactory.newFullHistory(totalsHistoryFile, totalsInput, true); this.typesStats = TmfStateSystemFactory.newFullHistory(typesHistoryFile, typesInput, true); - registerStateSystems(); } /** - * Register the state systems used here into the trace's state system map. + * Return the state system containing the "totals" values + * + * @return The "totals" state system + * @since 3.0 + */ + public ITmfStateSystem getTotalsSS() { + return totalsStats; + } + + /** + * Return the state system containing the "event types" values + * + * @return The "event types" state system + * @since 3.0 */ - private void registerStateSystems() { - trace.registerStateSystem(TOTALS_STATE_ID, totalsStats); - trace.registerStateSystem(TYPES_STATE_ID, typesStats); + public ITmfStateSystem getEventTypesSS() { + return typesStats; } // ------------------------------------------------------------------------ @@ -299,11 +259,7 @@ public class TmfStateStatistics implements ITmfStatistics { } catch (TimeRangeException e) { /* Assume there is no events, nothing will be put in the map. */ - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } catch (StateValueTypeException e) { - e.printStackTrace(); - } catch (StateSystemDisposedException e) { + } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) { e.printStackTrace(); } return map; @@ -388,16 +344,12 @@ public class TmfStateStatistics implements ITmfStatistics { } catch (TimeRangeException e) { /* Assume there is no events, nothing will be put in the map. */ - } catch (AttributeNotFoundException e) { + } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) { /* * These other exception types would show a logic problem however, * so they should not happen. */ e.printStackTrace(); - } catch (StateValueTypeException e) { - e.printStackTrace(); - } catch (StateSystemDisposedException e) { - e.printStackTrace(); } return map; } @@ -418,11 +370,7 @@ public class TmfStateStatistics implements ITmfStatistics { } catch (TimeRangeException e) { /* Assume there is no events for that range */ - } catch (AttributeNotFoundException e) { - e.printStackTrace(); - } catch (StateValueTypeException e) { - e.printStackTrace(); - } catch (StateSystemDisposedException e) { + } catch (AttributeNotFoundException | StateValueTypeException | StateSystemDisposedException e) { e.printStackTrace(); } diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java new file mode 100644 index 0000000000..6260eeb19d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsEventTypesModule.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + ******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.statistics; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent; +import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; +import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; +import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; +import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; +import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; +import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; + +/** + * The analysis module building the "event types" statistics state system. + * + * It is not in the extension point (and as such, not registered in the + * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule. + * + * @author Alexandre Montplaisir + * @since 3.0 + */ +public class TmfStatisticsEventTypesModule extends TmfStateSystemAnalysisModule { + + /** + * The ID of this analysis module (which is also the ID of the state system) + */ + public static final String ID = "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$ + + private static final String NAME = "TMF Statistics, events per type"; //$NON-NLS-1$ + + /** + * Constructor + */ + public TmfStatisticsEventTypesModule() { + setId(ID); + setName(NAME); + } + + @Override + protected ITmfStateProvider createStateProvider() { + return new StatsProviderEventTypes(getTrace()); + } + + @Override + protected StateSystemBackendType getBackendType() { + return StateSystemBackendType.FULL; + } + + @Override + protected String getSsFileName() { + return "statistics-types.ht"; //$NON-NLS-1$ + } + + + /** + * The state provider for traces statistics that use TmfStateStatistics. It + * should work with any trace type for which we can use the state system. + * + * It will store number of events seen, per event types. The resulting attribute + * tree will look like this: + * + *
+     * (root)
+     *   \-- event_types
+     *        |-- (event name 1)
+     *        |-- (event name 2)
+     *        |-- (event name 3)
+     *       ...
+     * 
+ * + * And each (event name)'s value will be an integer, representing how many times + * this particular event type has been seen in the trace so far. + * + * @author Alexandre Montplaisir + * @version 1.0 + */ + class StatsProviderEventTypes extends AbstractTmfStateProvider { + + /** + * Version number of this input handler. Please bump this if you modify the + * contents of the generated state history in some way. + */ + private static final int VERSION = 2; + + /** + * Constructor + * + * @param trace + * The trace for which we build this state system + */ + public StatsProviderEventTypes(ITmfTrace trace) { + super(trace, ITmfEvent.class ,"TMF Statistics, events per type"); //$NON-NLS-1$ + } + + @Override + public int getVersion() { + return VERSION; + } + + @Override + public StatsProviderEventTypes getNewInstance() { + return new StatsProviderEventTypes(this.getTrace()); + } + + @Override + protected void eventHandle(ITmfEvent event) { + int quark; + + /* Since this can be used for any trace types, normalize all the + * timestamp values to nanoseconds. */ + final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + + final String eventName = event.getType().getName(); + + try { + /* Special handling for lost events */ + if (event instanceof ITmfLostEvent) { + ITmfLostEvent le = (ITmfLostEvent) event; + quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); + + int curVal = ss.queryOngoingState(quark).unboxInt(); + if (curVal == -1) { + curVal = 0; + } + + TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents())); + ss.modifyAttribute(ts, value, quark); + return; + } + + /* Number of events of each type, globally */ + quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); + ss.incrementAttribute(ts, quark); + +// /* Number of events per CPU */ +// quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); +// ss.incrementAttribute(ts, quark); + // +// /* Number of events per process */ +// quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); +// ss.incrementAttribute(ts, quark); + + } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) { + e.printStackTrace(); + } + } + } +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java new file mode 100644 index 0000000000..cd4b394a04 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/statistics/TmfStatisticsTotalsModule.java @@ -0,0 +1,134 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + ******************************************************************************/ + +package org.eclipse.linuxtools.tmf.core.statistics; + +import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; +import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent; +import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; +import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; +import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; +import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateProvider; +import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; +import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; + +/** + * The analysis module building the "totals" statistics state system. + * + * It is not in the extension point (and as such, not registered in the + * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule. + * + * @author Alexandre Montplaisir + * @since 3.0 + */ +public class TmfStatisticsTotalsModule extends TmfStateSystemAnalysisModule { + + /** + * The ID of this analysis module (which is also the ID of the state system) + */ + public static final String ID = "org.eclipse.linuxtools.tmf.statistics.totals"; //$NON-NLS-1$ + + private static final String NAME = "TMF Statistics, event totals"; //$NON-NLS-1$ + + /** + * Constructor + */ + public TmfStatisticsTotalsModule() { + setId(ID); + setName(NAME); + } + + @Override + protected ITmfStateProvider createStateProvider() { + return new StatsProviderTotals(getTrace()); + } + + @Override + protected StateSystemBackendType getBackendType() { + return StateSystemBackendType.FULL; + } + + @Override + protected String getSsFileName() { + return "statistics-totals.ht"; //$NON-NLS-1$ + } + + + /** + * The state provider for traces statistics that use TmfStateStatistics. It + * should work with any trace type for which we can use the state system. + * + * Only one attribute will be stored, containing the total of events seen so + * far. The resulting attribute tree will look like this: + * + *
+     * (root)
+     *   \-- total
+     * 
+ * + * @author Alexandre Montplaisir + * @version 1.0 + */ + class StatsProviderTotals extends AbstractTmfStateProvider { + + /** + * Version number of this input handler. Please bump this if you modify the + * contents of the generated state history in some way. + */ + private static final int VERSION = 2; + + /** + * Constructor + * + * @param trace + * The trace for which we build this state system + */ + public StatsProviderTotals(ITmfTrace trace) { + super(trace, ITmfEvent.class , NAME); + } + + @Override + public int getVersion() { + return VERSION; + } + + @Override + public StatsProviderTotals getNewInstance() { + return new StatsProviderTotals(this.getTrace()); + } + + @Override + protected void eventHandle(ITmfEvent event) { + /* Do not count lost events in the total */ + if (event instanceof ITmfLostEvent) { + return; + } + + /* Since this can be used for any trace types, normalize all the + * timestamp values to nanoseconds. */ + final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); + + try { + /* Total number of events */ + int quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL); + ss.incrementAttribute(ts, quark); + + } catch (StateValueTypeException | TimeRangeException | AttributeNotFoundException e) { + e.printStackTrace(); + } + } + } + +} diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java index a012d64ce7..9fcfc7d649 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/ITmfTrace.java @@ -27,9 +27,8 @@ import org.eclipse.linuxtools.tmf.core.analysis.IAnalysisModule; import org.eclipse.linuxtools.tmf.core.component.ITmfEventProvider; import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; import org.eclipse.linuxtools.tmf.core.exceptions.TmfTraceException; -import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; -import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; import org.eclipse.linuxtools.tmf.core.timestamp.TmfTimeRange; @@ -196,12 +195,6 @@ public interface ITmfTrace extends ITmfEventProvider { */ int getCacheSize(); - /** - * @return The statistics provider for this trace - * @since 2.0 - */ - ITmfStatistics getStatistics(); - /** * Return the map of state systems associated with this trace. * diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java index 2872025fac..9f8a18d8a2 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/trace/TmfTrace.java @@ -53,8 +53,6 @@ import org.eclipse.linuxtools.tmf.core.signal.TmfTraceOpenedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceRangeUpdatedSignal; import org.eclipse.linuxtools.tmf.core.signal.TmfTraceUpdatedSignal; import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; -import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; -import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics; import org.eclipse.linuxtools.tmf.core.synchronization.ITmfTimestampTransform; import org.eclipse.linuxtools.tmf.core.synchronization.TmfTimestampTransform; import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; @@ -122,8 +120,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { // The trace parser private ITmfEventParser fParser; - // The trace's statistics - private ITmfStatistics fStatistics; /** * The collection of state systems that are registered with this trace. Each @@ -283,27 +279,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { getIndexer().buildIndex(0, TmfTimeRange.ETERNITY, waitForCompletion); } - /** - * The default implementation of TmfTrace uses a TmfStatistics back-end. - * Override this if you want to specify another type (or none at all). - * - * @return An IStatus indicating if the statistics could be built - * successfully or not. - * @since 3.0 - */ - protected IStatus buildStatistics() { - /* - * Initialize the statistics provider, but only if a Resource has been - * set (so we don't build it for experiments, for unit tests, etc.) - */ - try { - fStatistics = (fResource == null ? null : new TmfStateStatistics(this) ); - } catch (TmfTraceException e) { - return new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); - } - return Status.OK_STATUS; - } - /** * Build the state system(s) associated with this trace type. * @@ -405,11 +380,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { getIndexer().dispose(); } - /* Clean up the statistics */ - if (fStatistics != null) { - fStatistics.dispose(); - } - /* Clean up the state systems */ for (ITmfStateSystem ss : fStateSystems.values()) { ss.dispose(); @@ -469,14 +439,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { return fParser; } - /** - * @since 2.0 - */ - @Override - public ITmfStatistics getStatistics() { - return fStatistics; - } - /** * @since 2.0 * @deprecated See {@link ITmfTrace} @@ -787,7 +749,6 @@ public abstract class TmfTrace extends TmfEventProvider implements ITmfTrace { * this trace. */ MultiStatus status = new MultiStatus(Activator.PLUGIN_ID, IStatus.OK, null, null); - status.add(buildStatistics()); status.add(buildStateSystem()); status.add(executeAnalysis()); if (!status.isOK()) { diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 3c2fe469da..6af00f9226 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -1610,4 +1610,18 @@ name="%project.new.category.name"> + + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java index 16ac50dd9d..5613964dc2 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/viewers/statistics/TmfStatisticsViewer.java @@ -42,6 +42,7 @@ import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTree; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeManager; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfStatisticsTreeNode; import org.eclipse.linuxtools.tmf.ui.viewers.statistics.model.TmfTreeContentProvider; +import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; @@ -735,8 +736,13 @@ public class TmfStatisticsViewer extends TmfViewer { continue; } - /* Retrieves the statistics object */ - final ITmfStatistics stats = aTrace.getStatistics(); + /* Retrieve the statistics object */ + final TmfStatisticsModule statsMod = aTrace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID); + if (statsMod == null) { + /* No statistics module available for this trace */ + continue; + } + final ITmfStatistics stats = statsMod.getStatistics(); if (stats == null) { /* * The statistics provider for this trace is not accessible @@ -755,7 +761,7 @@ public class TmfStatisticsViewer extends TmfViewer { * be sent through a {@link TmfStatsUpdatedSignal}, and will be * processed by the signal handler. */ - aTrace.getStatistics().updateStats(isGlobal, start, end); + stats.updateStats(isGlobal, start, end); } } } diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java new file mode 100644 index 0000000000..6197c52d6c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/views/statistics/TmfStatisticsModule.java @@ -0,0 +1,162 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * All rights reserved. This program and the accompanying materials are + * made available under the terms of the Eclipse Public License v1.0 which + * accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Alexandre Montplaisir - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.tmf.ui.views.statistics; + +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.linuxtools.tmf.core.analysis.TmfAbstractAnalysisModule; +import org.eclipse.linuxtools.tmf.core.exceptions.TmfAnalysisException; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfAnalysisModuleWithStateSystems; +import org.eclipse.linuxtools.tmf.core.statesystem.ITmfStateSystem; +import org.eclipse.linuxtools.tmf.core.statesystem.TmfStateSystemAnalysisModule; +import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsEventTypesModule; +import org.eclipse.linuxtools.tmf.core.statistics.TmfStatisticsTotalsModule; +import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; +import org.eclipse.linuxtools.tmf.ui.analysis.TmfAnalysisViewOutput; + +/** + * Analysis module to compute the statistics of a trace. + * + * @author Alexandre Montplaisir + * @since 3.0 + */ +public class TmfStatisticsModule extends TmfAbstractAnalysisModule + implements ITmfAnalysisModuleWithStateSystems { + + /** ID of this analysis module */ + public static final String ID = "org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"; //$NON-NLS-1$ + + /** The trace's statistics */ + private ITmfStatistics fStatistics = null; + + private final TmfStateSystemAnalysisModule totalsModule = new TmfStatisticsTotalsModule(); + private final TmfStateSystemAnalysisModule eventTypesModule = new TmfStatisticsEventTypesModule(); + + /** + * Constructor + */ + public TmfStatisticsModule() { + super(); + this.registerOutput(new TmfAnalysisViewOutput(TmfStatisticsView.ID)); + } + + /** + * Get the statistics object built by this analysis + * + * @return The ITmfStatistics object + */ + public ITmfStatistics getStatistics() { + return fStatistics; + } + + // ------------------------------------------------------------------------ + // TmfAbstractAnalysisModule + // ------------------------------------------------------------------------ + + @Override + protected boolean executeAnalysis(IProgressMonitor monitor) throws TmfAnalysisException { + ITmfTrace trace = getTrace(); + if (trace == null) { + /* This analysis's trace should not be null when this is called */ + throw new IllegalStateException(); + } + + /* + * Since these sub-analyzes are not built from an extension point, we + * have to assign the trace ourselves. Very important to do so before + * calling schedule()! + */ + totalsModule.setTrace(trace); + eventTypesModule.setTrace(trace); + + IStatus status1 = totalsModule.schedule(); + IStatus status2 = eventTypesModule.schedule(); + if (!status1.isOK() || !status2.isOK()) { + return false; + } + + /* + * The "execute" of this trace will encompass the "execute" of the two + * sub-analyzes. + */ + if (!totalsModule.waitForCompletion(monitor) || + !eventTypesModule.waitForCompletion(monitor)) { + return false; + } + + ITmfStateSystem totalsSS = totalsModule.getStateSystem(); + ITmfStateSystem eventTypesSS = eventTypesModule.getStateSystem(); + + if (totalsSS == null || eventTypesSS == null) { + /* Better safe than sorry... */ + throw new IllegalStateException(); + } + + fStatistics = new TmfStateStatistics(trace, totalsSS, eventTypesSS); + return true; + } + + @Override + protected void canceling() { + /* + * FIXME The "right" way to cancel state system construction is not + * available yet... + */ + totalsModule.cancel(); + eventTypesModule.cancel(); + + ITmfStatistics stats = fStatistics; + if (stats != null) { + stats.dispose(); + } + } + + // ------------------------------------------------------------------------ + // ITmfStateSystemAnalysisModule + // ------------------------------------------------------------------------ + + @Override + public ITmfStateSystem getStateSystem(String id) { + switch (id) { + case TmfStatisticsTotalsModule.ID: + return totalsModule.getStateSystem(); + case TmfStatisticsEventTypesModule.ID: + return eventTypesModule.getStateSystem(); + default: + return null; + } + } + + @Override + public String getStateSystemId(ITmfStateSystem ss) { + if (ss.equals(totalsModule.getStateSystem())) { + return TmfStatisticsTotalsModule.ID; + } else if (ss.equals(eventTypesModule.getStateSystem())){ + return TmfStatisticsEventTypesModule.ID; + } + return null; + } + + @Override + public Iterable getStateSystems() { + List list = new LinkedList<>(); + list.add(totalsModule.getStateSystem()); + list.add(eventTypesModule.getStateSystem()); + return list; + } +} diff --git a/org.eclipse.linuxtools.tracing.examples/src/org/eclipse/linuxtools/tracing/examples/ui/viewers/histogram/NewHistogramViewer.java b/org.eclipse.linuxtools.tracing.examples/src/org/eclipse/linuxtools/tracing/examples/ui/viewers/histogram/NewHistogramViewer.java index e0a722fe24..aa033c263c 100644 --- a/org.eclipse.linuxtools.tracing.examples/src/org/eclipse/linuxtools/tracing/examples/ui/viewers/histogram/NewHistogramViewer.java +++ b/org.eclipse.linuxtools.tracing.examples/src/org/eclipse/linuxtools/tracing/examples/ui/viewers/histogram/NewHistogramViewer.java @@ -19,6 +19,7 @@ import org.eclipse.linuxtools.tmf.core.statistics.ITmfStatistics; import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; import org.eclipse.linuxtools.tmf.core.trace.TmfTraceManager; import org.eclipse.linuxtools.tmf.ui.viewers.xycharts.barcharts.TmfBarChartViewer; +import org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; @@ -73,7 +74,14 @@ public class NewHistogramViewer extends TmfBarChartViewer { /* Add the values for each trace */ for (ITmfTrace trace : TmfTraceManager.getTraceSet(getTrace())) { - ITmfStatistics stats = trace.getStatistics(); + /* Retrieve the statistics object */ + final TmfStatisticsModule statsMod = + trace.getAnalysisModuleOfClass(TmfStatisticsModule.class, TmfStatisticsModule.ID); + if (statsMod == null) { + /* No statistics module available for this trace */ + continue; + } + final ITmfStatistics stats = statsMod.getStatistics(); List values = stats.histogramQuery(start, end, nb); for (int i = 0; i < nb; i++) {