1 /*******************************************************************************
2 * Copyright (c) 2012 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 org
.eclipse
.linuxtools
.tmf
.core
.event
.ITmfEvent
;
16 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.AttributeNotFoundException
;
17 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.StateValueTypeException
;
18 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TimeRangeException
;
19 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.AbstractStateChangeInput
;
20 import org
.eclipse
.linuxtools
.tmf
.core
.statesystem
.ITmfStateSystemBuilder
;
21 import org
.eclipse
.linuxtools
.tmf
.core
.statistics
.TmfStateStatistics
.Attributes
;
22 import org
.eclipse
.linuxtools
.tmf
.core
.timestamp
.ITmfTimestamp
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
26 * The state provider for traces statistics that use TmfStateStatistics. It
27 * should work with any trace type for which we can use the state system.
29 * The resulting attribute tree will look like this:
39 * And each <event name>'s value will be an integer, representing how many times
40 * this particular event type has been seen in the trace so far.
42 * @author Alexandre Montplaisir
45 class StatsStateProvider
extends AbstractStateChangeInput
{
48 * Version number of this input handler. Please bump this if you modify the
49 * contents of the generated state history in some way.
51 private static final int VERSION
= 0;
53 /* Commonly-used attributes */
54 private int typeAttribute
= -1;
60 * The trace for which we build this state system
62 public StatsStateProvider(ITmfTrace trace
) {
63 super(trace
, ITmfEvent
.class ,"TMF Statistics"); //$NON-NLS-1$
67 public int getVersion() {
72 public void assignTargetStateSystem(ITmfStateSystemBuilder ssb
) {
73 super.assignTargetStateSystem(ssb
);
75 /* Setup common locations */
76 typeAttribute
= ss
.getQuarkAbsoluteAndAdd(Attributes
.EVENT_TYPES
);
80 protected void eventHandle(ITmfEvent event
) {
83 /* Since this can be used for any trace types, normalize all the
84 * timestamp values to nanoseconds. */
85 final long ts
= event
.getTimestamp().normalize(0, ITmfTimestamp
.NANOSECOND_SCALE
).getValue();
87 final String eventName
= event
.getType().getName();
91 /* Total number of events */
92 quark
= ss
.getQuarkAbsoluteAndAdd(Attributes
.TOTAL
);
93 ss
.incrementAttribute(ts
, quark
);
95 /* Number of events of each type, globally */
96 quark
= ss
.getQuarkRelativeAndAdd(typeAttribute
, eventName
);
97 ss
.incrementAttribute(ts
, quark
);
99 // /* Number of events per CPU */
100 // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
101 // ss.incrementAttribute(ts, quark);
103 // /* Number of events per process */
104 // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName);
105 // ss.incrementAttribute(ts, quark);
107 } catch (StateValueTypeException e
) {
109 } catch (TimeRangeException e
) {
111 } catch (AttributeNotFoundException e
) {