temporary re-factoring project
[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.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;
23
24 abstract class AbstractStatsEventHandler implements IEventProcessing {
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(LttngEvent trcEvent) {
36 StatisticsTreeNode tree = StatisticsTreeFactory.getStatisticsTree("Experiment");
37 return tree;
38 }
39
40 /**
41 * @return list of paths that should be updated for this event.
42 */
43 protected String[][] getRelevantPaths(LttngEvent event,
44 LttngTraceState traceState) {
45 String trace = traceState.getInputDataRef().getTraceId();
46
47 Long cpu = event.getCpuId();
48
49 LttngProcessState process = traceState.getRunning_process().get(
50 cpu);
51
52 String processName = getPocessName(process);
53
54 String mode = process.getState().getExec_mode().getInName();
55
56 String submode = process.getState().getExec_submode();
57
58 Long function = process.getCurrent_function();
59
60 // String type = event.getType().getTypeId();
61
62 String[][] paths = {
63 {trace},
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},
76 };
77 return paths;
78 }
79
80 /**
81 * @return list of event types paths that should be updated for this event.
82 */
83 protected String[][] getRelevantEventTypesPaths(LttngEvent event,
84 LttngTraceState traceState) {
85 String trace = traceState.getInputDataRef().getTraceId();
86
87 Long cpu = event.getCpuId();
88
89 LttngProcessState process = traceState.getRunning_process().get(
90 cpu);
91
92 String processName = getPocessName(process);
93
94 String mode = process.getState().getExec_mode().getInName();
95
96 String submode = process.getState().getExec_submode();
97
98 Long function = process.getCurrent_function();
99
100 String type = event.getType().getTypeId();
101
102 String[][] paths = {
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},
116 };
117 return paths;
118 }
119
120 /**
121 * @return name of the process. Returns special string if the name is "".
122 */
123 private String getPocessName(LttngProcessState process) {
124 if (process.getName() == null) {
125 return "Unknown process";
126 }
127 if (process.getName() == "") {
128 return process.getPid().toString();
129 }
130 else {
131 return process.getName();
132 }
133 }
134
135 /**
136 * Increase the NbEvents counter of this node.
137 */
138 protected void increaseNbEvents(StatisticsTreeNode node) {
139 node.getValue().nbEvents++;
140 }
141
142 /**
143 * Increase the CPU Time according to the trace state.
144 */
145 protected void increaseCPUTime(StatisticsTreeNode node, LttngEvent event,
146 LttngTraceState traceState) {
147 Long cpu = event.getCpuId();
148
149 LttngProcessState process = traceState.getRunning_process().get(
150 cpu);
151
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();
156 }
157 }
158
159 /**
160 * Increase the Elapsed Time according to the trace state.
161 */
162 protected void increaseElapsedTime(StatisticsTreeNode node, LttngEvent event,
163 LttngTraceState traceState) {
164 Long cpu = event.getCpuId();
165
166 LttngProcessState process = traceState.getRunning_process().get(
167 cpu);
168
169 if (!process.getState().getExec_mode().equals(ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
170 node.getValue().elapsedTime += event.getTimestamp().getValue()
171 - process.getState().getEntry_LttTime();
172 }
173 }
174
175 /**
176 * Increase the Cumulative CPU Time according to the trace state.
177 */
178 protected void increaseCumulativeCPUTime(StatisticsTreeNode node, LttngEvent event,
179 LttngTraceState traceState) {
180 Long cpu = event.getCpuId();
181
182 LttngProcessState process = traceState.getRunning_process().get(
183 cpu);
184
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();
190 }
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();
197 }
198 }
199
200 /**
201 * Increase the State-bound Cumulative CPU Time according to the trace state.
202 */
203 protected void increaseStateCumulativeCPUTime(LttngEvent event,
204 LttngTraceState traceState) {
205 Long cpu = event.getCpuId();
206
207 LttngProcessState process = traceState.getRunning_process().get(cpu);
208
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);
214 }
215 }
216
217 // @Override
218 public Events getEventHandleType() {
219 return eventType;
220 }
221
222 }
This page took 0.036915 seconds and 5 git commands to generate.