1 /*******************************************************************************
2 * Copyright (c) 2009 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 * Yann N. Dauphin (dhaemon@gmail.com) - Implementation for stats
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.statistics
.evProcessor
;
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
;
24 abstract class AbstractStatsEventHandler
implements ILttngEventProcessor
{
25 private Events eventType
;
27 public AbstractStatsEventHandler(Events eventType
) {
29 this.eventType
= eventType
;
33 * @return root of of the tree for this experiment.
35 protected StatisticsTreeNode
getStatisticsTree(LttngTraceState trcState
) {
36 String experimentName
= trcState
.getContext().getExperimentName();
37 StatisticsTreeNode tree
= StatisticsTreeRootFactory
.getStatTreeRoot(experimentName
);
42 * @return list of paths that should be updated for this event.
44 protected String
[][] getRelevantPaths(LttngEvent event
,
45 LttngTraceState traceState
) {
46 String trace
= traceState
.getContext().getTraceId();
48 Long cpu
= event
.getCpuId();
50 LttngProcessState process
= traceState
.getRunning_process().get(
53 String processName
= getPocessName(process
);
55 String mode
= process
.getState().getExec_mode().getInName();
57 String submode
= process
.getState().getExec_submode();
59 Long function
= process
.getCurrent_function();
61 // String type = event.getType().getTypeId();
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
},
82 * @return list of event types paths that should be updated for this event.
84 protected String
[][] getRelevantEventTypesPaths(LttngEvent event
,
85 LttngTraceState traceState
) {
86 String trace
= traceState
.getContext().getTraceId();
88 Long cpu
= event
.getCpuId();
90 LttngProcessState process
= traceState
.getRunning_process().get(
93 String processName
= getPocessName(process
);
95 String mode
= process
.getState().getExec_mode().getInName();
97 String submode
= process
.getState().getExec_submode();
99 Long function
= process
.getCurrent_function();
101 String type
= event
.getType().getTypeId();
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
},
122 * @return name of the process. Returns special string if the name is "".
124 private String
getPocessName(LttngProcessState process
) {
125 if (process
.getName() == null) {
126 return "Unknown process";
128 if (process
.getName() == "") {
129 return process
.getPid().toString();
132 return process
.getName();
137 * Increase the NbEvents counter of this node.
139 protected void increaseNbEvents(StatisticsTreeNode node
) {
140 node
.getValue().nbEvents
++;
144 * Increase the CPU Time according to the trace state.
146 protected void increaseCPUTime(StatisticsTreeNode node
, LttngEvent event
,
147 LttngTraceState traceState
) {
148 Long cpu
= event
.getCpuId();
150 LttngProcessState process
= traceState
.getRunning_process().get(
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();
161 * Increase the Elapsed Time according to the trace state.
163 protected void increaseElapsedTime(StatisticsTreeNode node
, LttngEvent event
,
164 LttngTraceState traceState
) {
165 Long cpu
= event
.getCpuId();
167 LttngProcessState process
= traceState
.getRunning_process().get(
170 if (!process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
171 node
.getValue().elapsedTime
+= event
.getTimestamp().getValue()
172 - process
.getState().getEntry_LttTime();
177 * Increase the Cumulative CPU Time according to the trace state.
179 protected void increaseCumulativeCPUTime(StatisticsTreeNode node
, LttngEvent event
,
180 LttngTraceState traceState
) {
181 Long cpu
= event
.getCpuId();
183 LttngProcessState process
= traceState
.getRunning_process().get(
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();
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();
202 * Increase the State-bound Cumulative CPU Time according to the trace state.
204 protected void increaseStateCumulativeCPUTime(LttngEvent event
,
205 LttngTraceState traceState
) {
206 Long cpu
= event
.getCpuId();
208 LttngProcessState process
= traceState
.getRunning_process().get(cpu
);
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
);
219 public Events
getEventHandleType() {
223 protected void stepCount(LttngEvent event
, LttngTraceState traceState
) {
224 StatisticsTreeNode root
= getStatisticsTree(traceState
);
226 String
[][] paths
= getRelevantPaths(event
, traceState
);
228 for (String
[] path
: paths
) {
229 StatisticsTreeNode node
= root
.getOrCreateChildFromPath(path
);
231 increaseNbEvents(node
);
234 String
[][] eventTypesPaths
= getRelevantEventTypesPaths(event
, traceState
);
236 for (String
[] path
: eventTypesPaths
) {
237 StatisticsTreeNode node
= root
.getOrCreateChildFromPath(path
);
239 increaseNbEvents(node
);