2010-11-09 Francois Chouinard <fchouinard@gmail.com> Fix for Bug329764
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / evProcessor / state / StateUpdateHandlers.java
CommitLineData
5d10d135
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 *******************************************************************************/
9dbeec54 12
5d10d135
ASL
13package org.eclipse.linuxtools.lttng.state.evProcessor.state;
14
15import java.util.Map;
16
17import org.eclipse.linuxtools.lttng.TraceDebug;
18import org.eclipse.linuxtools.lttng.event.LttngEvent;
19import org.eclipse.linuxtools.lttng.state.StateStrings;
20import org.eclipse.linuxtools.lttng.state.StateStrings.BdevMode;
21import org.eclipse.linuxtools.lttng.state.StateStrings.CpuMode;
22import org.eclipse.linuxtools.lttng.state.StateStrings.Events;
23import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode;
24import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionSubMode;
25import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
26import org.eclipse.linuxtools.lttng.state.StateStrings.IRQMode;
27import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus;
28import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessType;
8827c197 29import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
5d10d135
ASL
30import org.eclipse.linuxtools.lttng.state.model.LTTngCPUState;
31import org.eclipse.linuxtools.lttng.state.model.LttngBdevState;
32import org.eclipse.linuxtools.lttng.state.model.LttngExecutionState;
33import org.eclipse.linuxtools.lttng.state.model.LttngIRQState;
34import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
35import org.eclipse.linuxtools.lttng.state.model.LttngSoftIRQState;
36import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
37import org.eclipse.linuxtools.lttng.state.model.LttngTrapState;
38import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
39
40/**
41 * Wraps the creation of individual handlers, each method creates and instance
42 * of the corresponding handler
43 *
44 * @author alvaro
45 *
46 */
47class StateUpdateHandlers {
48
8827c197 49 final ILttngEventProcessor getSyscallEntryHandler() {
5d10d135
ASL
50 AbsStateUpdate handler = new AbsStateUpdate() {
51
52 // @Override
d4011df2 53 @Override
5d10d135
ASL
54 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
55
56 Long cpu = trcEvent.getCpuId();
57
58 // No syscall_entry update for initialization process
59 LttngProcessState process = traceSt.getRunning_process().get(
60 cpu);
61 if ((process != null) && (process.getPid() != null)
62 && (process.getPid().longValue() == 0L)) {
63 return true;
64 }
65
66 // Get the expected event field
67 Long syscall = getAFieldLong(trcEvent, traceSt,
68 Fields.LTT_FIELD_SYSCALL_ID);
69
70 String submode = null;
71 if (syscall == null) {
72 TraceDebug
73 .debug("Syscall Field not found, traceVent time: "
74 + trcEvent.getTimestamp());
75 } else {
76 submode = traceSt.getSyscall_names().get(syscall);
77 }
78
79 if (submode == null) {
80 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
81 .getInName();
82 }
83
84 push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
85 submode, trcEvent.getTimestamp(), traceSt);
86 return false;
87 }
88 };
89 return handler;
90 }
91
8827c197 92 final ILttngEventProcessor getsySyscallExitHandler() {
5d10d135
ASL
93 AbsStateUpdate handler = new AbsStateUpdate() {
94
95 // @Override
d4011df2 96 @Override
5d10d135
ASL
97 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
98
99 Long cpu = trcEvent.getCpuId();
100 LttngProcessState process = traceSt.getRunning_process().get(
101 cpu);
102
103 // No syscall_entry update for initialization process
104 if ((process != null) && (process.getPid() != null)
105 && (process.getPid().longValue() == 0L)) {
106 return true;
107 }
108
109 pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
110 traceSt, trcEvent.getTimestamp());
111 return false;
112
113 }
114 };
115 return handler;
116 }
117
118 /**
119 * Update stacks related to the parsing of an LttngEvent
120 *
121 * @return
122 */
8827c197 123 final ILttngEventProcessor getTrapEntryHandler() {
5d10d135
ASL
124 AbsStateUpdate handler = new AbsStateUpdate() {
125
126 // @Override
d4011df2 127 @Override
5d10d135
ASL
128 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
129 Long cpu = trcEvent.getCpuId();
130
131 Long trap = getAFieldLong(trcEvent, traceSt,
132 Fields.LTT_FIELD_TRAP_ID);
133 if (trap == null) {
134 TraceDebug
135 .debug("Trap field could not be found, event time: "
136 + trcEvent.getTimestamp());
137 return true;
138 }
139
140 // ready the trap submode name
141 String submode = traceSt.getTrap_names().get(trap);
142
143 if (submode == null) {
144 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
145 .getInName();
146 }
147
148 /* update process state */
149 push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
150 submode, trcEvent.getTimestamp(), traceSt);
151
152 /* update cpu status */
153 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
154 cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
155 cpust.pushToTrapStack(trap); /* update trap status */
e31e01e8 156
5d10d135 157 // update Trap State
e31e01e8
FC
158 LttngTrapState trap_state = null;
159 trap_state = traceSt.getTrap_states().get(trap);
160
161 // If the trape_state exists, just increment it's counter,
162 // otherwise, create it
163 if ( trap_state == null ) {
164 trap_state = new LttngTrapState();
165 trap_state.incrementRunning();
166 traceSt.getTrap_states().put(trap, trap_state);
167 }
168 else {
169 trap_state.incrementRunning();
170 }
171
5d10d135
ASL
172 return false;
173
174 }
175 };
176 return handler;
177 }
178
179 /**
180 *
181 * @return
182 */
8827c197 183 final ILttngEventProcessor getTrapExitHandler() {
5d10d135
ASL
184 AbsStateUpdate handler = new AbsStateUpdate() {
185
186 // @Override
d4011df2 187 @Override
5d10d135
ASL
188 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
189
190 Long cpu = trcEvent.getCpuId();
191 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
192 Long trap = cpust.popFromTrapStack();
193
194 /* update process state */
195 pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt, trcEvent
196 .getTimestamp());
197
198 /* update cpu status */
199 cpu_pop_mode(cpust);
200
201 if (trap != -1L) {
202 traceSt.getTrap_states().get(trap).decrementRunning();
203 }
204 // else {
205 // TraceDebug.debug("remove this line");
206 // }
207
208 return false;
209
210 }
211 };
212 return handler;
213 }
214
215 /**
216 *
217 * @return
218 */
8827c197 219 final ILttngEventProcessor getIrqEntryHandler() {
5d10d135
ASL
220 AbsStateUpdate handler = new AbsStateUpdate() {
221
222 // @Override
d4011df2 223 @Override
5d10d135
ASL
224 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
225
226 Long cpu = trcEvent.getCpuId();
227
228 Long irq = getAFieldLong(trcEvent, traceSt,
229 Fields.LTT_FIELD_IRQ_ID);
8827c197
FC
230 if (irq == null || traceSt.getIrq_states().get(irq) == null) {
231 if (irq != null) {
550d787e 232 TraceDebug.debug("Invalid irq (" + irq + "), ts = " + trcEvent.getOriginalTimestamp());
8827c197 233 }
5d10d135
ASL
234 return true;
235 }
236
237 String submode;
238 submode = traceSt.getIrq_names().get(irq);
239
240 if (submode == null) {
241 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
242 .getInName();
243 }
244
245 /*
246 * Do something with the info about being in user or system mode
247 * when int?
248 */
249 push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode, trcEvent
250 .getTimestamp(), traceSt);
251
252 /* update cpu state */
253 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
254 cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
255 cpust.pushToIrqStack(irq); /* last irq */
256
257 /* udpate irq state */
258 irq_push_mode(traceSt.getIrq_states().get(irq),
259 IRQMode.LTTV_IRQ_BUSY);
260 return false;
261
262 }
263 };
264 return handler;
265 }
266
267 /**
268 *
269 * @return
270 */
8827c197 271 final ILttngEventProcessor getSoftIrqExitHandler() {
5d10d135
ASL
272 AbsStateUpdate handler = new AbsStateUpdate() {
273
274 // @Override
d4011df2 275 @Override
5d10d135
ASL
276 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
277
278 Long cpu = trcEvent.getCpuId();
279 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
280 Long softirq = cpust.popFromSoftIrqStack();
281
282 // Update process status
283 pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
284 trcEvent.getTimestamp());
285
286 /* update softirq status */
287 if (softirq != -1) {
288 LttngSoftIRQState softIrqstate = traceSt
289 .getSoft_irq_states().get(softirq);
8827c197
FC
290 if (softIrqstate != null) {
291 softIrqstate.decrementRunning();
292 }
5d10d135
ASL
293 }
294
295 /* update cpu status */
296 cpu_pop_mode(cpust);
297
298 return false;
299 }
300 };
301 return handler;
302 }
303
304 /**
305 *
306 * @return
307 */
8827c197 308 final ILttngEventProcessor getIrqExitHandler() {
5d10d135
ASL
309 AbsStateUpdate handler = new AbsStateUpdate() {
310
311 // @Override
d4011df2 312 @Override
5d10d135
ASL
313 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
314
315 Long cpu = trcEvent.getCpuId();
316
317 /* update process state */
318 pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt, trcEvent
319 .getTimestamp());
320
321 /* update cpu status */
322 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
323 cpu_pop_mode(cpust);
324
325 /* update irq status */
326 Long last_irq = cpust.popFromIrqStack();
327 if (last_irq != -1L) {
328 LttngIRQState irq_state = traceSt.getIrq_states().get(
329 last_irq);
330 irq_pop_mode(irq_state);
331 }
332
333 return false;
334
335 }
336 };
337 return handler;
338 }
339
340 /**
341 *
342 * @return
343 */
8827c197 344 final ILttngEventProcessor getSoftIrqRaiseHandler() {
5d10d135
ASL
345 AbsStateUpdate handler = new AbsStateUpdate() {
346
347 private Events eventType = Events.LTT_EVENT_SOFT_IRQ_RAISE;
348
349 // @Override
d4011df2 350 @Override
5d10d135
ASL
351 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
352
353 // Long cpu = trcEvent.getCpuId();
354
355 // get event field
356 Long softirq = getAFieldLong(trcEvent, traceSt,
357 Fields.LTT_FIELD_SOFT_IRQ_ID);
358
359 if (softirq == null) {
360 TraceDebug.debug("Soft_irq_id not found in "
361 + eventType.getInName() + " time: "
362 + trcEvent.getTimestamp());
363 return true;
364 }
365
366 // String submode;
367 // String[] softIrqNames = traceSt.getSoft_irq_names();
368 // if (softirq < softIrqNames.length) {
369 // submode = softIrqNames[softirq];
370 // } else {
371 // submode = "softirq " + softirq;
372 // }
373
374 /* update softirq status */
375 /* a soft irq raises are not cumulative */
376 LttngSoftIRQState irqState = traceSt.getSoft_irq_states().get(
377 softirq);
378 if (irqState != null) {
379 irqState.setPending(1L);
380 } else {
381 TraceDebug
382 .debug("unexpected soft irq id value: " + softirq);
383 }
384
385 return false;
386
387 }
388 };
389 return handler;
390 }
391
392 /**
393 *
394 * @return
395 */
8827c197 396 final ILttngEventProcessor getSoftIrqEntryHandler() {
5d10d135
ASL
397 AbsStateUpdate handler = new AbsStateUpdate() {
398
399 // @Override
d4011df2 400 @Override
5d10d135
ASL
401 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
402
403 // obtrain cpu
404 Long cpu = trcEvent.getCpuId();
405
406 // get event field
407 Long softirq = getAFieldLong(trcEvent, traceSt,
408 Fields.LTT_FIELD_SOFT_IRQ_ID);
409
410 if (softirq == null) {
411 TraceDebug.debug("Soft IRQ ID not found, eventTime: "
412 + trcEvent.getTimestamp());
413 return true;
414 }
415
416 // obtain submode
417 Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
418 String submode = softIrqNames.get(softirq);
419 if (submode == null) {
420 submode = "softirq " + softirq;
421 softIrqNames.put(softirq, submode);
422 }
423
424 /* update softirq status */
425 LttngSoftIRQState irqState = traceSt.getSoft_irq_states().get(
426 softirq);
427 if (irqState != null) {
428 irqState.decrementPending();
429 irqState.incrementRunning();
430 } else {
431 TraceDebug
432 .debug("unexpected soft irq id value: " + softirq);
433 }
434
435 /* update cpu state */
436 LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
437 cpu_state.pushToSoftIrqStack(softirq);
438 cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
439
440 /* update process execution mode state stack */
441 push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
442 trcEvent.getTimestamp(), traceSt);
443
444 return false;
445
446 }
447 };
448 return handler;
449 }
450
451 /**
452 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
453 *
454 * @return
455 */
8827c197 456 final ILttngEventProcessor getEnumInterruptHandler() {
5d10d135
ASL
457 AbsStateUpdate handler = new AbsStateUpdate() {
458
459 private Events eventType = Events.LTT_EVENT_LIST_INTERRUPT;
460
461 // @Override
d4011df2 462 @Override
5d10d135
ASL
463 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
464 String action = getAFieldString(trcEvent, traceSt,
465 Fields.LTT_FIELD_ACTION);
466 Long irq = getAFieldLong(trcEvent, traceSt,
467 Fields.LTT_FIELD_IRQ_ID);
468
63eecb47 469 if (action == null) {
5d10d135
ASL
470 TraceDebug.debug("Field Action not found in event "
471 + eventType.getInName() + " time: "
472 + trcEvent.getTimestamp());
473 return true;
474 }
475
63eecb47 476 if (irq == null) {
5d10d135
ASL
477 TraceDebug.debug("Field irq_id not found in event "
478 + eventType.getInName() + " time: "
479 + trcEvent.getTimestamp());
480 return true;
481 }
482
483 Map<Long, String> irq_names = traceSt.getIrq_names();
484
485 irq_names.put(irq, action);
486 return false;
487
488 }
489 };
490 return handler;
491 }
492
493 /**
494 * Handle the event LTT_EVENT_REQUEST_ISSUE
495 *
496 * @return
497 */
8827c197 498 final ILttngEventProcessor getBdevRequestIssueHandler() {
5d10d135
ASL
499 AbsStateUpdate handler = new AbsStateUpdate() {
500
501 // @Override
d4011df2 502 @Override
5d10d135
ASL
503 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
504
505 // Get Fields
506 Long major = getAFieldLong(trcEvent, traceSt,
507 Fields.LTT_FIELD_MAJOR);
508 Long minor = getAFieldLong(trcEvent, traceSt,
509 Fields.LTT_FIELD_MINOR);
510 Long operation = getAFieldLong(trcEvent, traceSt,
511 Fields.LTT_FIELD_OPERATION);
512
513 // calculate bdevcode
514 Long devcode = mkdev(major, minor);
515
516 if (devcode == null) {
517 TraceDebug
518 .debug("incorrect calcualtion of bdevcode input( major: "
519 + major
520 + " minor: "
521 + minor
522 + " operation: " + operation);
523 return true;
524 }
525
526 Map<Long, LttngBdevState> bdev_states = traceSt
527 .getBdev_states();
528 // Get the instance
529 LttngBdevState bdevState = bdev_states.get(devcode);
530 if (bdevState == null) {
531 bdevState = new LttngBdevState();
532 }
533
534 // update the mode in the stack
535 if (operation == 0L) {
536 bdevState.pushToBdevStack(BdevMode.LTTV_BDEV_BUSY_READING);
537 } else {
538 bdevState.pushToBdevStack(BdevMode.LTTV_BDEV_BUSY_WRITING);
539 }
540
541 // make sure it is included in the set
542 bdev_states.put(devcode, bdevState);
543 return false;
544
545 }
546 };
547 return handler;
548 }
549
550 /**
551 * <p>
552 * Handling event: LTT_EVENT_REQUEST_COMPLETE
553 * </p>
554 * <p>
555 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
556 * </p>
557 *
558 * @return
559 */
8827c197 560 final ILttngEventProcessor getBdevRequestCompleteHandler() {
5d10d135
ASL
561 AbsStateUpdate handler = new AbsStateUpdate() {
562
563 // @Override
d4011df2 564 @Override
5d10d135
ASL
565 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
566
567 // Get Fields
568 Long major = getAFieldLong(trcEvent, traceSt,
569 Fields.LTT_FIELD_MAJOR);
570 Long minor = getAFieldLong(trcEvent, traceSt,
571 Fields.LTT_FIELD_MINOR);
572 Long operation = getAFieldLong(trcEvent, traceSt,
573 Fields.LTT_FIELD_OPERATION);
574
575 // calculate bdevcode
576 Long devcode = mkdev(major, minor);
577
578 if (devcode == null) {
579 TraceDebug
580 .debug("incorrect calcualtion of bdevcode input( major: "
581 + major
582 + " minor: "
583 + minor
584 + " operation: " + operation);
585 return true;
586 }
587
588 Map<Long, LttngBdevState> bdev_states = traceSt
589 .getBdev_states();
590 // Get the instance
591 LttngBdevState bdevState = bdev_states.get(devcode);
592 if (bdevState == null) {
593 bdevState = new LttngBdevState();
594 }
595
596 /* update block device */
597 bdev_pop_mode(bdevState);
598
599 return false;
600
601 }
602 };
603 return handler;
604 }
605
606 /**
607 * <p>
608 * Handles event: LTT_EVENT_FUNCTION_ENTRY
609 * </p>
610 * <p>
611 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
612 * </p>
613 *
614 * @return
615 */
8827c197 616 final ILttngEventProcessor getFunctionEntryHandler() {
5d10d135
ASL
617 AbsStateUpdate handler = new AbsStateUpdate() {
618
619 // @Override
d4011df2 620 @Override
5d10d135
ASL
621 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
622 Long cpu = trcEvent.getCpuId();
623 Long funcptr = getAFieldLong(trcEvent, traceSt,
624 Fields.LTT_FIELD_THIS_FN);
625
626 push_function(traceSt, funcptr, cpu);
627 return false;
628
629 }
630 };
631 return handler;
632 }
633
634 /**
635 *
636 * @return
637 */
8827c197 638 final ILttngEventProcessor getFunctionExitHandler() {
5d10d135
ASL
639 AbsStateUpdate handler = new AbsStateUpdate() {
640
641 // @Override
d4011df2 642 @Override
5d10d135
ASL
643 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
644
645 Long funcptr = getAFieldLong(trcEvent, traceSt,
646 Fields.LTT_FIELD_THIS_FN);
647
648 pop_function(traceSt, trcEvent, funcptr);
649 return false;
650
651 }
652 };
653 return handler;
654 }
655
656 /**
657 * <p>
658 * process event: LTT_EVENT_SYS_CALL_TABLE
659 * </p>
660 * <p>
661 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
662 * </p>
663 *
664 * @return
665 */
8827c197 666 final ILttngEventProcessor getDumpSyscallHandler() {
5d10d135
ASL
667 AbsStateUpdate handler = new AbsStateUpdate() {
668
669 // @Override
d4011df2 670 @Override
5d10d135
ASL
671 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
672 // obtain the syscall id
673 Long id = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_ID);
674
675 // Long address = getAFieldLong(trcEvent, traceSt,
676 // Fields.LTT_FIELD_ADDRESS);
677
678 // Obtain the symbol
679 String symbol = getAFieldString(trcEvent, traceSt,
680 Fields.LTT_FIELD_SYMBOL);
681
682 // fill the symbol to the sycall_names collection
683 traceSt.getSyscall_names().put(id, symbol);
684
685 return false;
686 }
687 };
688 return handler;
689 }
690
691 /**
692 * <p>
693 * Handles event: LTT_EVENT_KPROBE_TABLE
694 * </p>
695 * <p>
696 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
697 * </p>
698 *
699 * @return
700 */
8827c197 701 final ILttngEventProcessor getDumpKprobeHandler() {
5d10d135
ASL
702 AbsStateUpdate handler = new AbsStateUpdate() {
703
704 // @Override
d4011df2 705 @Override
5d10d135
ASL
706 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
707
708 Long ip = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_IP);
709 String symbol = getAFieldString(trcEvent, traceSt,
710 Fields.LTT_FIELD_SYMBOL);
711
712 traceSt.getKprobe_table().put(ip, symbol);
713
714 return false;
715
716 }
717 };
718 return handler;
719 }
720
721 /**
722 * <p>
723 * Handles: LTT_EVENT_SOFTIRQ_VEC
724 * </p>
725 * <p>
726 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
727 * </p>
728 *
729 * @return
730 */
8827c197 731 final ILttngEventProcessor getDumpSoftIrqHandler() {
5d10d135
ASL
732 AbsStateUpdate handler = new AbsStateUpdate() {
733
734 // @Override
d4011df2 735 @Override
5d10d135
ASL
736 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
737
738 // Get id
739 Long id = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_ID);
740
741 // Address not needed
742 // Long address = ltt_event_get_long_unsigned(e,
743 // lttv_trace_get_hook_field(th,
744 // 1));
745
746 // Get symbol
747 String symbol = getAFieldString(trcEvent, traceSt,
748 Fields.LTT_FIELD_SYMBOL);
749
750 // Register the soft irq name
751 traceSt.getSoft_irq_names().put(id, symbol);
752 return false;
753
754 }
755 };
756 return handler;
757 }
758
759 /**
760 * <p>
761 * Handles: LTT_EVENT_SCHED_SCHEDULE
762 * </p>
763 * <p>
764 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
765 * </p>
766 *
767 * @return
768 */
8827c197 769 final ILttngEventProcessor getSchedChangeHandler() {
5d10d135
ASL
770 AbsStateUpdate handler = new AbsStateUpdate() {
771
772 // @Override
d4011df2 773 @Override
5d10d135
ASL
774 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
775
776 Long cpu = trcEvent.getCpuId();
777 TmfTimestamp eventTime = trcEvent.getTimestamp();
778
779 LttngProcessState process = traceSt.getRunning_process().get(
780 cpu);
781
782 Long pid_out = getAFieldLong(trcEvent, traceSt,
783 Fields.LTT_FIELD_PREV_PID);
784 Long pid_in = getAFieldLong(trcEvent, traceSt,
785 Fields.LTT_FIELD_NEXT_PID);
786 Long state_out = getAFieldLong(trcEvent, traceSt,
787 Fields.LTT_FIELD_PREV_STATE);
788
789 if (process != null) {
790
791 /*
792 * We could not know but it was not the idle process
793 * executing. This should only happen at the beginning,
794 * before the first schedule event, and when the initial
795 * information (current process for each CPU) is missing. It
796 * is not obvious how we could, after the fact, compensate
797 * the wrongly attributed statistics.
798 */
799
800 // This test only makes sense once the state is known and if
801 // there
802 // is no
803 // missing events. We need to silently ignore schedchange
804 // coming
805 // after a
806 // process_free, or it causes glitches. (FIXME)
807 // if(unlikely(process->pid != pid_out)) {
808 // g_assert(process->pid == 0);
809 // }
810 if ((process.getPid().longValue() == 0L)
811 && (process.getState().getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
812 if ((pid_out != null) && (pid_out.longValue() == 0L)) {
813 /*
814 * Scheduling out of pid 0 at beginning of the trace
815 * : we know for sure it is in syscall mode at this
816 * point.
817 */
818
819 process.getState().setExec_mode(
820 ExecutionMode.LTTV_STATE_SYSCALL);
821 process.getState().setProc_status(
822 ProcessStatus.LTTV_STATE_WAIT);
823 process.getState().setChange_Time(
28b94d61 824 trcEvent.getTimestamp().getValue());
5d10d135 825 process.getState().setEntry_Time(
28b94d61 826 trcEvent.getTimestamp().getValue());
5d10d135
ASL
827 }
828 } else {
829 if (process.getState().getProc_status() == ProcessStatus.LTTV_STATE_EXIT) {
830 process.getState().setProc_status(
831 ProcessStatus.LTTV_STATE_ZOMBIE);
832 process.getState().setChange_Time(
28b94d61 833 trcEvent.getTimestamp().getValue());
5d10d135
ASL
834 } else {
835 if ((state_out != null)
836 && (state_out.longValue() == 0L)) {
837 process.getState().setProc_status(
838 ProcessStatus.LTTV_STATE_WAIT_CPU);
839 } else {
840 process.getState().setProc_status(
841 ProcessStatus.LTTV_STATE_WAIT);
842 }
843
844 process.getState().setChange_Time(
28b94d61 845 trcEvent.getTimestamp().getValue());
5d10d135
ASL
846 }
847
848 if ((state_out != null)
849 && (state_out == 32L || state_out == 64L)) { /*
850 * EXIT_DEAD
851 * ||
852 * TASK_DEAD
853 */
854 /* see sched.h for states */
855 if (!exit_process(traceSt, process)) {
856 process.getState().setProc_status(
857 ProcessStatus.LTTV_STATE_DEAD);
858 process.getState().setChange_Time(
28b94d61 859 trcEvent.getTimestamp().getValue());
5d10d135
ASL
860 }
861 }
862 }
863 }
864 process = lttv_state_find_process_or_create(traceSt, cpu,
865 pid_in, eventTime);
866
867 traceSt.getRunning_process().put(cpu, process);
868
869 process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
28b94d61 870 process.getState().setChange_Time(eventTime.getValue());
5d10d135
ASL
871 process.setCpu(cpu);
872 // process->state->s = LTTV_STATE_RUN;
873 // if(process->usertrace)
874 // process->usertrace->cpu = cpu;
875 // process->last_cpu_index =
876 // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
877
878 // process->state->change = s->parent.timestamp;
879
880 LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
881 /* update cpu status */
882 if ((pid_in != null) && (pid_in.longValue() == 0L)) {
883
884 /* going to idle task */
885 cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
886 } else {
887 /*
888 * scheduling a real task. we must be careful here: if we
889 * just schedule()'ed to a process that is in a trap, we
890 * must put the cpu in trap mode
891 */
892 cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
893 if (process.getState().getExec_mode() == ExecutionMode.LTTV_STATE_TRAP) {
894 cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
895 }
896 }
897 return false;
898
899 }
900 };
901 return handler;
902 }
903
904 /**
905 * <p>
906 * Handles: LTT_EVENT_PROCESS_FORK
907 * </p>
908 * <p>
909 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
910 * LTT_FIELD_CHILD_TGID)
911 * </p>
912 *
913 * @return
914 */
8827c197 915 final ILttngEventProcessor getProcessForkHandler() {
5d10d135
ASL
916 AbsStateUpdate handler = new AbsStateUpdate() {
917
918 // @Override
d4011df2 919 @Override
5d10d135
ASL
920 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
921
922 Long cpu = trcEvent.getCpuId();
923 LttngProcessState process = traceSt.getRunning_process().get(
924 cpu);
925 TmfTimestamp timeStamp = trcEvent.getTimestamp();
926
927 // /* Parent PID */
928 // Long parent_pid = getAFieldLong(trcEvent, traceSt,
929 // Fields.LTT_FIELD_PARENT_PID);
930
931 /* Child PID */
932 /* In the Linux Kernel, there is one PID per thread. */
933 Long child_pid = getAFieldLong(trcEvent, traceSt,
934 Fields.LTT_FIELD_CHILD_PID);
935
936 /* Child TGID */
937 /* tgid in the Linux kernel is the "real" POSIX PID. */
938 Long child_tgid = getAFieldLong(trcEvent, traceSt,
939 Fields.LTT_FIELD_CHILD_TGID);
940 if (child_tgid == null) {
941 child_tgid = 0L;
942 }
943
944 /*
945 * Mathieu : it seems like the process might have been scheduled
946 * in before the fork, and, in a rare case, might be the current
947 * process. This might happen in a SMP case where we don't have
948 * enough precision on the clocks.
949 *
950 * Test reenabled after precision fixes on time. (Mathieu)
951 */
952 // #if 0
953 // zombie_process = lttv_state_find_process(ts, ANY_CPU,
954 // child_pid);
955 //
956 // if(unlikely(zombie_process != NULL)) {
957 // /* Reutilisation of PID. Only now we are sure that the old
958 // PID
959 // * has been released. FIXME : should know when release_task
960 // happens
961 // instead.
962 // */
963 // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
964 // guint i;
965 // for(i=0; i< num_cpus; i++) {
966 // g_assert(zombie_process != ts->running_process[i]);
967 // }
968 //
969 // exit_process(s, zombie_process);
970 // }
971 // #endif //0
972
973 if (process.getPid().equals(child_pid)) {
974 TraceDebug
975 .debug("Unexpected, process pid equal to child pid: "
976 + child_pid
977 + " Event Time: "
978 + trcEvent.getTimestamp());
979 }
980
981 // g_assert(process->pid != child_pid);
982 // FIXME : Add this test in the "known state" section
983 // g_assert(process->pid == parent_pid);
984 LttngProcessState child_process = lttv_state_find_process(
985 traceSt, ANY_CPU, child_pid);
986 if (child_process == null) {
987 child_process = create_process(traceSt, cpu, child_pid,
988 child_tgid, timeStamp);
28b94d61 989 child_process.setPpid(process.getPid(), timeStamp.getValue());
5d10d135
ASL
990 } else {
991 /*
992 * The process has already been created : due to time
993 * imprecision between multiple CPUs : it has been scheduled
994 * in before creation. Note that we shouldn't have this kind
995 * of imprecision.
996 *
997 * Simply put a correct parent.
998 */
999 StringBuilder sb = new StringBuilder("Process " + child_pid);
1000 sb.append(" has been created at ["
1001 + child_process.getCreation_time() + "] ");
1002 sb.append("and inserted at ["
1003 + child_process.getInsertion_time() + "] ");
1004 sb.append("before \nfork on cpu " + cpu + " Event time: ["
1005 + trcEvent + "]\n.");
1006 sb
1007 .append("Probably an unsynchronized TSD problem on the traced machine.");
1008 TraceDebug.debug(sb.toString());
1009
1010 // g_assert(0); /* This is a problematic case : the process
1011 // has
1012 // beencreated
1013 // before the fork event */
1014 child_process.setPpid(process.getPid());
1015 child_process.setTgid(child_tgid);
1016 }
1017
1018 if (!child_process.getName().equals(
1019 ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
1020 TraceDebug.debug("Unexpected child process status: "
1021 + child_process.getName());
1022 }
1023
1024 child_process.setName(process.getName());
1025 child_process.setBrand(process.getBrand());
1026
1027 return false;
1028
1029 }
1030 };
1031 return handler;
1032 }
1033
1034 /**
1035 * <p>
1036 * Handles: LTT_EVENT_KTHREAD_CREATE
1037 * </p>
1038 * <p>
1039 * Fields: LTT_FIELD_PID
1040 * </p>
1041 *
1042 * @return
1043 */
8827c197 1044 final ILttngEventProcessor getProcessKernelThreadHandler() {
5d10d135
ASL
1045 AbsStateUpdate handler = new AbsStateUpdate() {
1046
1047 // @Override
d4011df2 1048 @Override
5d10d135
ASL
1049 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1050 /*
1051 * We stamp a newly created process as kernel_thread. The thread
1052 * should not be running yet.
1053 */
1054
1055 LttngExecutionState exState;
1056 Long pid;
1057 LttngProcessState process;
1058
1059 /* PID */
1060 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1061 // s->parent.target_pid = pid;
1062
1063 process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1064 pid, new TmfTimestamp());
1065
1066 if (!process.getState().getProc_status().equals(
1067 ProcessStatus.LTTV_STATE_DEAD)) {
1068 // Leave only the first element in the stack with execution
1069 // mode to
1070 // syscall
1071 exState = process.getFirstElementFromExecutionStack();
1072 exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1073 process.clearExecutionStack();
1074 process.pushToExecutionStack(exState);
1075 }
1076
1077 process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1078
1079 return false;
1080
1081 }
1082 };
1083 return handler;
1084 }
1085
1086 /**
1087 * <p>
1088 * Handles: LTT_EVENT_PROCESS_EXIT
1089 * </p>
1090 * <p>
1091 * LTT_FIELD_PID
1092 * </p>
1093 *
1094 * @return
1095 */
8827c197 1096 final ILttngEventProcessor getProcessExitHandler() {
5d10d135
ASL
1097 AbsStateUpdate handler = new AbsStateUpdate() {
1098
1099 // @Override
d4011df2 1100 @Override
5d10d135
ASL
1101 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1102
1103 Long pid;
1104 LttngProcessState process;
1105
1106 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1107 // s->parent.target_pid = pid;
1108
1109 // FIXME : Add this test in the "known state" section
1110 // g_assert(process->pid == pid);
1111
1112 process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1113 if (process != null) {
1114 process.getState().setProc_status(
1115 ProcessStatus.LTTV_STATE_EXIT);
1116 }
1117 return false;
1118
1119 }
1120 };
1121 return handler;
1122 }
1123
1124 /**
1125 * <p>
1126 * Handles: LTT_EVENT_PROCESS_FREE
1127 * </p>
1128 * <p>
1129 * Fields: LTT_FIELD_PID
1130 * </p>
1131 *
1132 * @return
1133 */
8827c197 1134 final ILttngEventProcessor getProcessFreeHandler() {
5d10d135
ASL
1135 AbsStateUpdate handler = new AbsStateUpdate() {
1136
1137 // @Override
d4011df2 1138 @Override
5d10d135
ASL
1139 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1140
1141 Long release_pid;
1142 LttngProcessState process;
1143
1144 /* PID of the process to release */
1145 release_pid = getAFieldLong(trcEvent, traceSt,
1146 Fields.LTT_FIELD_PID);
1147 // s->parent.target_pid = release_pid;
1148
1149 if ((release_pid != null) && (release_pid.longValue() == 0L)) {
1150 TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1151 + trcEvent.getTimestamp());
1152 }
1153
1154 process = lttv_state_find_process(traceSt, ANY_CPU, release_pid);
1155 if (process != null) {
1156 exit_process(traceSt, process);
1157 }
1158
1159 return false;
1160 // DISABLED
1161 // if(process != null) {
1162 /*
1163 * release_task is happening at kernel level : we can now safely
1164 * release the data structure of the process
1165 */
1166 // This test is fun, though, as it may happen that
1167 // at time t : CPU 0 : process_free
1168 // at time t+150ns : CPU 1 : schedule out
1169 // Clearly due to time imprecision, we disable it. (Mathieu)
1170 // If this weird case happen, we have no choice but to put the
1171 // Currently running process on the cpu to 0.
1172 // I re-enable it following time precision fixes. (Mathieu)
1173 // Well, in the case where an process is freed by a process on
1174 // another
1175 // CPU
1176 // and still scheduled, it happens that this is the schedchange
1177 // that
1178 // will
1179 // drop the last reference count. Do not free it here!
1180
1181 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1182 // guint i;
1183 // for(i=0; i< num_cpus; i++) {
1184 // //g_assert(process != ts->running_process[i]);
1185 // if(process == ts->running_process[i]) {
1186 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1187 // break;
1188 // }
1189 // }
1190 // if(i == num_cpus) /* process is not scheduled */
1191 // exit_process(s, process);
1192 // }
1193 //
1194 // return false;
1195
1196 }
1197 };
1198 return handler;
1199 }
1200
1201 /**
1202 * <p>
1203 * Handles: LTT_EVENT_EXEC
1204 * </p>
1205 * <p>
1206 * FIELDS: LTT_FIELD_FILENAME
1207 * </p>
1208 *
1209 * @return
1210 */
8827c197 1211 final ILttngEventProcessor getProcessExecHandler() {
5d10d135
ASL
1212 AbsStateUpdate handler = new AbsStateUpdate() {
1213
1214 // @Override
d4011df2 1215 @Override
5d10d135
ASL
1216 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1217
1218 Long cpu = trcEvent.getCpuId();
1219 LttngProcessState process = traceSt.getRunning_process().get(
1220 cpu);
1221
1222 // #if 0//how to use a sequence that must be transformed in a
1223 // string
1224 // /* PID of the process to release */
1225 // guint64 name_len = ltt_event_field_element_number(e,
1226 // lttv_trace_get_hook_field(th, 0));
1227 // //name = ltt_event_get_string(e,
1228 // lttv_trace_get_hook_field(th, 0));
1229 // LttField *child = ltt_event_field_element_select(e,
1230 // lttv_trace_get_hook_field(th, 0), 0);
1231 // gchar *name_begin =
1232 // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e, child));
1233 // gchar *null_term_name = g_new(gchar, name_len+1);
1234 // memcpy(null_term_name, name_begin, name_len);
1235 // null_term_name[name_len] = '\0';
1236 // process->name = g_quark_from_string(null_term_name);
1237 // #endif //0
1238
1239 process.setName(getAFieldString(trcEvent, traceSt,
1240 Fields.LTT_FIELD_FILENAME));
1241 process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1242 return false;
1243
1244 }
1245 };
1246 return handler;
1247 }
1248
1249 /**
1250 * <p>
1251 * LTT_EVENT_THREAD_BRAND
1252 * </p>
1253 * <p>
1254 * FIELDS: LTT_FIELD_NAME
1255 * </p>
1256 *
1257 * @return
1258 */
8827c197 1259 final ILttngEventProcessor GetThreadBrandHandler() {
5d10d135
ASL
1260 AbsStateUpdate handler = new AbsStateUpdate() {
1261
1262 // @Override
d4011df2 1263 @Override
5d10d135
ASL
1264 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1265
1266 String name;
1267 Long cpu = trcEvent.getCpuId();
1268 LttngProcessState process = traceSt.getRunning_process().get(
1269 cpu);
1270
1271 name = getAFieldString(trcEvent, traceSt, Fields.LTT_FIELD_NAME);
1272 process.setBrand(name);
1273 return false;
1274
1275 }
1276 };
1277 return handler;
1278 }
1279
1280 /**
1281 * @return
1282 */
8827c197 1283 final ILttngEventProcessor getStateDumpEndHandler() {
5d10d135
ASL
1284 AbsStateUpdate handler = new AbsStateUpdate() {
1285
1286 // @Override
d4011df2 1287 @Override
5d10d135
ASL
1288 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1289
1290 /* For all processes */
1291 /*
1292 * if kernel thread, if stack[0] is unknown, set to syscall
1293 * mode, wait
1294 */
1295 /* else, if stack[0] is unknown, set to user mode, running */
2211df66 1296 LttngProcessState[] processes = traceSt.getProcesses();
5d10d135 1297 TmfTimestamp time = trcEvent.getTimestamp();
2211df66
FC
1298
1299 for (int pos = 0; pos < processes.length; pos++) {
1300 fix_process(processes[pos], time);
5d10d135 1301 }
2211df66 1302
9dbeec54
FC
1303 // Set the current process to be running
1304 // TODO Should we do it for all process running on a cpu?
1305 LttngProcessState process = traceSt.getRunning_process().get(trcEvent.getCpuId());
1306 process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
1307
5d10d135
ASL
1308 return false;
1309
1310 }
1311
1312 /**
1313 * Private method used to establish the first execution state in the
1314 * stack for a given process
1315 *
1316 * @param process
1317 * @param timestamp
1318 */
1319 private void fix_process(LttngProcessState process,
1320 TmfTimestamp timestamp) {
1321
1322 LttngExecutionState es;
1323
1324 if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1325 es = process.getFirstElementFromExecutionStack();
1326
1327 if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1328 es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1329 es
1330 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1331 .getInName());
28b94d61
FC
1332 es.setEntry_Time(timestamp.getValue());
1333 es.setChange_Time(timestamp.getValue());
5d10d135
ASL
1334 es.setCum_cpu_time(0L);
1335 if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1336 es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1337 }
1338 }
1339 } else {
1340 es = process.getFirstElementFromExecutionStack();
1341 if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1342 es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1343 es
1344 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1345 .getInName());
28b94d61
FC
1346 es.setEntry_Time(timestamp.getValue());
1347 es.setChange_Time(timestamp.getValue());
5d10d135
ASL
1348 es.setCum_cpu_time(0L);
1349 if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1350 es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1351 }
1352
1353 // If the first element is also the one on top... mean
1354 // we have ONE element on the stack
1355 if (process.getFirstElementFromExecutionStack() == process
1356 .peekFromExecutionStack()) {
1357 /*
1358 * Still in bottom unknown mode, means never did a
1359 * system call May be either in user mode, syscall
1360 * mode, running or waiting.
1361 */
1362 /*
1363 * FIXME : we may be tagging syscall mode when being
1364 * user mode
1365 */
1366 // Get a new execution State
1367 es = new LttngExecutionState();
1368
1369 // initialize values
1370 es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1371 es
1372 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1373 .getInName());
28b94d61
FC
1374 es.setEntry_Time(timestamp.getValue());
1375 es.setChange_Time(timestamp.getValue());
5d10d135 1376 es.setCum_cpu_time(0L);
63eecb47 1377 es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
5d10d135
ASL
1378
1379 // Push the new state to the stack
1380 process.pushToExecutionStack(es);
1381 }
1382 }
1383 }
1384 }
1385 };
1386 return handler;
1387 }
1388
1389 /**
1390 * <p>
1391 * Handles: LTT_EVENT_PROCESS_STATE
1392 * </p>
1393 * <p>
1394 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1395 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1396 * LTT_FIELD_TGID
1397 * </p>
1398 *
1399 * @return
1400 */
8827c197 1401 final ILttngEventProcessor getEnumProcessStateHandler() {
5d10d135
ASL
1402 AbsStateUpdate handler = new AbsStateUpdate() {
1403
1404 // @Override
d4011df2 1405 @Override
5d10d135
ASL
1406 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1407
1408 Long parent_pid;
1409 Long pid;
1410 Long tgid;
1411 String command;
1412 Long cpu = trcEvent.getCpuId();
28b94d61 1413
5d10d135
ASL
1414 LttngProcessState process = traceSt.getRunning_process().get(
1415 cpu);
1416 LttngProcessState parent_process;
1417 String type;
1418 // String mode, submode, status;
1419 LttngExecutionState es;
28b94d61 1420
5d10d135
ASL
1421 /* PID */
1422 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1423
1424 /* Parent PID */
1425 parent_pid = getAFieldLong(trcEvent, traceSt,
1426 Fields.LTT_FIELD_PARENT_PID);
1427
1428 /* Command name */
1429 command = getAFieldString(trcEvent, traceSt,
1430 Fields.LTT_FIELD_NAME);
1431
1432 Long typeVal = getAFieldLong(trcEvent, traceSt,
1433 Fields.LTT_FIELD_TYPE);
63eecb47
FC
1434
1435 type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
5d10d135
ASL
1436 if ((typeVal != null) && (typeVal.longValue() == 0L)) {
1437 type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1438 }
1439
1440 // /* mode */
1441 // mode = getAFieldString(trcEvent, traceSt,
1442 // Fields.LTT_FIELD_MODE);
1443 //
1444 // /* submode */
1445 // submode = getAFieldString(trcEvent, traceSt,
1446 // Fields.LTT_FIELD_SUBMODE);
1447 //
1448 // /* status */
1449 // status = getAFieldString(trcEvent, traceSt,
1450 // Fields.LTT_FIELD_STATUS);
1451
1452 /* TGID */
1453 tgid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_TGID);
1454 if (tgid == null) {
1455 tgid = 0L;
1456 }
1457
1458 if ((pid != null) && (pid.longValue() == 0L)) {
1459 for (Long acpu : traceSt.getCpu_states().keySet()) {
1460 process = lttv_state_find_process(traceSt, acpu, pid);
1461 if (process != null) {
1462 process.setPpid(parent_pid);
1463 process.setTgid(tgid);
1464 process.setName(command);
1465 process
1466 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1467 } else {
1468 StringBuilder sb = new StringBuilder(
1469 "Unexpected, null process read from the TraceState list of processes, event time: "
1470 + trcEvent.getTimestamp());
1471 TraceDebug.debug(sb.toString());
1472 }
1473 }
1474 } else {
1475 /*
1476 * The process might exist if a process was forked while
1477 * performing the state dump.
1478 */
1479 process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1480 if (process == null) {
1481 parent_process = lttv_state_find_process(traceSt,
1482 ANY_CPU, parent_pid);
41dc35d0 1483 TmfTimestamp eventTime = trcEvent.getTimestamp();
5d10d135 1484 process = create_process(traceSt, cpu, pid, tgid,
41dc35d0 1485 command, eventTime);
5d10d135 1486 if (parent_process != null) {
28b94d61 1487 process.setPpid(parent_process.getPid(), eventTime.getValue());
5d10d135
ASL
1488 }
1489
1490 /* Keep the stack bottom : a running user mode */
1491 /*
1492 * Disabled because of inconsistencies in the current
1493 * statedump states.
1494 */
1495 if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1496 .getInName())) {
1497 /*
1498 * FIXME Kernel thread : can be in syscall or
1499 * interrupt or trap.
1500 */
1501 /*
1502 * Will cause expected trap when in fact being
1503 * syscall (even after end of statedump event) Will
1504 * cause expected interrupt when being syscall.
1505 * (only before end of statedump event)
1506 */
63eecb47 1507 // process type is USER_THREAD by default.
5d10d135
ASL
1508 process
1509 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1510
1511 }
63eecb47
FC
1512
1513 //Only one entry needed in the execution stack
1514 process.popFromExecutionStack();
5d10d135
ASL
1515 es = process.getState();
1516 es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1517 es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1518 es
1519 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1520 .getInName());
1521 // #if 0
1522 // /* UNKNOWN STATE */
1523 // {
1524 // es = process->state =
1525 // &g_array_index(process->execution_stack,
1526 // LttvExecutionState, 1);
1527 // es->t = LTTV_STATE_MODE_UNKNOWN;
1528 // es->s = LTTV_STATE_UNNAMED;
1529 // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1530 // }
1531 // #endif //0
1532 } else {
1533 /*
1534 * The process has already been created : Probably was
1535 * forked while dumping the process state or was simply
1536 * scheduled in prior to get the state dump event.
1537 */
1538 process.setPpid(parent_pid);
1539 process.setTgid(tgid);
1540 process.setName(command);
1541 if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1542 .getInName())) {
1543 process
1544 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1545 } else {
1546 process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1547 }
1548
1549 // es =
1550 // &g_array_index(process->execution_stack,
1551 // LttvExecutionState,
1552 // 0);
1553 // #if 0
1554 // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1555 // if(type == LTTV_STATE_KERNEL_THREAD)
1556 // es->t = LTTV_STATE_SYSCALL;
1557 // else
1558 // es->t = LTTV_STATE_USER_MODE;
1559 // }
1560 // #endif //0
1561 /*
1562 * Don't mess around with the stack, it will eventually
1563 * become ok after the end of state dump.
1564 */
1565 }
1566 }
1567
1568 return false;
1569
1570 }
1571 };
1572 return handler;
1573 }
1574
1575}
This page took 0.096096 seconds and 5 git commands to generate.