Commit | Line | Data |
---|---|---|
200789b3 | 1 | /******************************************************************************* |
61759503 | 2 | * Copyright (c) 2012, 2013 Ericsson |
200789b3 AM |
3 | * |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
e8251298 | 11 | * Patrick Tasse - Fix javadoc |
200789b3 AM |
12 | ******************************************************************************/ |
13 | ||
14 | package org.eclipse.linuxtools.tmf.core.statistics; | |
15 | ||
16 | import org.eclipse.linuxtools.tmf.core.event.ITmfEvent; | |
6debe8aa | 17 | import org.eclipse.linuxtools.tmf.core.event.ITmfLostEvent; |
200789b3 AM |
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; | |
0fe46f2a | 21 | import org.eclipse.linuxtools.tmf.core.statesystem.AbstractTmfStateProvider; |
6debe8aa | 22 | import org.eclipse.linuxtools.tmf.core.statevalue.TmfStateValue; |
1c0de632 | 23 | import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; |
3bd46eef | 24 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
200789b3 AM |
25 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
26 | ||
27 | /** | |
1c0de632 AM |
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. | |
200789b3 AM |
30 | * |
31 | * The resulting attribute tree will look like this: | |
e8251298 PT |
32 | *<pre> |
33 | * (root) | |
df310609 | 34 | * |-- total |
200789b3 | 35 | * \-- event_types |
e8251298 PT |
36 | * |-- (event name 1) |
37 | * |-- (event name 2) | |
38 | * |-- (event name 3) | |
200789b3 | 39 | * ... |
e8251298 PT |
40 | *</pre> |
41 | * And each (event name)'s value will be an integer, representing how many times | |
200789b3 AM |
42 | * this particular event type has been seen in the trace so far. |
43 | * | |
44 | * @author Alexandre Montplaisir | |
45 | * @version 1.0 | |
46 | */ | |
0fe46f2a | 47 | class StatsStateProvider extends AbstractTmfStateProvider { |
200789b3 | 48 | |
a96cc6be AM |
49 | /** |
50 | * Version number of this input handler. Please bump this if you modify the | |
51 | * contents of the generated state history in some way. | |
52 | */ | |
6debe8aa | 53 | private static final int VERSION = 1; |
a96cc6be | 54 | |
200789b3 AM |
55 | /** |
56 | * Constructor | |
e8251298 | 57 | * |
200789b3 AM |
58 | * @param trace |
59 | * The trace for which we build this state system | |
60 | */ | |
61 | public StatsStateProvider(ITmfTrace trace) { | |
62 | super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$ | |
63 | } | |
64 | ||
a96cc6be AM |
65 | @Override |
66 | public int getVersion() { | |
67 | return VERSION; | |
68 | } | |
69 | ||
e96ab5c4 AM |
70 | @Override |
71 | public StatsStateProvider getNewInstance() { | |
72 | return new StatsStateProvider(this.getTrace()); | |
73 | } | |
74 | ||
200789b3 AM |
75 | @Override |
76 | protected void eventHandle(ITmfEvent event) { | |
77 | int quark; | |
78 | ||
c5a0ac41 AM |
79 | /* Since this can be used for any trace types, normalize all the |
80 | * timestamp values to nanoseconds. */ | |
faa38350 | 81 | final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
c5a0ac41 | 82 | |
200789b3 AM |
83 | final String eventName = event.getType().getName(); |
84 | ||
85 | try { | |
6debe8aa AM |
86 | /* Special handling for lost events */ |
87 | if (event instanceof ITmfLostEvent) { | |
88 | ITmfLostEvent le = (ITmfLostEvent) event; | |
e8f9ac01 | 89 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); |
6debe8aa AM |
90 | |
91 | int curVal = ss.queryOngoingState(quark).unboxInt(); | |
92 | if (curVal == -1) { curVal = 0; } | |
93 | ||
94 | TmfStateValue value = TmfStateValue.newValueInt((int) (curVal + le.getNbLostEvents())); | |
95 | ss.modifyAttribute(ts, value, quark); | |
96 | return; | |
97 | } | |
200789b3 | 98 | |
df310609 AM |
99 | /* Total number of events */ |
100 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL); | |
101 | ss.incrementAttribute(ts, quark); | |
102 | ||
200789b3 | 103 | /* Number of events of each type, globally */ |
6383e95d | 104 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); |
200789b3 AM |
105 | ss.incrementAttribute(ts, quark); |
106 | ||
107 | // /* Number of events per CPU */ | |
108 | // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
109 | // ss.incrementAttribute(ts, quark); | |
110 | // | |
111 | // /* Number of events per process */ | |
112 | // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
113 | // ss.incrementAttribute(ts, quark); | |
114 | ||
115 | } catch (StateValueTypeException e) { | |
116 | e.printStackTrace(); | |
117 | } catch (TimeRangeException e) { | |
118 | e.printStackTrace(); | |
119 | } catch (AttributeNotFoundException e) { | |
120 | e.printStackTrace(); | |
121 | } | |
122 | } | |
123 | } |