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
.IEventProcessing
;
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
.StatisticsTreeFactory
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.views
.statistics
.model
.StatisticsTreeNode
;
24 abstract class AbstractStatsEventHandler
implements IEventProcessing
{
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(LttngEvent trcEvent
) {
36 StatisticsTreeNode tree
= StatisticsTreeFactory
.getStatisticsTree("Experiment");
41 * @return list of paths that should be updated for this event.
43 protected String
[][] getRelevantPaths(LttngEvent event
,
44 LttngTraceState traceState
) {
45 String trace
= traceState
.getInputDataRef().getTraceId();
47 Long cpu
= event
.getCpuId();
49 LttngProcessState process
= traceState
.getRunning_process().get(
52 String processName
= getPocessName(process
);
54 String mode
= process
.getState().getExec_mode().getInName();
56 String submode
= process
.getState().getExec_submode();
58 Long function
= process
.getCurrent_function();
60 // String type = event.getType().getTypeId();
64 {trace
, "Modes", mode
},
65 {trace
, "Modes", mode
, "Submodes", submode
},
66 {trace
, "Processes", processName
},
67 {trace
, "Processes", processName
, "CPUs", cpu
.toString()},
68 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Functions", function
.toString()},
69 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Modes", mode
},
70 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Modes", mode
, "Submodes", submode
},
71 {trace
, "Processes", processName
, "Modes", mode
},
72 {trace
, "Processes", processName
, "Modes", mode
, "Submodes", submode
},
73 {trace
, "CPUs", cpu
.toString()},
74 {trace
, "CPUs", cpu
.toString(), "Modes", mode
},
75 {trace
, "CPUs", cpu
.toString(), "Modes", mode
, "Submodes", submode
},
81 * @return list of event types paths that should be updated for this event.
83 protected String
[][] getRelevantEventTypesPaths(LttngEvent event
,
84 LttngTraceState traceState
) {
85 String trace
= traceState
.getInputDataRef().getTraceId();
87 Long cpu
= event
.getCpuId();
89 LttngProcessState process
= traceState
.getRunning_process().get(
92 String processName
= getPocessName(process
);
94 String mode
= process
.getState().getExec_mode().getInName();
96 String submode
= process
.getState().getExec_submode();
98 Long function
= process
.getCurrent_function();
100 String type
= event
.getType().getTypeId();
103 {trace
, "Event Types", type
},
104 {trace
, "Modes", mode
, "Event Types", type
},
105 {trace
, "Modes", mode
, "Submodes", submode
, "Event Types", type
},
106 {trace
, "Processes", processName
, "Event Types", type
},
107 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Event Types", type
},
108 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Functions", function
.toString(), "Event Types", type
},
109 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Modes", mode
, "Event Types", type
},
110 {trace
, "Processes", processName
, "CPUs", cpu
.toString(), "Modes", mode
, "Submodes", submode
, "Event Types", type
},
111 {trace
, "Processes", processName
, "Modes", mode
, "Event Types", type
},
112 {trace
, "Processes", processName
, "Modes", mode
, "Submodes", submode
, "Event Types", type
},
113 {trace
, "CPUs", cpu
.toString(), "Event Types", type
},
114 {trace
, "CPUs", cpu
.toString(), "Modes", mode
, "Event Types", type
},
115 {trace
, "CPUs", cpu
.toString(), "Modes", mode
, "Submodes", submode
, "Event Types", type
},
121 * @return name of the process. Returns special string if the name is "".
123 private String
getPocessName(LttngProcessState process
) {
124 if (process
.getName() == null) {
125 return "Unknown process";
127 if (process
.getName() == "") {
128 return process
.getPid().toString();
131 return process
.getName();
136 * Increase the NbEvents counter of this node.
138 protected void increaseNbEvents(StatisticsTreeNode node
) {
139 node
.getValue().nbEvents
++;
143 * Increase the CPU Time according to the trace state.
145 protected void increaseCPUTime(StatisticsTreeNode node
, LttngEvent event
,
146 LttngTraceState traceState
) {
147 Long cpu
= event
.getCpuId();
149 LttngProcessState process
= traceState
.getRunning_process().get(
152 if (process
.getState().getProc_status().equals(ProcessStatus
.LTTV_STATE_RUN
) &&
153 !process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
154 node
.getValue().cpuTime
+= event
.getTimestamp().getValue()
155 - process
.getState().getChange_LttTime();
160 * Increase the Elapsed Time according to the trace state.
162 protected void increaseElapsedTime(StatisticsTreeNode node
, LttngEvent event
,
163 LttngTraceState traceState
) {
164 Long cpu
= event
.getCpuId();
166 LttngProcessState process
= traceState
.getRunning_process().get(
169 if (!process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
170 node
.getValue().elapsedTime
+= event
.getTimestamp().getValue()
171 - process
.getState().getEntry_LttTime();
176 * Increase the Cumulative CPU Time according to the trace state.
178 protected void increaseCumulativeCPUTime(StatisticsTreeNode node
, LttngEvent event
,
179 LttngTraceState traceState
) {
180 Long cpu
= event
.getCpuId();
182 LttngProcessState process
= traceState
.getRunning_process().get(
185 if (!process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
186 long cumulativeCpuTime
= process
.getState().getCum_cpu_time();
187 long delta
= event
.getTimestamp().getValue() - process
.getState().getEntry_LttTime();
188 process
.getState().setCum_cpu_time(cumulativeCpuTime
+ delta
);
189 node
.getValue().cumulativeCpuTime
+= process
.getState().getCum_cpu_time();
191 else if (process
.getState().getProc_status().equals(ProcessStatus
.LTTV_STATE_RUN
) &&
192 !process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
193 long cumulativeCpuTime
= process
.getState().getCum_cpu_time();
194 long delta
= event
.getTimestamp().getValue() - process
.getState().getChange_LttTime();
195 process
.getState().setCum_cpu_time(cumulativeCpuTime
+ delta
);
196 node
.getValue().cumulativeCpuTime
+= process
.getState().getCum_cpu_time();
201 * Increase the State-bound Cumulative CPU Time according to the trace state.
203 protected void increaseStateCumulativeCPUTime(LttngEvent event
,
204 LttngTraceState traceState
) {
205 Long cpu
= event
.getCpuId();
207 LttngProcessState process
= traceState
.getRunning_process().get(cpu
);
209 if (process
.getState().getProc_status().equals(ProcessStatus
.LTTV_STATE_RUN
) &&
210 !process
.getState().getExec_mode().equals(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
)) {
211 long cumulativeCpuTime
= process
.getState().getCum_cpu_time();
212 long delta
= event
.getTimestamp().getValue() - process
.getState().getChange_LttTime();
213 process
.getState().setCum_cpu_time(cumulativeCpuTime
+ delta
);
218 public Events
getEventHandleType() {