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