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; | |
17 | import org.eclipse.linuxtools.tmf.core.exceptions.AttributeNotFoundException; | |
18 | import org.eclipse.linuxtools.tmf.core.exceptions.StateValueTypeException; | |
19 | import org.eclipse.linuxtools.tmf.core.exceptions.TimeRangeException; | |
20 | import org.eclipse.linuxtools.tmf.core.statesystem.AbstractStateChangeInput; | |
1c0de632 | 21 | import org.eclipse.linuxtools.tmf.core.statistics.TmfStateStatistics.Attributes; |
3bd46eef | 22 | import org.eclipse.linuxtools.tmf.core.timestamp.ITmfTimestamp; |
200789b3 AM |
23 | import org.eclipse.linuxtools.tmf.core.trace.ITmfTrace; |
24 | ||
25 | /** | |
1c0de632 AM |
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. | |
200789b3 AM |
28 | * |
29 | * The resulting attribute tree will look like this: | |
e8251298 PT |
30 | *<pre> |
31 | * (root) | |
df310609 | 32 | * |-- total |
200789b3 | 33 | * \-- event_types |
e8251298 PT |
34 | * |-- (event name 1) |
35 | * |-- (event name 2) | |
36 | * |-- (event name 3) | |
200789b3 | 37 | * ... |
e8251298 PT |
38 | *</pre> |
39 | * And each (event name)'s value will be an integer, representing how many times | |
200789b3 AM |
40 | * this particular event type has been seen in the trace so far. |
41 | * | |
42 | * @author Alexandre Montplaisir | |
43 | * @version 1.0 | |
44 | */ | |
45 | class StatsStateProvider extends AbstractStateChangeInput { | |
46 | ||
a96cc6be AM |
47 | /** |
48 | * Version number of this input handler. Please bump this if you modify the | |
49 | * contents of the generated state history in some way. | |
50 | */ | |
51 | private static final int VERSION = 0; | |
52 | ||
200789b3 AM |
53 | /** |
54 | * Constructor | |
e8251298 | 55 | * |
200789b3 AM |
56 | * @param trace |
57 | * The trace for which we build this state system | |
58 | */ | |
59 | public StatsStateProvider(ITmfTrace trace) { | |
60 | super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$ | |
61 | } | |
62 | ||
a96cc6be AM |
63 | @Override |
64 | public int getVersion() { | |
65 | return VERSION; | |
66 | } | |
67 | ||
e96ab5c4 AM |
68 | @Override |
69 | public StatsStateProvider getNewInstance() { | |
70 | return new StatsStateProvider(this.getTrace()); | |
71 | } | |
72 | ||
200789b3 AM |
73 | @Override |
74 | protected void eventHandle(ITmfEvent event) { | |
75 | int quark; | |
76 | ||
c5a0ac41 AM |
77 | /* Since this can be used for any trace types, normalize all the |
78 | * timestamp values to nanoseconds. */ | |
faa38350 | 79 | final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
c5a0ac41 | 80 | |
200789b3 AM |
81 | final String eventName = event.getType().getName(); |
82 | ||
83 | try { | |
84 | ||
df310609 AM |
85 | /* Total number of events */ |
86 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL); | |
87 | ss.incrementAttribute(ts, quark); | |
88 | ||
200789b3 | 89 | /* Number of events of each type, globally */ |
6383e95d | 90 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES, eventName); |
200789b3 AM |
91 | ss.incrementAttribute(ts, quark); |
92 | ||
93 | // /* Number of events per CPU */ | |
94 | // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
95 | // ss.incrementAttribute(ts, quark); | |
96 | // | |
97 | // /* Number of events per process */ | |
98 | // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
99 | // ss.incrementAttribute(ts, quark); | |
100 | ||
101 | } catch (StateValueTypeException e) { | |
102 | e.printStackTrace(); | |
103 | } catch (TimeRangeException e) { | |
104 | e.printStackTrace(); | |
105 | } catch (AttributeNotFoundException e) { | |
106 | e.printStackTrace(); | |
107 | } | |
108 | } | |
109 | } |