1 /*******************************************************************************
2 * Copyright (c) 2012, 2013 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 * Patrick Tasse - Fix javadoc
12 ******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.core
.statistics
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfLostEvent
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractTmfStateProvider
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.statevalue
.TmfStateValue
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
28 * The state provider for traces statistics that use TmfStateStatistics. It
29 * should work with any trace type for which we can use the state system.
31 * The resulting attribute tree will look like this:
41 * And each (event name)'s value will be an integer, representing how many times
42 * this particular event type has been seen in the trace so far.
44 * @author Alexandre Montplaisir
47 class StatsStateProvider
extends AbstractTmfStateProvider
{
50 * Version number of this input handler. Please bump this if you modify the
51 * contents of the generated state history in some way.
53 private static final int VERSION
= 1;
59 * The trace for which we build this state system
61 public StatsStateProvider(ITmfTrace trace
) {
62 super(trace
, ITmfEvent
.class ,"TMF Statistics"); //$NON-NLS-1$
66 public int getVersion() {
71 public StatsStateProvider
getNewInstance() {
72 return new StatsStateProvider(this.getTrace());
76 protected void eventHandle(ITmfEvent event
) {
79 /* Since this can be used for any trace types, normalize all the
80 * timestamp values to nanoseconds. */
81 final long ts
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
83 final String eventName
= event
.getType().getName();
86 /* Special handling for lost events */
87 if (event
instanceof ITmfLostEvent
) {
88 ITmfLostEvent le
= (ITmfLostEvent
) event
;
89 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
91 int curVal
= ss
.queryOngoingState(quark
).unboxInt();
92 if (curVal
== -1) { curVal
= 0; }
94 TmfStateValue value
= TmfStateValue
.newValueInt((int) (curVal
+ le
.getNbLostEvents()));
95 ss
.modifyAttribute(ts
, value
, quark
);
99 /* Total number of events */
100 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
101 ss
.incrementAttribute(ts
, quark
);
103 /* Number of events of each type, globally */
104 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
, eventName
);
105 ss
.incrementAttribute(ts
, quark
);
107 // /* Number of events per CPU */
108 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
109 // ss.incrementAttribute(ts, quark);
111 // /* Number of events per process */
112 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
113 // ss.incrementAttribute(ts, quark);
115 } catch (StateValueTypeException e
) {
117 } catch (TimeRangeException e
) {
119 } catch (AttributeNotFoundException e
) {