(no commit message)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / statistics / evProcessor / AbstractStatsEventHandler.java
1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Yann N. Dauphin (dhaemon@gmail.com) - Implementation for stats
11 *******************************************************************************/
12 package org.eclipse.linuxtools.lttng.ui.views.statistics.evProcessor;
13
14 import org.eclipse.linuxtools.lttng.event.LttngEvent;
15 import org.eclipse.linuxtools.lttng.state.StateStrings.Events;
16 import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode;
17 import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus;
18 import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
19 import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
20 import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
21 import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeRootFactory;
22 import org.eclipse.linuxtools.lttng.ui.views.statistics.model.StatisticsTreeNode;
23
24 abstract class AbstractStatsEventHandler implements ILttngEventProcessor {
25 private Events eventType;
26
27 public AbstractStatsEventHandler(Events eventType) {
28 super();
29 this.eventType = eventType;
30 }
31
32 /**
33 * @return root of of the tree for this experiment.
34 */
35 protected StatisticsTreeNode getStatisticsTree(LttngTraceState trcState) {
36 String experimentName = trcState.getContext().getExperimentName();
37 StatisticsTreeNode tree = StatisticsTreeRootFactory.getStatTreeRoot(experimentName);
38 return tree;
39 }
40
41 /**
42 * @return list of paths that should be updated for this event.
43 */
44 protected String[][] getRelevantPaths(LttngEvent event,
45 LttngTraceState traceState) {
46 String trace = traceState.getContext().getTraceId();
47
48 Long cpu = event.getCpuId();
49
50 LttngProcessState process = traceState.getRunning_process().get(
51 cpu);
52
53 String processName = getPocessName(process);
54
55 String mode = process.getState().getExec_mode().getInName();
56
57 String submode = process.getState().getExec_submode();
58
59 Long function = process.getCurrent_function();
60
61 // String type = event.getType().getTypeId();
62
63 String[][] paths = {
64 {trace},
65 {trace, "Modes", mode},
66 {trace, "Modes", mode, "Submodes", submode},
67 {trace, "Processes", processName},
68 {trace, "Processes", processName, "CPUs", cpu.toString()},
69 {trace, "Processes", processName, "CPUs", cpu.toString(), "Functions", function.toString()},
70 {trace, "Processes", processName, "CPUs", cpu.toString(), "Modes", mode},
71 {trace, "Processes", processName, "CPUs", cpu.toString(), "Modes", mode, "Submodes", submode},
72 {trace, "Processes", processName, "Modes", mode},
73 {trace, "Processes", processName, "Modes", mode, "Submodes", submode},
74 {trace, "CPUs", cpu.toString()},
75 {trace, "CPUs", cpu.toString(), "Modes", mode},
76 {trace, "CPUs", cpu.toString(), "Modes", mode, "Submodes", submode},
77 };
78 return paths;
79 }
80
81 /**
82 * @return list of event types paths that should be updated for this event.
83 */
84 protected String[][] getRelevantEventTypesPaths(LttngEvent event,
85 LttngTraceState traceState) {
86 String trace = traceState.getContext().getTraceId();
87
88 Long cpu = event.getCpuId();
89
90 LttngProcessState process = traceState.getRunning_process().get(
91 cpu);
92
93 String processName = getPocessName(process);
94
95 String mode = process.getState().getExec_mode().getInName();
96
97 String submode = process.getState().getExec_submode();
98
99 Long function = process.getCurrent_function();
100
101 String type = event.getType().getTypeId();
102
103 String[][] paths = {
104 {trace, "Event Types", type},
105 {trace, "Modes", mode, "Event Types", type},
106 {trace, "Modes", mode, "Submodes", submode, "Event Types", type},
107 {trace, "Processes", processName, "Event Types", type},
108 {trace, "Processes", processName, "CPUs", cpu.toString(), "Event Types", type},
109 {trace, "Processes", processName, "CPUs", cpu.toString(), "Functions", function.toString(), "Event Types", type},
110 {trace, "Processes", processName, "CPUs", cpu.toString(), "Modes", mode, "Event Types", type},
111 {trace, "Processes", processName, "CPUs", cpu.toString(), "Modes", mode, "Submodes", submode, "Event Types", type},
112 {trace, "Processes", processName, "Modes", mode, "Event Types", type},
113 {trace, "Processes", processName, "Modes", mode, "Submodes", submode, "Event Types", type},
114 {trace, "CPUs", cpu.toString(), "Event Types", type},
115 {trace, "CPUs", cpu.toString(), "Modes", mode, "Event Types", type},
116 {trace, "CPUs", cpu.toString(), "Modes", mode, "Submodes", submode, "Event Types", type},
117 };
118 return paths;
119 }
120
121 /**
122 * @return name of the process. Returns special string if the name is "".
123 */
124 private String getPocessName(LttngProcessState process) {
125 if (process.getName() == null) {
126 return "Unknown process";
127 }
128 if (process.getName() == "") {
129 return process.getPid().toString();
130 }
131 else {
132 return process.getName();
133 }
134 }
135
136 /**
137 * Increase the NbEvents counter of this node.
138 */
139 protected void increaseNbEvents(StatisticsTreeNode node) {
140 node.getValue().nbEvents++;
141 }
142
143 /**
144 * Increase the CPU Time according to the trace state.
145 */
146 protected void increaseCPUTime(StatisticsTreeNode node, LttngEvent event,
147 LttngTraceState traceState) {
148 Long cpu = event.getCpuId();
149
150 LttngProcessState process = traceState.getRunning_process().get(
151 cpu);
152
153 if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) &&
154 !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
155 node.getValue().cpuTime += event.getTimestamp().getValue()
156 - process.getState().getChange_LttTime();
157 }
158 }
159
160 /**
161 * Increase the Elapsed Time according to the trace state.
162 */
163 protected void increaseElapsedTime(StatisticsTreeNode node, LttngEvent event,
164 LttngTraceState traceState) {
165 Long cpu = event.getCpuId();
166
167 LttngProcessState process = traceState.getRunning_process().get(
168 cpu);
169
170 if (!process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
171 node.getValue().elapsedTime += event.getTimestamp().getValue()
172 - process.getState().getEntry_LttTime();
173 }
174 }
175
176 /**
177 * Increase the Cumulative CPU Time according to the trace state.
178 */
179 protected void increaseCumulativeCPUTime(StatisticsTreeNode node, LttngEvent event,
180 LttngTraceState traceState) {
181 Long cpu = event.getCpuId();
182
183 LttngProcessState process = traceState.getRunning_process().get(
184 cpu);
185
186 if (!process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
187 long cumulativeCpuTime = process.getState().getCum_cpu_time();
188 long delta = event.getTimestamp().getValue() - process.getState().getEntry_LttTime();
189 process.getState().setCum_cpu_time(cumulativeCpuTime + delta);
190 node.getValue().cumulativeCpuTime += process.getState().getCum_cpu_time();
191 }
192 else if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) &&
193 !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
194 long cumulativeCpuTime = process.getState().getCum_cpu_time();
195 long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime();
196 process.getState().setCum_cpu_time(cumulativeCpuTime + delta);
197 node.getValue().cumulativeCpuTime += process.getState().getCum_cpu_time();
198 }
199 }
200
201 /**
202 * Increase the State-bound Cumulative CPU Time according to the trace state.
203 */
204 protected void increaseStateCumulativeCPUTime(LttngEvent event,
205 LttngTraceState traceState) {
206 Long cpu = event.getCpuId();
207
208 LttngProcessState process = traceState.getRunning_process().get(cpu);
209
210 if (process.getState().getProc_status().equals(ProcessStatus.LTTV_STATE_RUN) &&
211 !process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
212 long cumulativeCpuTime = process.getState().getCum_cpu_time();
213 long delta = event.getTimestamp().getValue() - process.getState().getChange_LttTime();
214 process.getState().setCum_cpu_time(cumulativeCpuTime + delta);
215 }
216 }
217
218 // @Override
219 public Events getEventHandleType() {
220 return eventType;
221 }
222
223 protected void stepCount(LttngEvent event, LttngTraceState traceState) {
224 StatisticsTreeNode root = getStatisticsTree(traceState);
225
226 String[][] paths = getRelevantPaths(event, traceState);
227
228 for (String[] path : paths) {
229 StatisticsTreeNode node = root.getOrCreateChildFromPath(path);
230
231 increaseNbEvents(node);
232 }
233
234 String[][] eventTypesPaths = getRelevantEventTypesPaths(event, traceState);
235
236 for (String[] path : eventTypesPaths) {
237 StatisticsTreeNode node = root.getOrCreateChildFromPath(path);
238
239 increaseNbEvents(node);
240 }
241 }
242
243 }
This page took 0.036539 seconds and 6 git commands to generate.