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 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.lttng
.tests
.state
.handlers
.after
;
16 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
17 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.Events
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionMode
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.IEventProcessing
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngExecutionState
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
24 import org
.eclipse
.linuxtools
.lttng
.tests
.state
.handlers
.AbsStateUpdate
;
27 * Process the system call entry event
32 class StateAfterUpdateHandlers
{
34 final IEventProcessing
getSyscallEntryHandler() {
35 AbsStateUpdate handler
= new AbsStateUpdate() {
37 private Events eventType
= Events
.LTT_EVENT_SYSCALL_ENTRY
;
40 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
41 // TraceDebug.debug("After event called");
43 Long cpu
= trcEvent
.getCpuId();
45 // No syscall_entry update for initialization process
46 LttngProcessState process
= traceSt
.getRunning_process().get(
49 if (pid
!= process
.getPid()) {
51 .debug("pid values don't match from before and after verification check");
54 if (process
.getPid() == 0L) {
58 // Make sure the top of the stack and the state of the stack are
61 LttngExecutionState stackState
= process
.peekFromExecutionStack();
62 if (stackState
!= process
.getState()) {
64 .debug("The top of the stack does not match to the process state");
67 if (stackState
.getExec_mode().getInName() != ExecutionMode
.LTTV_STATE_SYSCALL
69 TraceDebug
.debug("Unexpected ExecutionMode: "
70 + stackState
.getExec_mode().getInName()
72 + ExecutionMode
.LTTV_STATE_SYSCALL
.getInName());
75 if (stackState
.getEntry_LttTime() != trcEvent
.getTimestamp().getValue()) {
76 TraceDebug
.debug("Unexpected Entry time: "
77 + trcEvent
.getTimestamp() + " Expected: "
78 + stackState
.getEntry_LttTime());
85 public Events
getEventHandleType() {
92 final IEventProcessing
getsySyscallExitHandler() {
93 AbsStateUpdate handler
= new AbsStateUpdate() {
95 private Events eventType
= Events
.LTT_EVENT_SYSCALL_EXIT
;
98 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
100 // TraceDebug.debug("Syscall Exit After event called");
101 Long cpu
= trcEvent
.getCpuId();
102 LttngProcessState process
= traceSt
.getRunning_process().get(
105 /* There can be no system call from PID 0 : unknown state */
106 if (process
.getPid() == 0L) {
109 .debug("Unexpected pid from before and after verfication methods, before pid: "
112 + process
.getPid_time());
118 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
119 // traceSt, trcEvent.getTimestamp());
125 public Events
getEventHandleType() {
133 * Update stacks related to the parsing of an LttngEvent
137 final IEventProcessing
getTrapEntryHandler() {
138 AbsStateUpdate handler
= new AbsStateUpdate() {
140 private Events eventType
= Events
.LTT_EVENT_TRAP_ENTRY
;
143 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
144 // Long cpu = trcEvent.getCpuId();
146 // Long trap = getAFieldLong(trcEvent, traceSt,
147 // Fields.LTT_FIELD_TRAP_ID);
148 // if (trap == null) {
152 // String submode = traceSt.getSyscall_names()
155 // if (submode == null) {
156 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
160 // /* update process state */
161 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
162 // submode, trcEvent.getTimestamp(), traceSt);
164 // /* update cpu status */
165 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
166 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
167 // cpust.setLast_trap(trap); /* update trap status */
169 // // update Trap State
170 // LttngTrapState trap_state = traceSt.getTrap_states().get(
172 // trap_state.incrementRunning();
179 public Events
getEventHandleType() {
190 final IEventProcessing
getTrapExitHandler() {
191 AbsStateUpdate handler
= new AbsStateUpdate() {
193 private Events eventType
= Events
.LTT_EVENT_TRAP_EXIT
;
196 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
198 // Long cpu = trcEvent.getCpuId();
199 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
200 // Long trap = cpust.getLast_trap();
202 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
206 // /* update cpu status */
207 // cpu_pop_mode(cpust);
209 // /* update trap status */
210 // if (trap != -1L) {
211 // traceSt.getTrap_states().get(trap).decrementRunning();
218 public Events
getEventHandleType() {
229 final IEventProcessing
getIrqEntryHandler() {
230 AbsStateUpdate handler
= new AbsStateUpdate() {
232 private Events eventType
= Events
.LTT_EVENT_IRQ_ENTRY
;
235 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
237 // Long cpu = trcEvent.getCpuId();
239 // Long irq = getAFieldLong(trcEvent, traceSt,
240 // Fields.LTT_FIELD_IRQ_ID);
241 // if (irq == null) {
246 // submode = traceSt.getIrq_names().get(irq);
248 // if (submode == null) {
250 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
254 // * Do something with the info about being in user or system
258 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
260 // .getTimestamp(), traceSt);
262 // /* update cpu state */
263 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
264 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
265 // cpust.setLast_irq(irq); /* last irq */
267 // /* udpate irq state */
268 // irq_push_mode(traceSt.getIrq_states().get(irq),
269 // IRQMode.LTTV_IRQ_BUSY);
274 public Events
getEventHandleType() {
285 final IEventProcessing
getSoftIrqExitHandler() {
286 AbsStateUpdate handler
= new AbsStateUpdate() {
288 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_EXIT
;
291 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
293 // Long cpu = trcEvent.getCpuId();
294 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
295 // Long softirq = cpust.getLast_soft_irq();
296 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
297 // trcEvent.getTimestamp());
299 // /* update softirq status */
300 // if (softirq != -1) {
301 // LttngSoftIRQState softIrqstate = traceSt
302 // .getSoft_irq_states().get(softirq);
303 // softIrqstate.decrementRunning();
306 // /* update cpu status */
307 // cpu_pop_mode(cpust);
313 public Events
getEventHandleType() {
324 final IEventProcessing
getIrqExitHandler() {
325 AbsStateUpdate handler
= new AbsStateUpdate() {
327 private Events eventType
= Events
.LTT_EVENT_IRQ_EXIT
;
330 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
332 // Long cpu = trcEvent.getCpuId();
334 // /* update process state */
335 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
339 // /* update cpu status */
340 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
341 // cpu_pop_mode(cpust);
343 // /* update irq status */
344 // Long last_irq = cpust.getLast_irq();
345 // if (last_irq != -1L) {
346 // LttngIRQState irq_state = traceSt.getIrq_states().get(
348 // irq_pop_mode(irq_state);
356 public Events
getEventHandleType() {
367 final IEventProcessing
getSoftIrqRaiseHandler() {
368 AbsStateUpdate handler
= new AbsStateUpdate() {
370 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_RAISE
;
373 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
375 // // Long cpu = trcEvent.getCpuId();
377 // // get event field
378 // Long softirq = getAFieldLong(trcEvent, traceSt,
379 // Fields.LTT_FIELD_SOFT_IRQ_ID);
381 // if (softirq == null) {
385 // // String submode;
386 // // String[] softIrqNames = traceSt.getSoft_irq_names();
387 // // if (softirq < softIrqNames.length) {
388 // // submode = softIrqNames[softirq];
390 // // submode = "softirq " + softirq;
393 // /* update softirq status */
394 // /* a soft irq raises are not cumulative */
395 // LttngSoftIRQState irqState =
396 // traceSt.getSoft_irq_states().get(
398 // if (irqState != null) {
399 // irqState.setPending(1L);
402 // .debug("unexpected soft irq id value: " + softirq);
410 public Events
getEventHandleType() {
421 final IEventProcessing
getSoftIrqEntryHandler() {
422 AbsStateUpdate handler
= new AbsStateUpdate() {
424 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_ENTRY
;
427 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
430 // Long cpu = trcEvent.getCpuId();
432 // // get event field
433 // Long softirq = getAFieldLong(trcEvent, traceSt,
434 // Fields.LTT_FIELD_SOFT_IRQ_ID);
436 // if (softirq == null) {
441 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
442 // String submode = softIrqNames.get(softirq);
443 // if (submode == null) {
444 // submode = "softirq " + softirq;
445 // softIrqNames.put(softirq, submode);
448 // /* update softirq status */
449 // LttngSoftIRQState irqState =
450 // traceSt.getSoft_irq_states().get(
452 // if (irqState != null) {
453 // irqState.decrementPending();
454 // irqState.incrementRunning();
457 // .debug("unexpected soft irq id value: " + softirq);
460 // /* update cpu state */
461 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
462 // cpu_state.setLast_soft_irq(softirq);
463 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
465 // /* update process execution mode state stack */
466 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
467 // trcEvent.getTimestamp(), traceSt);
474 public Events
getEventHandleType() {
482 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
486 final IEventProcessing
getEnumInterruptHandler() {
487 AbsStateUpdate handler
= new AbsStateUpdate() {
489 private Events eventType
= Events
.LTT_EVENT_LIST_INTERRUPT
;
492 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
493 // String action = getAFieldString(trcEvent, traceSt,
494 // Fields.LTT_FIELD_ACTION);
495 // Long irq = getAFieldLong(trcEvent, traceSt,
496 // Fields.LTT_FIELD_IRQ_ID);
498 // Map<Long, String> irq_names = traceSt.getIrq_names();
500 // irq_names.put(irq, action);
506 public Events
getEventHandleType() {
514 * Handle the event LTT_EVENT_REQUEST_ISSUE
518 final IEventProcessing
getBdevRequestIssueHandler() {
519 AbsStateUpdate handler
= new AbsStateUpdate() {
521 private Events eventType
= Events
.LTT_EVENT_REQUEST_ISSUE
;
524 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
527 // Long major = getAFieldLong(trcEvent, traceSt,
528 // Fields.LTT_FIELD_MAJOR);
529 // Long minor = getAFieldLong(trcEvent, traceSt,
530 // Fields.LTT_FIELD_MINOR);
531 // Long operation = getAFieldLong(trcEvent, traceSt,
532 // Fields.LTT_FIELD_OPERATION);
534 // // calculate bdevcode
535 // Long devcode = mkdev(major, minor);
537 // if (devcode == null) {
539 // .debug("incorrect calcualtion of bdevcode input( major: "
543 // + " operation: " + operation);
547 // Map<Long, LttngBdevState> bdev_states = traceSt
548 // .getBdev_states();
549 // // Get the instance
550 // LttngBdevState bdevState = bdev_states.get(devcode);
551 // if (bdevState == null) {
552 // bdevState = new LttngBdevState();
555 // // update the mode in the stack
556 // if (operation == 0L) {
557 // bdevState.getMode_stack().push(
558 // BdevMode.LTTV_BDEV_BUSY_READING);
560 // bdevState.getMode_stack().push(
561 // BdevMode.LTTV_BDEV_BUSY_WRITING);
564 // // make sure it is included in the set
565 // bdev_states.put(devcode, bdevState);
571 public Events
getEventHandleType() {
580 * Handling event: LTT_EVENT_REQUEST_COMPLETE
583 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
588 final IEventProcessing
getBdevRequestCompleteHandler() {
589 AbsStateUpdate handler
= new AbsStateUpdate() {
591 private Events eventType
= Events
.LTT_EVENT_REQUEST_COMPLETE
;
594 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
597 // Long major = getAFieldLong(trcEvent, traceSt,
598 // Fields.LTT_FIELD_MAJOR);
599 // Long minor = getAFieldLong(trcEvent, traceSt,
600 // Fields.LTT_FIELD_MINOR);
601 // Long operation = getAFieldLong(trcEvent, traceSt,
602 // Fields.LTT_FIELD_OPERATION);
604 // // calculate bdevcode
605 // Long devcode = mkdev(major, minor);
607 // if (devcode == null) {
609 // .debug("incorrect calcualtion of bdevcode input( major: "
613 // + " operation: " + operation);
617 // Map<Long, LttngBdevState> bdev_states = traceSt
618 // .getBdev_states();
619 // // Get the instance
620 // LttngBdevState bdevState = bdev_states.get(devcode);
621 // if (bdevState == null) {
622 // bdevState = new LttngBdevState();
625 // /* update block device */
626 // bdev_pop_mode(bdevState);
633 public Events
getEventHandleType() {
642 * Handles event: LTT_EVENT_FUNCTION_ENTRY
645 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
650 final IEventProcessing
getFunctionEntryHandler() {
651 AbsStateUpdate handler
= new AbsStateUpdate() {
653 private Events eventType
= Events
.LTT_EVENT_FUNCTION_ENTRY
;
656 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
657 // Long cpu = trcEvent.getCpuId();
658 // Long funcptr = getAFieldLong(trcEvent, traceSt,
659 // Fields.LTT_FIELD_THIS_FN);
661 // push_function(traceSt, funcptr, cpu);
667 public Events
getEventHandleType() {
678 final IEventProcessing
getFunctionExitHandler() {
679 AbsStateUpdate handler
= new AbsStateUpdate() {
681 private Events eventType
= Events
.LTT_EVENT_FUNCTION_EXIT
;
684 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
686 // Long funcptr = getAFieldLong(trcEvent, traceSt,
687 // Fields.LTT_FIELD_THIS_FN);
689 // pop_function(traceSt, trcEvent, funcptr);
695 public Events
getEventHandleType() {
704 * process event: LTT_EVENT_SYS_CALL_TABLE
707 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
712 final IEventProcessing
getDumpSyscallHandler() {
713 AbsStateUpdate handler
= new AbsStateUpdate() {
715 private Events eventType
= Events
.LTT_EVENT_SYS_CALL_TABLE
;
718 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
719 // // obtain the syscall id
720 // Long id = getAFieldLong(trcEvent, traceSt,
721 // Fields.LTT_FIELD_ID);
723 // // Long address = getAFieldLong(trcEvent, traceSt,
724 // // Fields.LTT_FIELD_ADDRESS);
726 // // Obtain the symbol
727 // String symbol = getAFieldString(trcEvent, traceSt,
728 // Fields.LTT_FIELD_SYMBOL);
730 // // fill the symbol to the sycall_names collection
731 // traceSt.getSyscall_names().put(id, symbol);
737 public Events
getEventHandleType() {
746 * Handles event: LTT_EVENT_KPROBE_TABLE
749 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
754 final IEventProcessing
getDumpKprobeHandler() {
755 AbsStateUpdate handler
= new AbsStateUpdate() {
757 private Events eventType
= Events
.LTT_EVENT_KPROBE_TABLE
;
760 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
762 // Long ip = getAFieldLong(trcEvent, traceSt,
763 // Fields.LTT_FIELD_IP);
764 // String symbol = getAFieldString(trcEvent, traceSt,
765 // Fields.LTT_FIELD_SYMBOL);
767 // traceSt.getKprobe_table().put(ip, symbol);
774 public Events
getEventHandleType() {
783 * Handles: LTT_EVENT_SOFTIRQ_VEC
786 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
791 final IEventProcessing
getDumpSoftIrqHandler() {
792 AbsStateUpdate handler
= new AbsStateUpdate() {
794 private Events eventType
= Events
.LTT_EVENT_SOFTIRQ_VEC
;
797 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
800 // Long id = getAFieldLong(trcEvent, traceSt,
801 // Fields.LTT_FIELD_ID);
803 // // Address not needed
804 // // Long address = ltt_event_get_long_unsigned(e,
805 // // lttv_trace_get_hook_field(th,
809 // String symbol = getAFieldString(trcEvent, traceSt,
810 // Fields.LTT_FIELD_SYMBOL);
812 // // Register the soft irq name
813 // traceSt.getSoft_irq_names().put(id, symbol);
819 public Events
getEventHandleType() {
828 * Handles: LTT_EVENT_SCHED_SCHEDULE
831 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
836 final IEventProcessing
getSchedChangeHandler() {
837 AbsStateUpdate handler
= new AbsStateUpdate() {
839 private Events eventType
= Events
.LTT_EVENT_SCHED_SCHEDULE
;
842 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
844 // Long cpu = trcEvent.getCpuId();
845 // TmfTimestamp eventTime = trcEvent.getTimestamp();
847 // LttngProcessState process = traceSt.getRunning_process().get(
850 // Long pid_out = getAFieldLong(trcEvent, traceSt,
851 // Fields.LTT_FIELD_PREV_PID);
852 // Long pid_in = getAFieldLong(trcEvent, traceSt,
853 // Fields.LTT_FIELD_NEXT_PID);
854 // Long state_out = getAFieldLong(trcEvent, traceSt,
855 // Fields.LTT_FIELD_PREV_STATE);
857 // if (process != null) {
860 // * We could not know but it was not the idle process
861 // * executing. This should only happen at the beginning,
862 // * before the first schedule event, and when the initial
863 // * information (current process for each CPU) is missing. It
864 // * is not obvious how we could, after the fact, compensate
865 // * the wrongly attributed statistics.
868 // // This test only makes sense once the state is known and if
871 // // missing events. We need to silently ignore schedchange
874 // // process_free, or it causes glitches. (FIXME)
875 // // if(unlikely(process->pid != pid_out)) {
876 // // g_assert(process->pid == 0);
878 // if (process.getPid() == 0
879 // && process.getState().getExec_mode() ==
880 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
881 // if (pid_out == 0) {
883 // * Scheduling out of pid 0 at beginning of the trace
884 // * : we know for sure it is in syscall mode at this
887 // int stackSize = process.getExecution_stack().size();
888 // if (stackSize != 1) {
890 // .debug("unpexpected process execution stack size, expected 1, received: ");
893 // process.getState().setExec_mode(
894 // ExecutionMode.LTTV_STATE_SYSCALL);
895 // process.getState().setProc_status(
896 // ProcessStatus.LTTV_STATE_WAIT);
897 // process.getState().setChage_Time(
898 // trcEvent.getTimestamp());
899 // process.getState().setEntry_Time(
900 // trcEvent.getTimestamp());
903 // if (process.getState().getProc_status() ==
904 // ProcessStatus.LTTV_STATE_EXIT) {
905 // process.getState().setProc_status(
906 // ProcessStatus.LTTV_STATE_ZOMBIE);
907 // process.getState().setChage_Time(
908 // trcEvent.getTimestamp());
910 // if (state_out == 0L) {
911 // process.getState().setProc_status(
912 // ProcessStatus.LTTV_STATE_WAIT_CPU);
914 // process.getState().setProc_status(
915 // ProcessStatus.LTTV_STATE_WAIT);
918 // process.getState().setChage_Time(
919 // trcEvent.getTimestamp());
922 // if (state_out == 32L || state_out == 64L) { /*
927 // /* see sched.h for states */
928 // if (!exit_process(traceSt, process)) {
929 // process.getState().setProc_status(
930 // ProcessStatus.LTTV_STATE_DEAD);
931 // process.getState().setChage_Time(
932 // trcEvent.getTimestamp());
937 // process = lttv_state_find_process_or_create(traceSt, cpu,
938 // pid_in, eventTime);
940 // traceSt.getRunning_process().put(cpu, process);
942 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
943 // process.getState().setChage_Time(eventTime);
944 // process.setCpu(cpu);
945 // // process->state->s = LTTV_STATE_RUN;
946 // // if(process->usertrace)
947 // // process->usertrace->cpu = cpu;
948 // // process->last_cpu_index =
949 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
951 // // process->state->change = s->parent.timestamp;
953 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
954 // /* update cpu status */
955 // if (pid_in == 0) {
957 // /* going to idle task */
958 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
961 // * scheduling a real task. we must be careful here: if we
962 // * just schedule()'ed to a process that is in a trap, we
963 // * must put the cpu in trap mode
965 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
966 // if (process.getState().getExec_mode() ==
967 // ExecutionMode.LTTV_STATE_TRAP) {
968 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
976 public Events
getEventHandleType() {
985 * Handles: LTT_EVENT_PROCESS_FORK
988 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
989 * LTT_FIELD_CHILD_TGID)
994 final IEventProcessing
getProcessForkHandler() {
995 AbsStateUpdate handler
= new AbsStateUpdate() {
997 private Events eventType
= Events
.LTT_EVENT_PROCESS_FORK
;
1000 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1002 // Long cpu = trcEvent.getCpuId();
1003 // LttngProcessState process = traceSt.getRunning_process().get(
1005 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
1007 // // /* Parent PID */
1008 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
1009 // // Fields.LTT_FIELD_PARENT_PID);
1012 // /* In the Linux Kernel, there is one PID per thread. */
1013 // Long child_pid = getAFieldLong(trcEvent, traceSt,
1014 // Fields.LTT_FIELD_CHILD_PID);
1017 // /* tgid in the Linux kernel is the "real" POSIX PID. */
1018 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
1019 // Fields.LTT_FIELD_CHILD_TGID);
1020 // if (child_tgid == null) {
1025 // * Mathieu : it seems like the process might have been
1027 // * in before the fork, and, in a rare case, might be the
1029 // * process. This might happen in a SMP case where we don't
1031 // * enough precision on the clocks.
1033 // * Test reenabled after precision fixes on time. (Mathieu)
1036 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
1039 // // if(unlikely(zombie_process != NULL)) {
1040 // // /* Reutilisation of PID. Only now we are sure that the old
1042 // // * has been released. FIXME : should know when release_task
1046 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1048 // // for(i=0; i< num_cpus; i++) {
1049 // // g_assert(zombie_process != ts->running_process[i]);
1052 // // exit_process(s, zombie_process);
1056 // if (process.getPid() == child_pid) {
1058 // .debug("Unexpected, process pid equal to child pid: "
1060 // + " Event Time: "
1061 // + trcEvent.getTimestamp());
1064 // // g_assert(process->pid != child_pid);
1065 // // FIXME : Add this test in the "known state" section
1066 // // g_assert(process->pid == parent_pid);
1067 // LttngProcessState child_process = lttv_state_find_process(
1068 // traceSt, ANY_CPU, child_pid);
1069 // if (child_process == null) {
1070 // child_process = create_process(traceSt, cpu, child_pid,
1071 // child_tgid, timeStamp);
1074 // * The process has already been created : due to time
1075 // * imprecision between multiple CPUs : it has been scheduled
1076 // * in before creation. Note that we shouldn't have this kind
1077 // * of imprecision.
1079 // * Simply put a correct parent.
1081 // StringBuilder sb = new StringBuilder("Process " + child_pid);
1082 // sb.append(" has been created at ["
1083 // + child_process.getCration_time() + "] ");
1084 // sb.append("and inserted at ["
1085 // + child_process.getInsertion_time() + "] ");
1086 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
1087 // + trcEvent + "]\n.");
1089 // .append("Probably an unsynchronized TSD problem on the traced machine.");
1090 // TraceDebug.debug(sb.toString());
1092 // // g_assert(0); /* This is a problematic case : the process
1095 // // before the fork event */
1096 // child_process.setPpid(process.getPid());
1097 // child_process.setTgid(child_tgid);
1100 // if (!child_process.getName().equals(
1101 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
1102 // TraceDebug.debug("Unexpected child process status: "
1103 // + child_process.getName());
1106 // child_process.setName(process.getName());
1107 // child_process.setBrand(process.getBrand());
1114 public Events
getEventHandleType() {
1123 * Handles: LTT_EVENT_KTHREAD_CREATE
1126 * Fields: LTT_FIELD_PID
1131 final IEventProcessing
getProcessKernelThreadHandler() {
1132 AbsStateUpdate handler
= new AbsStateUpdate() {
1134 private Events eventType
= Events
.LTT_EVENT_KTHREAD_CREATE
;
1137 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1139 // * We stamp a newly created process as kernel_thread. The
1141 // * should not be running yet.
1144 // LttngExecutionState exState;
1146 // LttngProcessState process;
1149 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1150 // // s->parent.target_pid = pid;
1152 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1153 // pid, new TmfTimestamp());
1155 // if (!process.getState().getProc_status().equals(
1156 // ProcessStatus.LTTV_STATE_DEAD)) {
1157 // // Leave only the first element in the stack with execution
1160 // Stack<LttngExecutionState> processExStack = process
1161 // .getExecution_stack();
1162 // exState = processExStack.firstElement();
1163 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1164 // if (processExStack.size() > 1) {
1165 // processExStack.clear();
1166 // processExStack.add(exState);
1169 // // update the process state to the only one in the stack
1170 // process.setState(exState);
1173 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1180 public Events
getEventHandleType() {
1189 * Handles: LTT_EVENT_PROCESS_EXIT
1197 final IEventProcessing
getProcessExitHandler() {
1198 AbsStateUpdate handler
= new AbsStateUpdate() {
1200 private Events eventType
= Events
.LTT_EVENT_PROCESS_EXIT
;
1203 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1206 // LttngProcessState process;
1208 // pid = getAFieldLong(trcEvent, traceSt,
1209 // Fields.LTT_FIELD_PID);
1210 // // s->parent.target_pid = pid;
1212 // // FIXME : Add this test in the "known state" section
1213 // // g_assert(process->pid == pid);
1215 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1216 // if (process != null) {
1217 // process.getState().setProc_status(
1218 // ProcessStatus.LTTV_STATE_EXIT);
1225 public Events
getEventHandleType() {
1234 * Handles: LTT_EVENT_PROCESS_FREE
1237 * Fields: LTT_FIELD_PID
1242 final IEventProcessing
getProcessFreeHandler() {
1243 AbsStateUpdate handler
= new AbsStateUpdate() {
1245 private Events eventType
= Events
.LTT_EVENT_PROCESS_FREE
;
1248 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1250 // Long release_pid;
1251 // LttngProcessState process;
1253 // /* PID of the process to release */
1254 // release_pid = getAFieldLong(trcEvent, traceSt,
1255 // Fields.LTT_FIELD_PID);
1256 // // s->parent.target_pid = release_pid;
1258 // if (release_pid == 0) {
1259 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1260 // + trcEvent.getTimestamp());
1263 // process = lttv_state_find_process(traceSt, ANY_CPU,
1265 // if (process != null) {
1266 // exit_process(traceSt, process);
1271 // if(process != null) {
1273 * release_task is happening at kernel level : we can now safely
1274 * release the data structure of the process
1276 // This test is fun, though, as it may happen that
1277 // at time t : CPU 0 : process_free
1278 // at time t+150ns : CPU 1 : schedule out
1279 // Clearly due to time imprecision, we disable it. (Mathieu)
1280 // If this weird case happen, we have no choice but to put the
1281 // Currently running process on the cpu to 0.
1282 // I re-enable it following time precision fixes. (Mathieu)
1283 // Well, in the case where an process is freed by a process on
1286 // and still scheduled, it happens that this is the schedchange
1289 // drop the last reference count. Do not free it here!
1291 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1293 // for(i=0; i< num_cpus; i++) {
1294 // //g_assert(process != ts->running_process[i]);
1295 // if(process == ts->running_process[i]) {
1296 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1300 // if(i == num_cpus) /* process is not scheduled */
1301 // exit_process(s, process);
1309 public Events
getEventHandleType() {
1318 * Handles: LTT_EVENT_EXEC
1321 * FIELDS: LTT_FIELD_FILENAME
1326 final IEventProcessing
getProcessExecHandler() {
1327 AbsStateUpdate handler
= new AbsStateUpdate() {
1329 private Events eventType
= Events
.LTT_EVENT_EXEC
;
1332 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1334 // Long cpu = trcEvent.getCpuId();
1335 // LttngProcessState process = traceSt.getRunning_process().get(
1338 // // #if 0//how to use a sequence that must be transformed in a
1340 // // /* PID of the process to release */
1341 // // guint64 name_len = ltt_event_field_element_number(e,
1342 // // lttv_trace_get_hook_field(th, 0));
1343 // // //name = ltt_event_get_string(e,
1344 // // lttv_trace_get_hook_field(th, 0));
1345 // // LttField *child = ltt_event_field_element_select(e,
1346 // // lttv_trace_get_hook_field(th, 0), 0);
1347 // // gchar *name_begin =
1348 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1350 // // gchar *null_term_name = g_new(gchar, name_len+1);
1351 // // memcpy(null_term_name, name_begin, name_len);
1352 // // null_term_name[name_len] = '\0';
1353 // // process->name = g_quark_from_string(null_term_name);
1356 // process.setName(getAFieldString(trcEvent, traceSt,
1357 // Fields.LTT_FIELD_FILENAME));
1358 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1364 public Events
getEventHandleType() {
1373 * LTT_EVENT_THREAD_BRAND
1376 * FIELDS: LTT_FIELD_NAME
1381 final IEventProcessing
GetThreadBrandHandler() {
1382 AbsStateUpdate handler
= new AbsStateUpdate() {
1384 private Events eventType
= Events
.LTT_EVENT_THREAD_BRAND
;
1387 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1390 // Long cpu = trcEvent.getCpuId();
1391 // LttngProcessState process = traceSt.getRunning_process().get(
1394 // name = getAFieldString(trcEvent, traceSt,
1395 // Fields.LTT_FIELD_NAME);
1396 // process.setBrand(name);
1402 public Events
getEventHandleType() {
1412 final IEventProcessing
getStateDumpEndHandler() {
1413 AbsStateUpdate handler
= new AbsStateUpdate() {
1415 private Events eventType
= Events
.LTT_EVENT_STATEDUMP_END
;
1418 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1420 // /* For all processes */
1422 // * if kernel thread, if stack[0] is unknown, set to syscall
1425 // /* else, if stack[0] is unknown, set to user mode, running */
1426 // List<LttngProcessState> processes = traceSt.getProcesses();
1427 // TmfTimestamp time = trcEvent.getTimestamp();
1429 // for (LttngProcessState process : processes) {
1430 // fix_process(process, time);
1438 public Events
getEventHandleType() {
1446 * Private method used to establish the first execution state in the stack
1447 * for a given process
1452 // private void fix_process(LttngProcessState process,
1453 // TmfTimestamp timestamp) {
1455 // LttngExecutionState es;
1456 // Stack<LttngExecutionState> procStack = process
1457 // .getExecution_stack();
1459 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1460 // es = procStack.firstElement();
1462 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1463 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1465 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1467 // es.setEntry_Time(timestamp);
1468 // es.setChage_Time(timestamp);
1469 // es.setCum_cpu_time(0L);
1470 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1471 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1475 // es = procStack.firstElement();
1476 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1477 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1479 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1481 // es.setEntry_Time(timestamp);
1482 // es.setChage_Time(timestamp);
1483 // es.setCum_cpu_time(0L);
1484 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1485 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1488 // if (procStack.size() == 1) {
1490 // * Still in bottom unknown mode, means never did a
1491 // * system call May be either in user mode, syscall
1492 // * mode, running or waiting.
1495 // * FIXME : we may be tagging syscall mode when being
1498 // // Get a new execution State
1499 // es = new LttngExecutionState();
1501 // // initialize values
1502 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1504 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1506 // es.setEntry_Time(timestamp);
1507 // es.setChage_Time(timestamp);
1508 // es.setCum_cpu_time(0L);
1509 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1511 // // Push the new state to the stack
1512 // procStack.push(es);
1523 * Handles: LTT_EVENT_PROCESS_STATE
1526 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1527 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1533 final IEventProcessing
getEnumProcessStateHandler() {
1534 AbsStateUpdate handler
= new AbsStateUpdate() {
1536 private Events eventType
= Events
.LTT_EVENT_PROCESS_STATE
;
1539 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1545 // Long cpu = trcEvent.getCpuId();
1546 // LttngProcessState process = traceSt.getRunning_process().get(
1548 // LttngProcessState parent_process;
1550 // // String mode, submode, status;
1551 // LttngExecutionState es;
1554 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1557 // parent_pid = getAFieldLong(trcEvent, traceSt,
1558 // Fields.LTT_FIELD_PARENT_PID);
1560 // /* Command name */
1561 // command = getAFieldString(trcEvent, traceSt,
1562 // Fields.LTT_FIELD_NAME);
1564 // /* TODO: type field, Values need to be verified */
1566 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1567 // Fields.LTT_FIELD_TYPE);
1568 // if (typeVal == 0L) {
1569 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1571 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1574 // // FIXME: type is rarely used, enum must match possible
1578 // // mode = getAFieldString(trcEvent, traceSt,
1579 // // Fields.LTT_FIELD_MODE);
1582 // // submode = getAFieldString(trcEvent, traceSt,
1583 // // Fields.LTT_FIELD_SUBMODE);
1586 // // status = getAFieldString(trcEvent, traceSt,
1587 // // Fields.LTT_FIELD_STATUS);
1590 // tgid = getAFieldLong(trcEvent, traceSt,
1591 // Fields.LTT_FIELD_TGID);
1592 // if (tgid == null) {
1597 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1598 // process = lttv_state_find_process(traceSt, acpu, pid);
1599 // if (process != null) {
1600 // process.setPpid(parent_pid);
1601 // process.setTgid(tgid);
1602 // process.setName(command);
1604 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1606 // StringBuilder sb = new StringBuilder(
1607 // "Unexpected, null process read from the TraceState list of processes, event time: "
1608 // + trcEvent.getTimestamp());
1609 // TraceDebug.debug(sb.toString());
1614 // * The process might exist if a process was forked while
1615 // * performing the state dump.
1617 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1618 // if (process == null) {
1619 // parent_process = lttv_state_find_process(traceSt,
1620 // ANY_CPU, parent_pid);
1621 // process = create_process(traceSt, cpu, pid, tgid,
1622 // command, trcEvent.getTimestamp());
1623 // if (parent_process != null) {
1624 // process.setPpid(parent_process.getPid());
1627 // /* Keep the stack bottom : a running user mode */
1629 // * Disabled because of inconsistencies in the current
1630 // * statedump states.
1632 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1635 // * FIXME Kernel thread : can be in syscall or
1636 // * interrupt or trap.
1639 // * Will cause expected trap when in fact being
1640 // * syscall (even after end of statedump event) Will
1641 // * cause expected interrupt when being syscall.
1642 // * (only before end of statedump event)
1645 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1648 // // es->t = LTTV_STATE_SYSCALL;
1649 // // es->s = status;
1650 // // es->n = submode;
1654 // * User space process : bottom : user mode either
1655 // * currently running or scheduled out. can be
1656 // * scheduled out because interrupted in (user mode
1657 // * or in syscall) or because of an explicit call to
1658 // * the scheduler in syscall. Note that the scheduler
1659 // * call comes after the irq_exit, so never in
1660 // * interrupt context.
1662 // // temp workaround : set size to 1 : only have user
1664 // // bottom of stack.
1665 // // will cause g_info message of expected syscall
1668 // // in user mode. Can also cause expected trap when
1671 // // mode in the event of a page fault reenabling
1673 // // in the handler.
1674 // // Expected syscall and trap can also happen after
1677 // // This will cause a
1678 // // "popping last state on stack, ignoring it."
1680 // // process->execution_stack =
1681 // // g_array_set_size(process->execution_stack, 1);
1682 // // es = process->state =
1683 // // &g_array_index(process->execution_stack,
1684 // // LttvExecutionState, 0);
1685 // // a new process must have only one state in the
1687 // // be the same as the current state
1688 // // es = process.getState();
1689 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1690 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1693 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1694 // // .getInName());
1697 // // es->t = LTTV_STATE_USER_MODE;
1698 // // es->s = status;
1699 // // es->n = submode;
1702 // // TODO: clean up comments above: Moved repeated code
1704 // // if / else blocks above,
1705 // // comments left temporarily for easier visualization
1707 // // comparision with c code
1708 // es = process.getState();
1709 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1710 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1712 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1715 // // /* UNKNOWN STATE */
1717 // // es = process->state =
1718 // // &g_array_index(process->execution_stack,
1719 // // LttvExecutionState, 1);
1720 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1721 // // es->s = LTTV_STATE_UNNAMED;
1722 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1727 // * The process has already been created : Probably was
1728 // * forked while dumping the process state or was simply
1729 // * scheduled in prior to get the state dump event.
1731 // process.setPpid(parent_pid);
1732 // process.setTgid(tgid);
1733 // process.setName(command);
1734 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1737 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1739 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1743 // // &g_array_index(process->execution_stack,
1744 // // LttvExecutionState,
1747 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1748 // // if(type == LTTV_STATE_KERNEL_THREAD)
1749 // // es->t = LTTV_STATE_SYSCALL;
1751 // // es->t = LTTV_STATE_USER_MODE;
1755 // * Don't mess around with the stack, it will eventually
1756 // * become ok after the end of state dump.
1766 public Events
getEventHandleType() {