2010-10-26 Francois Chouinard <fchouinard@gmail.com> Contribution for Bug309042
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.ui / src / org / eclipse / linuxtools / lttng / ui / views / resources / evProcessor / ResourcesBeforeUpdateHandlers.java
CommitLineData
6e512b93
ASL
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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor;
13
14import org.eclipse.linuxtools.lttng.event.LttngEvent;
15import org.eclipse.linuxtools.lttng.state.StateStrings.Channels;
16import org.eclipse.linuxtools.lttng.state.StateStrings.Events;
17import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
18import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
19import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
20import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource;
21import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes;
22import org.eclipse.linuxtools.tmf.event.TmfTimeRange;
23
24/**
25 * Creates instances of specific before state update handlers, per corresponding
26 * event.
27 *
28 * @author alvaro
29 *
30 */
31public class ResourcesBeforeUpdateHandlers {
32
33 /**
34 * <p>
35 * Handles: LTT_EVENT_SCHED_SCHEDULE
36 * </p>
37 * Replace C function named "before_schedchange_hook" in eventhooks.c
38 * <p>
39 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID(?), LTT_FIELD_PREV_STATE
40 * (?)
41 * </p>
42 *
43 * @return
44 */
45 final ILttngEventProcessor getBeforeSchedChangeHandler() {
46 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
47
48 // @Override
d4011df2 49 @Override
6e512b93
ASL
50 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
51 // Create a time range for the cpu.
52 globalProcessBeforeExecmode(trcEvent, traceSt);
53
54 return false;
55 }
56 };
57
58 return handler;
59 }
60
61 /**
62 * <p>
63 * Handles: LTT_EVENT_IRQ_ENTRY, LTT_EVENT_IRQ_EXIT
64 * </p>
65 * Replace C function named "before_execmode_hook_irq" in eventhooks.c
66 *
67 * @return
68 */
69 final ILttngEventProcessor getBeforeExecutionModeIrq() {
70 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
71
72 // @Override
d4011df2 73 @Override
6e512b93
ASL
74 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
75
76 Long irqId = null;
77
78 // According to Ltt, we should not draw anything if the channel
79 // is the kernel one
80 if (trcEvent.getChannelName().equals(
81 Channels.LTT_CHANNEL_KERNEL)) {
82 return false;
83 } else {
84
85 if (trcEvent.getMarkerName().equals(
86 Events.LTT_EVENT_IRQ_ENTRY.getInName())) {
87 irqId = getAFieldLong(trcEvent, traceSt,
88 Fields.LTT_FIELD_IRQ_ID);
89 } else if (trcEvent.getMarkerName().equals(
90 Events.LTT_EVENT_IRQ_EXIT.getInName())) {
91 long cpu = trcEvent.getCpuId();
92 irqId = traceSt.getCpu_states().get(cpu)
93 .peekFromIrqStack();
94 if (irqId.equals(-1L)) {
95 // nothing to update
96 return false;
97 }
98 }
99
100
101 // softIrqId is the resource id here
102 TimeRangeEventResource localResource = resourcelist_obtain_irq(
103 traceSt, irqId);
104
105 // If the resource is missing in the list, add it
106 if (localResource == null) {
107 TmfTimeRange timeRange = traceSt.getContext()
108 .getTraceTimeWindow();
109 localResource = addLocalResource(timeRange
110 .getStartTime().getValue(), timeRange
111 .getEndTime().getValue(), traceSt.getTraceId(),
112 ResourceTypes.IRQ, irqId, trcEvent
113 .getTimestamp().getValue());
114 }
115
116 // get the start time
117 long stime = localResource.getNext_good_time();
118
119 // Get the resource state mode
120 String irqStateMode = localResource.getStateMode(traceSt);
121
122 // Call the makeDraw function
123 makeDraw(traceSt, stime,
124 trcEvent.getTimestamp().getValue(), localResource,
125 params, irqStateMode);
126
127 // Call the globalProcessBeforeExecmode() after, as
128 // it is needed by all
129 // getBeforeExecmode*SOMETHING*()
130 globalProcessBeforeExecmode(trcEvent, traceSt);
131 }
132 return false;
133 }
134 };
135
136 return handler;
137 }
138
139 /**
140 * <p>
141 * Handles: LTT_EVENT_SOFT_IRQ_RAISE, LTT_EVENT_SOFT_IRQ_ENTRY,
142 * LTT_EVENT_SOFT_IRQ_EXIT,
143 * </p>
144 * Replace C function named "before_execmode_hook_soft_irq" in eventhooks.c
145 * <p>
146 * Fields: LTT_FIELD_SOFT_IRQ_ID
147 * </p>
148 *
149 * @return
150 */
151 final ILttngEventProcessor getBeforeExecutionModeSoftIrq() {
152 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
153
154 // @Override
d4011df2 155 @Override
6e512b93
ASL
156 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
157
158 Long softIrqId = null;
159
160 // According to Ltt, we should not draw anything if the channel
161 // is the kernel one
162 if (trcEvent.getChannelName().equals(
163 Channels.LTT_CHANNEL_KERNEL)) {
164 return false;
165 } else {
166
167 if ((trcEvent.getMarkerName()
168 .equals(Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName()))
169 || (trcEvent.getMarkerName()
170 .equals(Events.LTT_EVENT_SOFT_IRQ_ENTRY
171 .getInName()))) {
172 softIrqId = getAFieldLong(trcEvent, traceSt,
173 Fields.LTT_FIELD_SOFT_IRQ_ID);
174 } else if (trcEvent.getMarkerName().equals(
175 Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName())) {
176 long cpu = trcEvent.getCpuId();
177 softIrqId = traceSt.getCpu_states().get(cpu)
178 .peekFromSoftIrqStack();
179 if (softIrqId < 0) {
180 // nothing to update
181 return false;
182 }
183 }
184
185 // Add the resource to the resource list
186 // softIrqId is the resource id here
187 TimeRangeEventResource localResource = resourcelist_obtain_soft_irq(
188 traceSt, softIrqId);
189
190 // If the resource is missing in the list, add it
191 if (localResource == null) {
192 TmfTimeRange timeRange = traceSt.getContext()
193 .getTraceTimeWindow();
194 localResource = addLocalResource(timeRange
195 .getStartTime().getValue(), timeRange
196 .getEndTime().getValue(), traceSt.getTraceId(),
197 ResourceTypes.SOFT_IRQ, softIrqId, trcEvent
198 .getTimestamp().getValue());
199 }
200
201 // get the start time
202 long stime = localResource.getNext_good_time();
203
204 // Get the resource state mode
205 String softIrqStateMode = localResource
206 .getStateMode(traceSt);
207
208 // Call the makeDraw function
209 makeDraw(traceSt, stime,
210 trcEvent.getTimestamp().getValue(), localResource,
211 params, softIrqStateMode);
212
213 // Call the globalProcessBeforeExecmode() after, as
214 // it is needed by all
215 // getBeforeExecmode*SOMETHING*()
216 globalProcessBeforeExecmode(trcEvent, traceSt);
217
218 }
219
220 return false;
221 }
222 };
223
224 return handler;
225 }
226
227 /**
228 * <p>
229 * Handles: LTT_EVENT_TRAP_ENTRY, LTT_EVENT_TRAP_EXIT,
230 * LTT_EVENT_PAGE_FAULT_ENTRY, LTT_EVENT_PAGE_FAULT_EXIT,
231 * LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
232 * </p>
233 * Replace C function named "before_execmode_hook_trap" in eventhooks.c
234 * <p>
235 * Fields: LTT_FIELD_TRAP_ID
236 * </p>
237 *
238 * @return
239 */
240 final ILttngEventProcessor getBeforeExecutionModeTrap() {
241 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
242
243 // @Override
d4011df2 244 @Override
6e512b93
ASL
245 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
246
247 Long trapId = null;
248
249 // According to Ltt, we should not draw anything if the channel
250 // is the kernel one
251 if (trcEvent.getChannelName().equals(
252 Channels.LTT_CHANNEL_KERNEL)) {
253 return false;
254 } else {
255
256 if ((trcEvent.getMarkerName()
257 .equals(Events.LTT_EVENT_TRAP_ENTRY.getInName()))
258 || (trcEvent.getMarkerName()
259 .equals(Events.LTT_EVENT_PAGE_FAULT_ENTRY
260 .getInName()))
261 || (trcEvent.getMarkerName()
262 .equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
263 .getInName()))) {
264 trapId = getAFieldLong(trcEvent, traceSt,
265 Fields.LTT_FIELD_TRAP_ID);
266 } else if ((trcEvent.getMarkerName()
267 .equals(Events.LTT_EVENT_TRAP_EXIT.getInName()))
268 || (trcEvent.getMarkerName()
269 .equals(Events.LTT_EVENT_PAGE_FAULT_EXIT
270 .getInName()))
271 || (trcEvent.getMarkerName()
272 .equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
273 .getInName()))) {
274 long cpu = trcEvent.getCpuId();
275 trapId = traceSt.getCpu_states().get(cpu)
276 .peekFromTrapStack();
277
278 if (trapId.equals(-1L)) {
279 // Nothing to update
280 return false;
281 }
282 } else {
283 return false;
284 }
285
286 // Add the resource to the resource list
287 // trapId is the resource id here
288 TimeRangeEventResource localResource = resourcelist_obtain_trap(
289 traceSt, trapId);
290
291 // If the resource is missing in the list, add it
292 if (localResource == null) {
293 TmfTimeRange timeRange = traceSt.getContext()
294 .getTraceTimeWindow();
295 localResource = addLocalResource(timeRange
296 .getStartTime().getValue(), timeRange
297 .getEndTime().getValue(), traceSt.getTraceId(),
298 ResourceTypes.TRAP, trapId, trcEvent
299 .getTimestamp().getValue());
300 }
301
302 // Determine the trap state.
303 String trapStateMode = localResource.getStateMode(traceSt);
304
305 long stime = localResource.getNext_good_time();
306 makeDraw(traceSt, stime,
307 trcEvent.getTimestamp().getValue(), localResource,
308 params, trapStateMode);
309
310 // Call the globalProcessBeforeExecmode() after, as
311 // it is needed by all
312 // getBeforeExecmode*SOMETHING*()
313 globalProcessBeforeExecmode(trcEvent, traceSt);
314
315 }
316
317 return false;
318 }
319 };
320
321 return handler;
322 }
323
324 /**
325 * <p>
326 * Handles: LTT_EVENT_REQUEST_ISSUE, LTT_EVENT_REQUEST_COMPLETE
327 * </p>
328 * Replace C function named "before_bdev_event_hook" in eventhooks.c
329 * <p>
330 * Fields: LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION (?)
331 * </p>
332 *
333 * @return
334 */
335 final ILttngEventProcessor getBeforeBdevEvent() {
336 AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {
337
338 // @Override
d4011df2 339 @Override
6e512b93
ASL
340 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
341 Long major = getAFieldLong(trcEvent, traceSt,
342 Fields.LTT_FIELD_MAJOR);
343 Long minor = getAFieldLong(trcEvent, traceSt,
344 Fields.LTT_FIELD_MINOR);
345 // This is useless even in LTTv!
346 // Long oper = getAFieldLong(trcEvent, traceSt,
347 // Fields.LTT_FIELD_OPERATION);
348
349 Long bdevId = getMkdevId(major, minor);
350
351 // According to Lttv, bdevId (obtain from MKDEV macro) is
352 // the id here
353 TimeRangeEventResource localResource = resourcelist_obtain_bdev(
354 traceSt, bdevId);
355
356 if (localResource == null) {
357 TmfTimeRange timeRange = traceSt.getContext()
358 .getTraceTimeWindow();
359 localResource = addLocalResource(timeRange.getStartTime()
360 .getValue(), timeRange.getEndTime().getValue(),
361 traceSt.getTraceId(), ResourceTypes.BDEV, bdevId,
362 trcEvent.getTimestamp().getValue());
363 }
364
365 // get the start time
366 long stime = localResource.getNext_good_time();
367 // Get the resource state mode
368 String bdevStateMode = localResource.getStateMode(traceSt);
369 // Call the makeDraw function
370 makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(),
371 localResource, params, bdevStateMode);
372
373 return false;
374 }
375 };
376
377 return handler;
378 }
379}
This page took 0.040141 seconds and 5 git commands to generate.