Commit | Line | Data |
---|---|---|
200789b3 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2012 Ericsson | |
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 | |
11 | ******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.core.statistics; | |
14 | ||
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; | |
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: | |
30 | * | |
31 | * <root> | |
df310609 | 32 | * |-- total |
200789b3 AM |
33 | * \-- event_types |
34 | * |-- <event name 1> | |
35 | * |-- <event name 2> | |
36 | * |-- <event name 3> | |
37 | * ... | |
38 | * | |
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. | |
41 | * | |
42 | * @author Alexandre Montplaisir | |
43 | * @version 1.0 | |
44 | */ | |
45 | class StatsStateProvider extends AbstractStateChangeInput { | |
46 | ||
47 | /* Commonly-used attributes */ | |
48 | private int typeAttribute = -1; | |
49 | ||
50 | /** | |
51 | * Constructor | |
52 | * | |
53 | * @param trace | |
54 | * The trace for which we build this state system | |
55 | */ | |
56 | public StatsStateProvider(ITmfTrace trace) { | |
57 | super(trace, ITmfEvent.class ,"TMF Statistics"); //$NON-NLS-1$ | |
58 | } | |
59 | ||
60 | @Override | |
61 | public void assignTargetStateSystem(ITmfStateSystemBuilder ssb) { | |
62 | super.assignTargetStateSystem(ssb); | |
63 | ||
64 | /* Setup common locations */ | |
65 | typeAttribute = ss.getQuarkAbsoluteAndAdd(Attributes.EVENT_TYPES); | |
66 | } | |
67 | ||
68 | @Override | |
69 | protected void eventHandle(ITmfEvent event) { | |
70 | int quark; | |
71 | ||
c5a0ac41 AM |
72 | /* Since this can be used for any trace types, normalize all the |
73 | * timestamp values to nanoseconds. */ | |
faa38350 | 74 | final long ts = event.getTimestamp().normalize(0, ITmfTimestamp.NANOSECOND_SCALE).getValue(); |
c5a0ac41 | 75 | |
200789b3 AM |
76 | final String eventName = event.getType().getName(); |
77 | ||
78 | try { | |
79 | ||
df310609 AM |
80 | /* Total number of events */ |
81 | quark = ss.getQuarkAbsoluteAndAdd(Attributes.TOTAL); | |
82 | ss.incrementAttribute(ts, quark); | |
83 | ||
200789b3 AM |
84 | /* Number of events of each type, globally */ |
85 | quark = ss.getQuarkRelativeAndAdd(typeAttribute, eventName); | |
86 | ss.incrementAttribute(ts, quark); | |
87 | ||
88 | // /* Number of events per CPU */ | |
89 | // quark = ss.getQuarkRelativeAndAdd(currentCPUNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
90 | // ss.incrementAttribute(ts, quark); | |
91 | // | |
92 | // /* Number of events per process */ | |
93 | // quark = ss.getQuarkRelativeAndAdd(currentThreadNode, Attributes.STATISTICS, Attributes.EVENT_TYPES, eventName); | |
94 | // ss.incrementAttribute(ts, quark); | |
95 | ||
96 | } catch (StateValueTypeException e) { | |
97 | e.printStackTrace(); | |
98 | } catch (TimeRangeException e) { | |
99 | e.printStackTrace(); | |
100 | } catch (AttributeNotFoundException e) { | |
101 | e.printStackTrace(); | |
102 | } | |
103 | } | |
104 | } |