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 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
;
15 import org
.eclipse
.linuxtools
.lttng
.core
.event
.LttngEvent
;
16 import org
.eclipse
.linuxtools
.lttng
.core
.state
.StateStrings
.Channels
;
17 import org
.eclipse
.linuxtools
.lttng
.core
.state
.StateStrings
.Events
;
18 import org
.eclipse
.linuxtools
.lttng
.core
.state
.StateStrings
.Fields
;
19 import org
.eclipse
.linuxtools
.lttng
.core
.state
.evProcessor
.ILttngEventProcessor
;
20 import org
.eclipse
.linuxtools
.lttng
.core
.state
.model
.LttngTraceState
;
21 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
;
22 import org
.eclipse
.linuxtools
.lttng
.ui
.model
.trange
.TimeRangeEventResource
.ResourceTypes
;
23 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfTimeRange
;
26 * Creates instances of specific before state update handlers, per corresponding
32 public class ResourcesBeforeUpdateHandlers
{
36 * Handles: LTT_EVENT_SCHED_SCHEDULE
38 * Replace C function named "before_schedchange_hook" in eventhooks.c
40 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID(?), LTT_FIELD_PREV_STATE
46 final ILttngEventProcessor
getBeforeSchedChangeHandler() {
47 AbsResourcesTRangeUpdate handler
= new AbsResourcesTRangeUpdate() {
51 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
52 // Create a time range for the cpu.
53 globalProcessBeforeExecmode(trcEvent
, traceSt
);
64 * Handles: LTT_EVENT_IRQ_ENTRY, LTT_EVENT_IRQ_EXIT
66 * Replace C function named "before_execmode_hook_irq" in eventhooks.c
70 final ILttngEventProcessor
getBeforeExecutionModeIrq() {
71 AbsResourcesTRangeUpdate handler
= new AbsResourcesTRangeUpdate() {
75 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
79 // According to Ltt, we should not draw anything if the channel
81 if (trcEvent
.getChannelName().equals(
82 Channels
.LTT_CHANNEL_KERNEL
)) {
86 if (trcEvent
.getMarkerName().equals(
87 Events
.LTT_EVENT_IRQ_ENTRY
.getInName())) {
88 irqId
= getAFieldLong(trcEvent
, traceSt
,
89 Fields
.LTT_FIELD_IRQ_ID
);
90 } else if (trcEvent
.getMarkerName().equals(
91 Events
.LTT_EVENT_IRQ_EXIT
.getInName())) {
92 long cpu
= trcEvent
.getCpuId();
93 irqId
= traceSt
.getCpu_states().get(cpu
)
95 if (irqId
.equals(-1L)) {
102 // softIrqId is the resource id here
103 TimeRangeEventResource localResource
= resourcelist_obtain_irq(
106 // If the resource is missing in the list, add it
107 if (localResource
== null) {
108 TmfTimeRange timeRange
= traceSt
.getContext()
109 .getTraceTimeWindow();
110 localResource
= addLocalResource(timeRange
111 .getStartTime().getValue(), timeRange
112 .getEndTime().getValue(), traceSt
.getTraceId(),
113 ResourceTypes
.IRQ
, irqId
, trcEvent
114 .getTimestamp().getValue());
117 // get the start time
118 long stime
= localResource
.getNext_good_time();
120 // Get the resource state mode
121 String irqStateMode
= localResource
.getStateMode(traceSt
);
123 // Call the makeDraw function
124 makeDraw(traceSt
, stime
,
125 trcEvent
.getTimestamp().getValue(), localResource
,
126 params
, irqStateMode
);
128 // Call the globalProcessBeforeExecmode() after, as
129 // it is needed by all
130 // getBeforeExecmode*SOMETHING*()
131 globalProcessBeforeExecmode(trcEvent
, traceSt
);
142 * Handles: LTT_EVENT_SOFT_IRQ_RAISE, LTT_EVENT_SOFT_IRQ_ENTRY,
143 * LTT_EVENT_SOFT_IRQ_EXIT,
145 * Replace C function named "before_execmode_hook_soft_irq" in eventhooks.c
147 * Fields: LTT_FIELD_SOFT_IRQ_ID
152 final ILttngEventProcessor
getBeforeExecutionModeSoftIrq() {
153 AbsResourcesTRangeUpdate handler
= new AbsResourcesTRangeUpdate() {
157 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
159 Long softIrqId
= null;
161 // According to Ltt, we should not draw anything if the channel
163 if (trcEvent
.getChannelName().equals(
164 Channels
.LTT_CHANNEL_KERNEL
)) {
168 if ((trcEvent
.getMarkerName()
169 .equals(Events
.LTT_EVENT_SOFT_IRQ_RAISE
.getInName()))
170 || (trcEvent
.getMarkerName()
171 .equals(Events
.LTT_EVENT_SOFT_IRQ_ENTRY
173 softIrqId
= getAFieldLong(trcEvent
, traceSt
,
174 Fields
.LTT_FIELD_SOFT_IRQ_ID
);
175 } else if (trcEvent
.getMarkerName().equals(
176 Events
.LTT_EVENT_SOFT_IRQ_EXIT
.getInName())) {
177 long cpu
= trcEvent
.getCpuId();
178 softIrqId
= traceSt
.getCpu_states().get(cpu
)
179 .peekFromSoftIrqStack();
186 // Add the resource to the resource list
187 // softIrqId is the resource id here
188 TimeRangeEventResource localResource
= resourcelist_obtain_soft_irq(
191 // If the resource is missing in the list, add it
192 if (localResource
== null) {
193 TmfTimeRange timeRange
= traceSt
.getContext()
194 .getTraceTimeWindow();
195 localResource
= addLocalResource(timeRange
196 .getStartTime().getValue(), timeRange
197 .getEndTime().getValue(), traceSt
.getTraceId(),
198 ResourceTypes
.SOFT_IRQ
, softIrqId
, trcEvent
199 .getTimestamp().getValue());
202 // get the start time
203 long stime
= localResource
.getNext_good_time();
205 // Get the resource state mode
206 String softIrqStateMode
= localResource
207 .getStateMode(traceSt
);
209 // Call the makeDraw function
210 makeDraw(traceSt
, stime
,
211 trcEvent
.getTimestamp().getValue(), localResource
,
212 params
, softIrqStateMode
);
214 // Call the globalProcessBeforeExecmode() after, as
215 // it is needed by all
216 // getBeforeExecmode*SOMETHING*()
217 globalProcessBeforeExecmode(trcEvent
, traceSt
);
230 * Handles: LTT_EVENT_TRAP_ENTRY, LTT_EVENT_TRAP_EXIT,
231 * LTT_EVENT_PAGE_FAULT_ENTRY, LTT_EVENT_PAGE_FAULT_EXIT,
232 * LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
234 * Replace C function named "before_execmode_hook_trap" in eventhooks.c
236 * Fields: LTT_FIELD_TRAP_ID
241 final ILttngEventProcessor
getBeforeExecutionModeTrap() {
242 AbsResourcesTRangeUpdate handler
= new AbsResourcesTRangeUpdate() {
246 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
250 // According to Ltt, we should not draw anything if the channel
252 if (trcEvent
.getChannelName().equals(
253 Channels
.LTT_CHANNEL_KERNEL
)) {
257 if ((trcEvent
.getMarkerName()
258 .equals(Events
.LTT_EVENT_TRAP_ENTRY
.getInName()))
259 || (trcEvent
.getMarkerName()
260 .equals(Events
.LTT_EVENT_PAGE_FAULT_ENTRY
262 || (trcEvent
.getMarkerName()
263 .equals(Events
.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
265 trapId
= getAFieldLong(trcEvent
, traceSt
,
266 Fields
.LTT_FIELD_TRAP_ID
);
267 } else if ((trcEvent
.getMarkerName()
268 .equals(Events
.LTT_EVENT_TRAP_EXIT
.getInName()))
269 || (trcEvent
.getMarkerName()
270 .equals(Events
.LTT_EVENT_PAGE_FAULT_EXIT
272 || (trcEvent
.getMarkerName()
273 .equals(Events
.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
275 long cpu
= trcEvent
.getCpuId();
276 trapId
= traceSt
.getCpu_states().get(cpu
)
277 .peekFromTrapStack();
279 if (trapId
.equals(-1L)) {
287 // Add the resource to the resource list
288 // trapId is the resource id here
289 TimeRangeEventResource localResource
= resourcelist_obtain_trap(
292 // If the resource is missing in the list, add it
293 if (localResource
== null) {
294 TmfTimeRange timeRange
= traceSt
.getContext()
295 .getTraceTimeWindow();
296 localResource
= addLocalResource(timeRange
297 .getStartTime().getValue(), timeRange
298 .getEndTime().getValue(), traceSt
.getTraceId(),
299 ResourceTypes
.TRAP
, trapId
, trcEvent
300 .getTimestamp().getValue());
303 // Determine the trap state.
304 String trapStateMode
= localResource
.getStateMode(traceSt
);
306 long stime
= localResource
.getNext_good_time();
307 makeDraw(traceSt
, stime
,
308 trcEvent
.getTimestamp().getValue(), localResource
,
309 params
, trapStateMode
);
311 // Call the globalProcessBeforeExecmode() after, as
312 // it is needed by all
313 // getBeforeExecmode*SOMETHING*()
314 globalProcessBeforeExecmode(trcEvent
, traceSt
);
327 * Handles: LTT_EVENT_REQUEST_ISSUE, LTT_EVENT_REQUEST_COMPLETE
329 * Replace C function named "before_bdev_event_hook" in eventhooks.c
331 * Fields: LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION (?)
336 final ILttngEventProcessor
getBeforeBdevEvent() {
337 AbsResourcesTRangeUpdate handler
= new AbsResourcesTRangeUpdate() {
341 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
342 Long major
= getAFieldLong(trcEvent
, traceSt
,
343 Fields
.LTT_FIELD_MAJOR
);
344 Long minor
= getAFieldLong(trcEvent
, traceSt
,
345 Fields
.LTT_FIELD_MINOR
);
346 // This is useless even in LTTv!
347 // Long oper = getAFieldLong(trcEvent, traceSt,
348 // Fields.LTT_FIELD_OPERATION);
350 Long bdevId
= getMkdevId(major
, minor
);
352 // According to Lttv, bdevId (obtain from MKDEV macro) is
354 TimeRangeEventResource localResource
= resourcelist_obtain_bdev(
357 if (localResource
== null) {
358 TmfTimeRange timeRange
= traceSt
.getContext()
359 .getTraceTimeWindow();
360 localResource
= addLocalResource(timeRange
.getStartTime()
361 .getValue(), timeRange
.getEndTime().getValue(),
362 traceSt
.getTraceId(), ResourceTypes
.BDEV
, bdevId
,
363 trcEvent
.getTimestamp().getValue());
366 // get the start time
367 long stime
= localResource
.getNext_good_time();
368 // Get the resource state mode
369 String bdevStateMode
= localResource
.getStateMode(traceSt
);
370 // Call the makeDraw function
371 makeDraw(traceSt
, stime
, trcEvent
.getTimestamp().getValue(),
372 localResource
, params
, bdevStateMode
);