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;
// 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 */
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;
// 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 */
+++ /dev/null
-/*******************************************************************************
- * 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:
- *
- * <pre>
- * (root)
- * \-- event_types
- * |-- (event name 1)
- * |-- (event name 2)
- * |-- (event name 3)
- * ...
- * </pre>
- *
- * 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();
- }
- }
-}
+++ /dev/null
-/*******************************************************************************
- * 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:
- *
- * <pre>
- * (root)
- * \-- total
- * </pre>
- *
- * @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();
- }
- }
-}
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;
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
*/
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
// ------------------------------------------------------------------------
// 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;
}
/**
* 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;
}
// ------------------------------------------------------------------------
} 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;
} 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;
}
} 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();
}
--- /dev/null
+/*******************************************************************************
+ * 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:
+ *
+ * <pre>
+ * (root)
+ * \-- event_types
+ * |-- (event name 1)
+ * |-- (event name 2)
+ * |-- (event name 3)
+ * ...
+ * </pre>
+ *
+ * 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();
+ }
+ }
+ }
+}
--- /dev/null
+/*******************************************************************************
+ * 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:
+ *
+ * <pre>
+ * (root)
+ * \-- total
+ * </pre>
+ *
+ * @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();
+ }
+ }
+ }
+
+}
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;
*/
int getCacheSize();
- /**
- * @return The statistics provider for this trace
- * @since 2.0
- */
- ITmfStatistics getStatistics();
-
/**
* Return the map of state systems associated with this trace.
*
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;
// 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
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.
*
getIndexer().dispose();
}
- /* Clean up the statistics */
- if (fStatistics != null) {
- fStatistics.dispose();
- }
-
/* Clean up the state systems */
for (ITmfStateSystem ss : fStateSystems.values()) {
ss.dispose();
return fParser;
}
- /**
- * @since 2.0
- */
- @Override
- public ITmfStatistics getStatistics() {
- return fStatistics;
- }
-
/**
* @since 2.0
* @deprecated See {@link 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()) {
name="%project.new.category.name">
</category>
</extension>
+ <extension
+ point="org.eclipse.linuxtools.tmf.core.analysis">
+ <module
+ analysis_module="org.eclipse.linuxtools.tmf.ui.views.statistics.TmfStatisticsModule"
+ automatic="true"
+ id="org.eclipse.linuxtools.tmf.ui.views.statistics.analysis"
+ name="Tmf Statistics Analysis">
+ <tracetype
+ applies="true"
+ class="org.eclipse.linuxtools.tmf.core.trace.TmfTrace">
+ </tracetype>
+ </module>
+ </extension>
+
</plugin>
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;
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
* 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);
}
}
}
--- /dev/null
+/*******************************************************************************
+ * 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<ITmfStateSystem> getStateSystems() {
+ List<ITmfStateSystem> list = new LinkedList<>();
+ list.add(totalsModule.getStateSystem());
+ list.add(eventTypesModule.getStateSystem());
+ return list;
+ }
+}
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;
/* 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<Long> values = stats.histogramQuery(start, end, nb);
for (int i = 0; i < nb; i++) {