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 org
.eclipse
.jdt
.annotation
.NonNull
;
16 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.AttributeNotFoundException
;
17 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.StateValueTypeException
;
18 import org
.eclipse
.linuxtools
.statesystem
.core
.exceptions
.TimeRangeException
;
19 import org
.eclipse
.linuxtools
.statesystem
.core
.statevalue
.TmfStateValue
;
20 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfEvent
;
21 import org
.eclipse
.tracecompass
.tmf
.core
.event
.ITmfLostEvent
;
22 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.ITmfStateProvider
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.statesystem
.TmfStateSystemAnalysisModule
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.ITmfTimestamp
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
30 * The analysis module building the "event types" statistics state system.
32 * It is not in the extension point (and as such, not registered in the
33 * TmfAnalysisManager), as it is being handled by the TmfStatisticsModule.
35 * @author Alexandre Montplaisir
38 public class TmfStatisticsEventTypesModule
extends TmfStateSystemAnalysisModule
{
41 * The ID of this analysis module (which is also the ID of the state system)
44 public static final String ID
= "org.eclipse.linuxtools.tmf.statistics.types"; //$NON-NLS-1$
46 private static final String NAME
= "TMF Statistics, events per type"; //$NON-NLS-1$
51 public TmfStatisticsEventTypesModule() {
58 protected ITmfStateProvider
createStateProvider() {
59 return new StatsProviderEventTypes(getTrace());
63 protected String
getSsFileName() {
64 return "statistics-types.ht"; //$NON-NLS-1$
69 * The state provider for traces statistics that use TmfStateStatistics. It
70 * should work with any trace type for which we can use the state system.
72 * It will store number of events seen, per event types. The resulting attribute
73 * tree will look like this:
84 * And each (event name)'s value will be an integer, representing how many times
85 * this particular event type has been seen in the trace so far.
87 * @author Alexandre Montplaisir
90 class StatsProviderEventTypes
extends AbstractTmfStateProvider
{
93 * Version number of this input handler. Please bump this if you modify the
94 * contents of the generated state history in some way.
96 private static final int VERSION
= 2;
102 * The trace for which we build this state system
104 public StatsProviderEventTypes(ITmfTrace trace
) {
105 super(trace
, ITmfEvent
.class ,"TMF Statistics, events per type"); //$NON-NLS-1$
109 public int getVersion() {
114 public StatsProviderEventTypes
getNewInstance() {
115 return new StatsProviderEventTypes(this.getTrace());
119 protected void eventHandle(ITmfEvent event
) {
122 /* Since this can be used for any trace types, normalize all the
123 * timestamp values to nanoseconds. */
124 final long ts
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
126 final String eventName
= event
.getType().getName();
129 /* Special handling for lost events */
130 if (event
instanceof ITmfLostEvent
) {
131 ITmfLostEvent le
= (ITmfLostEvent
) event
;
132 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
134 int curVal
= ss
.queryOngoingState(quark
).unboxInt();
139 TmfStateValue value
= TmfStateValue
.newValueInt((int) (curVal
+ le
.getNbLostEvents()));
140 ss
.modifyAttribute(ts
, value
, quark
);
144 /* Number of events of each type, globally */
145 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
146 ss
.incrementAttribute(ts
, quark
);
148 // /* Number of events per CPU */
149 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
150 // ss.incrementAttribute(ts, quark);
152 // /* Number of events per process */
153 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
154 // ss.incrementAttribute(ts, quark);
156 } catch (StateValueTypeException
| TimeRangeException
| AttributeNotFoundException e
) {