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
.ExecutionMode
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ILttngEventProcessor
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngExecutionState
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
23 import org
.eclipse
.linuxtools
.lttng
.tests
.state
.handlers
.AbsStateUpdate
;
26 * Process the system call entry event
31 class StateAfterUpdateHandlers
{
33 final ILttngEventProcessor
getSyscallEntryHandler() {
34 AbsStateUpdate handler
= new AbsStateUpdate() {
38 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
39 // TraceDebug.debug("After event called");
41 Long cpu
= trcEvent
.getCpuId();
43 // No syscall_entry update for initialization process
44 LttngProcessState process
= traceSt
.getRunning_process().get(
47 if (pid
!= process
.getPid()) {
49 .debug("pid values don't match from before and after verification check");
52 if (process
.getPid() == 0L) {
56 // Make sure the top of the stack and the state of the stack are
59 LttngExecutionState stackState
= process
.peekFromExecutionStack();
60 if (stackState
!= process
.getState()) {
62 .debug("The top of the stack does not match to the process state");
65 if (stackState
.getExec_mode().getInName() != ExecutionMode
.LTTV_STATE_SYSCALL
67 TraceDebug
.debug("Unexpected ExecutionMode: "
68 + stackState
.getExec_mode().getInName()
70 + ExecutionMode
.LTTV_STATE_SYSCALL
.getInName());
73 if (stackState
.getEntry_LttTime() != trcEvent
.getTimestamp().getValue()) {
74 TraceDebug
.debug("Unexpected Entry time: "
75 + trcEvent
.getTimestamp() + " Expected: "
76 + stackState
.getEntry_LttTime());
85 final ILttngEventProcessor
getsySyscallExitHandler() {
86 AbsStateUpdate handler
= new AbsStateUpdate() {
90 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
92 // TraceDebug.debug("Syscall Exit After event called");
93 Long cpu
= trcEvent
.getCpuId();
94 LttngProcessState process
= traceSt
.getRunning_process().get(
97 /* There can be no system call from PID 0 : unknown state */
98 if (process
.getPid() == 0L) {
101 .debug("Unexpected pid from before and after verfication methods, before pid: "
104 + process
.getPid_time());
110 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
111 // traceSt, trcEvent.getTimestamp());
120 * Update stacks related to the parsing of an LttngEvent
124 final ILttngEventProcessor
getTrapEntryHandler() {
125 AbsStateUpdate handler
= new AbsStateUpdate() {
129 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
130 // Long cpu = trcEvent.getCpuId();
132 // Long trap = getAFieldLong(trcEvent, traceSt,
133 // Fields.LTT_FIELD_TRAP_ID);
134 // if (trap == null) {
138 // String submode = traceSt.getSyscall_names()
141 // if (submode == null) {
142 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
146 // /* update process state */
147 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
148 // submode, trcEvent.getTimestamp(), traceSt);
150 // /* update cpu status */
151 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
152 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
153 // cpust.setLast_trap(trap); /* update trap status */
155 // // update Trap State
156 // LttngTrapState trap_state = traceSt.getTrap_states().get(
158 // trap_state.incrementRunning();
171 final ILttngEventProcessor
getTrapExitHandler() {
172 AbsStateUpdate handler
= new AbsStateUpdate() {
176 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
178 // Long cpu = trcEvent.getCpuId();
179 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
180 // Long trap = cpust.getLast_trap();
182 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
186 // /* update cpu status */
187 // cpu_pop_mode(cpust);
189 // /* update trap status */
190 // if (trap != -1L) {
191 // traceSt.getTrap_states().get(trap).decrementRunning();
204 final ILttngEventProcessor
getIrqEntryHandler() {
205 AbsStateUpdate handler
= new AbsStateUpdate() {
209 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
211 // Long cpu = trcEvent.getCpuId();
213 // Long irq = getAFieldLong(trcEvent, traceSt,
214 // Fields.LTT_FIELD_IRQ_ID);
215 // if (irq == null) {
220 // submode = traceSt.getIrq_names().get(irq);
222 // if (submode == null) {
224 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
228 // * Do something with the info about being in user or system
232 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
234 // .getTimestamp(), traceSt);
236 // /* update cpu state */
237 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
238 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
239 // cpust.setLast_irq(irq); /* last irq */
241 // /* udpate irq state */
242 // irq_push_mode(traceSt.getIrq_states().get(irq),
243 // IRQMode.LTTV_IRQ_BUSY);
255 final ILttngEventProcessor
getSoftIrqExitHandler() {
256 AbsStateUpdate handler
= new AbsStateUpdate() {
260 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
262 // Long cpu = trcEvent.getCpuId();
263 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
264 // Long softirq = cpust.getLast_soft_irq();
265 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
266 // trcEvent.getTimestamp());
268 // /* update softirq status */
269 // if (softirq != -1) {
270 // LttngSoftIRQState softIrqstate = traceSt
271 // .getSoft_irq_states().get(softirq);
272 // softIrqstate.decrementRunning();
275 // /* update cpu status */
276 // cpu_pop_mode(cpust);
288 final ILttngEventProcessor
getIrqExitHandler() {
289 AbsStateUpdate handler
= new AbsStateUpdate() {
293 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
295 // Long cpu = trcEvent.getCpuId();
297 // /* update process state */
298 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
302 // /* update cpu status */
303 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
304 // cpu_pop_mode(cpust);
306 // /* update irq status */
307 // Long last_irq = cpust.getLast_irq();
308 // if (last_irq != -1L) {
309 // LttngIRQState irq_state = traceSt.getIrq_states().get(
311 // irq_pop_mode(irq_state);
325 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
326 AbsStateUpdate handler
= new AbsStateUpdate() {
330 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
332 // // Long cpu = trcEvent.getCpuId();
334 // // get event field
335 // Long softirq = getAFieldLong(trcEvent, traceSt,
336 // Fields.LTT_FIELD_SOFT_IRQ_ID);
338 // if (softirq == null) {
342 // // String submode;
343 // // String[] softIrqNames = traceSt.getSoft_irq_names();
344 // // if (softirq < softIrqNames.length) {
345 // // submode = softIrqNames[softirq];
347 // // submode = "softirq " + softirq;
350 // /* update softirq status */
351 // /* a soft irq raises are not cumulative */
352 // LttngSoftIRQState irqState =
353 // traceSt.getSoft_irq_states().get(
355 // if (irqState != null) {
356 // irqState.setPending(1L);
359 // .debug("unexpected soft irq id value: " + softirq);
373 final ILttngEventProcessor
getSoftIrqEntryHandler() {
374 AbsStateUpdate handler
= new AbsStateUpdate() {
378 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
381 // Long cpu = trcEvent.getCpuId();
383 // // get event field
384 // Long softirq = getAFieldLong(trcEvent, traceSt,
385 // Fields.LTT_FIELD_SOFT_IRQ_ID);
387 // if (softirq == null) {
392 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
393 // String submode = softIrqNames.get(softirq);
394 // if (submode == null) {
395 // submode = "softirq " + softirq;
396 // softIrqNames.put(softirq, submode);
399 // /* update softirq status */
400 // LttngSoftIRQState irqState =
401 // traceSt.getSoft_irq_states().get(
403 // if (irqState != null) {
404 // irqState.decrementPending();
405 // irqState.incrementRunning();
408 // .debug("unexpected soft irq id value: " + softirq);
411 // /* update cpu state */
412 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
413 // cpu_state.setLast_soft_irq(softirq);
414 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
416 // /* update process execution mode state stack */
417 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
418 // trcEvent.getTimestamp(), traceSt);
428 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
432 final ILttngEventProcessor
getEnumInterruptHandler() {
433 AbsStateUpdate handler
= new AbsStateUpdate() {
437 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
438 // String action = getAFieldString(trcEvent, traceSt,
439 // Fields.LTT_FIELD_ACTION);
440 // Long irq = getAFieldLong(trcEvent, traceSt,
441 // Fields.LTT_FIELD_IRQ_ID);
443 // Map<Long, String> irq_names = traceSt.getIrq_names();
445 // irq_names.put(irq, action);
454 * Handle the event LTT_EVENT_REQUEST_ISSUE
458 final ILttngEventProcessor
getBdevRequestIssueHandler() {
459 AbsStateUpdate handler
= new AbsStateUpdate() {
463 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
466 // Long major = getAFieldLong(trcEvent, traceSt,
467 // Fields.LTT_FIELD_MAJOR);
468 // Long minor = getAFieldLong(trcEvent, traceSt,
469 // Fields.LTT_FIELD_MINOR);
470 // Long operation = getAFieldLong(trcEvent, traceSt,
471 // Fields.LTT_FIELD_OPERATION);
473 // // calculate bdevcode
474 // Long devcode = mkdev(major, minor);
476 // if (devcode == null) {
478 // .debug("incorrect calcualtion of bdevcode input( major: "
482 // + " operation: " + operation);
486 // Map<Long, LttngBdevState> bdev_states = traceSt
487 // .getBdev_states();
488 // // Get the instance
489 // LttngBdevState bdevState = bdev_states.get(devcode);
490 // if (bdevState == null) {
491 // bdevState = new LttngBdevState();
494 // // update the mode in the stack
495 // if (operation == 0L) {
496 // bdevState.getMode_stack().push(
497 // BdevMode.LTTV_BDEV_BUSY_READING);
499 // bdevState.getMode_stack().push(
500 // BdevMode.LTTV_BDEV_BUSY_WRITING);
503 // // make sure it is included in the set
504 // bdev_states.put(devcode, bdevState);
514 * Handling event: LTT_EVENT_REQUEST_COMPLETE
517 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
522 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
523 AbsStateUpdate handler
= new AbsStateUpdate() {
527 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
530 // Long major = getAFieldLong(trcEvent, traceSt,
531 // Fields.LTT_FIELD_MAJOR);
532 // Long minor = getAFieldLong(trcEvent, traceSt,
533 // Fields.LTT_FIELD_MINOR);
534 // Long operation = getAFieldLong(trcEvent, traceSt,
535 // Fields.LTT_FIELD_OPERATION);
537 // // calculate bdevcode
538 // Long devcode = mkdev(major, minor);
540 // if (devcode == null) {
542 // .debug("incorrect calcualtion of bdevcode input( major: "
546 // + " operation: " + operation);
550 // Map<Long, LttngBdevState> bdev_states = traceSt
551 // .getBdev_states();
552 // // Get the instance
553 // LttngBdevState bdevState = bdev_states.get(devcode);
554 // if (bdevState == null) {
555 // bdevState = new LttngBdevState();
558 // /* update block device */
559 // bdev_pop_mode(bdevState);
570 * Handles event: LTT_EVENT_FUNCTION_ENTRY
573 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
578 final ILttngEventProcessor
getFunctionEntryHandler() {
579 AbsStateUpdate handler
= new AbsStateUpdate() {
583 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
584 // Long cpu = trcEvent.getCpuId();
585 // Long funcptr = getAFieldLong(trcEvent, traceSt,
586 // Fields.LTT_FIELD_THIS_FN);
588 // push_function(traceSt, funcptr, cpu);
600 final ILttngEventProcessor
getFunctionExitHandler() {
601 AbsStateUpdate handler
= new AbsStateUpdate() {
605 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
607 // Long funcptr = getAFieldLong(trcEvent, traceSt,
608 // Fields.LTT_FIELD_THIS_FN);
610 // pop_function(traceSt, trcEvent, funcptr);
620 * process event: LTT_EVENT_SYS_CALL_TABLE
623 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
628 final ILttngEventProcessor
getDumpSyscallHandler() {
629 AbsStateUpdate handler
= new AbsStateUpdate() {
633 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
634 // // obtain the syscall id
635 // Long id = getAFieldLong(trcEvent, traceSt,
636 // Fields.LTT_FIELD_ID);
638 // // Long address = getAFieldLong(trcEvent, traceSt,
639 // // Fields.LTT_FIELD_ADDRESS);
641 // // Obtain the symbol
642 // String symbol = getAFieldString(trcEvent, traceSt,
643 // Fields.LTT_FIELD_SYMBOL);
645 // // fill the symbol to the sycall_names collection
646 // traceSt.getSyscall_names().put(id, symbol);
656 * Handles event: LTT_EVENT_KPROBE_TABLE
659 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
664 final ILttngEventProcessor
getDumpKprobeHandler() {
665 AbsStateUpdate handler
= new AbsStateUpdate() {
669 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
671 // Long ip = getAFieldLong(trcEvent, traceSt,
672 // Fields.LTT_FIELD_IP);
673 // String symbol = getAFieldString(trcEvent, traceSt,
674 // Fields.LTT_FIELD_SYMBOL);
676 // traceSt.getKprobe_table().put(ip, symbol);
687 * Handles: LTT_EVENT_SOFTIRQ_VEC
690 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
695 final ILttngEventProcessor
getDumpSoftIrqHandler() {
696 AbsStateUpdate handler
= new AbsStateUpdate() {
700 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
703 // Long id = getAFieldLong(trcEvent, traceSt,
704 // Fields.LTT_FIELD_ID);
706 // // Address not needed
707 // // Long address = ltt_event_get_long_unsigned(e,
708 // // lttv_trace_get_hook_field(th,
712 // String symbol = getAFieldString(trcEvent, traceSt,
713 // Fields.LTT_FIELD_SYMBOL);
715 // // Register the soft irq name
716 // traceSt.getSoft_irq_names().put(id, symbol);
726 * Handles: LTT_EVENT_SCHED_SCHEDULE
729 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
734 final ILttngEventProcessor
getSchedChangeHandler() {
735 AbsStateUpdate handler
= new AbsStateUpdate() {
739 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
741 // Long cpu = trcEvent.getCpuId();
742 // TmfTimestamp eventTime = trcEvent.getTimestamp();
744 // LttngProcessState process = traceSt.getRunning_process().get(
747 // Long pid_out = getAFieldLong(trcEvent, traceSt,
748 // Fields.LTT_FIELD_PREV_PID);
749 // Long pid_in = getAFieldLong(trcEvent, traceSt,
750 // Fields.LTT_FIELD_NEXT_PID);
751 // Long state_out = getAFieldLong(trcEvent, traceSt,
752 // Fields.LTT_FIELD_PREV_STATE);
754 // if (process != null) {
757 // * We could not know but it was not the idle process
758 // * executing. This should only happen at the beginning,
759 // * before the first schedule event, and when the initial
760 // * information (current process for each CPU) is missing. It
761 // * is not obvious how we could, after the fact, compensate
762 // * the wrongly attributed statistics.
765 // // This test only makes sense once the state is known and if
768 // // missing events. We need to silently ignore schedchange
771 // // process_free, or it causes glitches. (FIXME)
772 // // if(unlikely(process->pid != pid_out)) {
773 // // g_assert(process->pid == 0);
775 // if (process.getPid() == 0
776 // && process.getState().getExec_mode() ==
777 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
778 // if (pid_out == 0) {
780 // * Scheduling out of pid 0 at beginning of the trace
781 // * : we know for sure it is in syscall mode at this
784 // int stackSize = process.getExecution_stack().size();
785 // if (stackSize != 1) {
787 // .debug("unpexpected process execution stack size, expected 1, received: ");
790 // process.getState().setExec_mode(
791 // ExecutionMode.LTTV_STATE_SYSCALL);
792 // process.getState().setProc_status(
793 // ProcessStatus.LTTV_STATE_WAIT);
794 // process.getState().setChage_Time(
795 // trcEvent.getTimestamp());
796 // process.getState().setEntry_Time(
797 // trcEvent.getTimestamp());
800 // if (process.getState().getProc_status() ==
801 // ProcessStatus.LTTV_STATE_EXIT) {
802 // process.getState().setProc_status(
803 // ProcessStatus.LTTV_STATE_ZOMBIE);
804 // process.getState().setChage_Time(
805 // trcEvent.getTimestamp());
807 // if (state_out == 0L) {
808 // process.getState().setProc_status(
809 // ProcessStatus.LTTV_STATE_WAIT_CPU);
811 // process.getState().setProc_status(
812 // ProcessStatus.LTTV_STATE_WAIT);
815 // process.getState().setChage_Time(
816 // trcEvent.getTimestamp());
819 // if (state_out == 32L || state_out == 64L) { /*
824 // /* see sched.h for states */
825 // if (!exit_process(traceSt, process)) {
826 // process.getState().setProc_status(
827 // ProcessStatus.LTTV_STATE_DEAD);
828 // process.getState().setChage_Time(
829 // trcEvent.getTimestamp());
834 // process = lttv_state_find_process_or_create(traceSt, cpu,
835 // pid_in, eventTime);
837 // traceSt.getRunning_process().put(cpu, process);
839 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
840 // process.getState().setChage_Time(eventTime);
841 // process.setCpu(cpu);
842 // // process->state->s = LTTV_STATE_RUN;
843 // // if(process->usertrace)
844 // // process->usertrace->cpu = cpu;
845 // // process->last_cpu_index =
846 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
848 // // process->state->change = s->parent.timestamp;
850 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
851 // /* update cpu status */
852 // if (pid_in == 0) {
854 // /* going to idle task */
855 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
858 // * scheduling a real task. we must be careful here: if we
859 // * just schedule()'ed to a process that is in a trap, we
860 // * must put the cpu in trap mode
862 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
863 // if (process.getState().getExec_mode() ==
864 // ExecutionMode.LTTV_STATE_TRAP) {
865 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
877 * Handles: LTT_EVENT_PROCESS_FORK
880 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
881 * LTT_FIELD_CHILD_TGID)
886 final ILttngEventProcessor
getProcessForkHandler() {
887 AbsStateUpdate handler
= new AbsStateUpdate() {
891 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
893 // Long cpu = trcEvent.getCpuId();
894 // LttngProcessState process = traceSt.getRunning_process().get(
896 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
898 // // /* Parent PID */
899 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
900 // // Fields.LTT_FIELD_PARENT_PID);
903 // /* In the Linux Kernel, there is one PID per thread. */
904 // Long child_pid = getAFieldLong(trcEvent, traceSt,
905 // Fields.LTT_FIELD_CHILD_PID);
908 // /* tgid in the Linux kernel is the "real" POSIX PID. */
909 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
910 // Fields.LTT_FIELD_CHILD_TGID);
911 // if (child_tgid == null) {
916 // * Mathieu : it seems like the process might have been
918 // * in before the fork, and, in a rare case, might be the
920 // * process. This might happen in a SMP case where we don't
922 // * enough precision on the clocks.
924 // * Test reenabled after precision fixes on time. (Mathieu)
927 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
930 // // if(unlikely(zombie_process != NULL)) {
931 // // /* Reutilisation of PID. Only now we are sure that the old
933 // // * has been released. FIXME : should know when release_task
937 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
939 // // for(i=0; i< num_cpus; i++) {
940 // // g_assert(zombie_process != ts->running_process[i]);
943 // // exit_process(s, zombie_process);
947 // if (process.getPid() == child_pid) {
949 // .debug("Unexpected, process pid equal to child pid: "
952 // + trcEvent.getTimestamp());
955 // // g_assert(process->pid != child_pid);
956 // // FIXME : Add this test in the "known state" section
957 // // g_assert(process->pid == parent_pid);
958 // LttngProcessState child_process = lttv_state_find_process(
959 // traceSt, ANY_CPU, child_pid);
960 // if (child_process == null) {
961 // child_process = create_process(traceSt, cpu, child_pid,
962 // child_tgid, timeStamp);
965 // * The process has already been created : due to time
966 // * imprecision between multiple CPUs : it has been scheduled
967 // * in before creation. Note that we shouldn't have this kind
970 // * Simply put a correct parent.
972 // StringBuilder sb = new StringBuilder("Process " + child_pid);
973 // sb.append(" has been created at ["
974 // + child_process.getCration_time() + "] ");
975 // sb.append("and inserted at ["
976 // + child_process.getInsertion_time() + "] ");
977 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
978 // + trcEvent + "]\n.");
980 // .append("Probably an unsynchronized TSD problem on the traced machine.");
981 // TraceDebug.debug(sb.toString());
983 // // g_assert(0); /* This is a problematic case : the process
986 // // before the fork event */
987 // child_process.setPpid(process.getPid());
988 // child_process.setTgid(child_tgid);
991 // if (!child_process.getName().equals(
992 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
993 // TraceDebug.debug("Unexpected child process status: "
994 // + child_process.getName());
997 // child_process.setName(process.getName());
998 // child_process.setBrand(process.getBrand());
1009 * Handles: LTT_EVENT_KTHREAD_CREATE
1012 * Fields: LTT_FIELD_PID
1017 final ILttngEventProcessor
getProcessKernelThreadHandler() {
1018 AbsStateUpdate handler
= new AbsStateUpdate() {
1022 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1024 // * We stamp a newly created process as kernel_thread. The
1026 // * should not be running yet.
1029 // LttngExecutionState exState;
1031 // LttngProcessState process;
1034 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1035 // // s->parent.target_pid = pid;
1037 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1038 // pid, new TmfTimestamp());
1040 // if (!process.getState().getProc_status().equals(
1041 // ProcessStatus.LTTV_STATE_DEAD)) {
1042 // // Leave only the first element in the stack with execution
1045 // Stack<LttngExecutionState> processExStack = process
1046 // .getExecution_stack();
1047 // exState = processExStack.firstElement();
1048 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1049 // if (processExStack.size() > 1) {
1050 // processExStack.clear();
1051 // processExStack.add(exState);
1054 // // update the process state to the only one in the stack
1055 // process.setState(exState);
1058 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1069 * Handles: LTT_EVENT_PROCESS_EXIT
1077 final ILttngEventProcessor
getProcessExitHandler() {
1078 AbsStateUpdate handler
= new AbsStateUpdate() {
1082 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1085 // LttngProcessState process;
1087 // pid = getAFieldLong(trcEvent, traceSt,
1088 // Fields.LTT_FIELD_PID);
1089 // // s->parent.target_pid = pid;
1091 // // FIXME : Add this test in the "known state" section
1092 // // g_assert(process->pid == pid);
1094 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1095 // if (process != null) {
1096 // process.getState().setProc_status(
1097 // ProcessStatus.LTTV_STATE_EXIT);
1108 * Handles: LTT_EVENT_PROCESS_FREE
1111 * Fields: LTT_FIELD_PID
1116 final ILttngEventProcessor
getProcessFreeHandler() {
1117 AbsStateUpdate handler
= new AbsStateUpdate() {
1121 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1123 // Long release_pid;
1124 // LttngProcessState process;
1126 // /* PID of the process to release */
1127 // release_pid = getAFieldLong(trcEvent, traceSt,
1128 // Fields.LTT_FIELD_PID);
1129 // // s->parent.target_pid = release_pid;
1131 // if (release_pid == 0) {
1132 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1133 // + trcEvent.getTimestamp());
1136 // process = lttv_state_find_process(traceSt, ANY_CPU,
1138 // if (process != null) {
1139 // exit_process(traceSt, process);
1144 // if(process != null) {
1146 * release_task is happening at kernel level : we can now safely
1147 * release the data structure of the process
1149 // This test is fun, though, as it may happen that
1150 // at time t : CPU 0 : process_free
1151 // at time t+150ns : CPU 1 : schedule out
1152 // Clearly due to time imprecision, we disable it. (Mathieu)
1153 // If this weird case happen, we have no choice but to put the
1154 // Currently running process on the cpu to 0.
1155 // I re-enable it following time precision fixes. (Mathieu)
1156 // Well, in the case where an process is freed by a process on
1159 // and still scheduled, it happens that this is the schedchange
1162 // drop the last reference count. Do not free it here!
1164 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1166 // for(i=0; i< num_cpus; i++) {
1167 // //g_assert(process != ts->running_process[i]);
1168 // if(process == ts->running_process[i]) {
1169 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1173 // if(i == num_cpus) /* process is not scheduled */
1174 // exit_process(s, process);
1186 * Handles: LTT_EVENT_EXEC
1189 * FIELDS: LTT_FIELD_FILENAME
1194 final ILttngEventProcessor
getProcessExecHandler() {
1195 AbsStateUpdate handler
= new AbsStateUpdate() {
1199 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1201 // Long cpu = trcEvent.getCpuId();
1202 // LttngProcessState process = traceSt.getRunning_process().get(
1205 // // #if 0//how to use a sequence that must be transformed in a
1207 // // /* PID of the process to release */
1208 // // guint64 name_len = ltt_event_field_element_number(e,
1209 // // lttv_trace_get_hook_field(th, 0));
1210 // // //name = ltt_event_get_string(e,
1211 // // lttv_trace_get_hook_field(th, 0));
1212 // // LttField *child = ltt_event_field_element_select(e,
1213 // // lttv_trace_get_hook_field(th, 0), 0);
1214 // // gchar *name_begin =
1215 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1217 // // gchar *null_term_name = g_new(gchar, name_len+1);
1218 // // memcpy(null_term_name, name_begin, name_len);
1219 // // null_term_name[name_len] = '\0';
1220 // // process->name = g_quark_from_string(null_term_name);
1223 // process.setName(getAFieldString(trcEvent, traceSt,
1224 // Fields.LTT_FIELD_FILENAME));
1225 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1235 * LTT_EVENT_THREAD_BRAND
1238 * FIELDS: LTT_FIELD_NAME
1243 final ILttngEventProcessor
GetThreadBrandHandler() {
1244 AbsStateUpdate handler
= new AbsStateUpdate() {
1248 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1251 // Long cpu = trcEvent.getCpuId();
1252 // LttngProcessState process = traceSt.getRunning_process().get(
1255 // name = getAFieldString(trcEvent, traceSt,
1256 // Fields.LTT_FIELD_NAME);
1257 // process.setBrand(name);
1268 final ILttngEventProcessor
getStateDumpEndHandler() {
1269 AbsStateUpdate handler
= new AbsStateUpdate() {
1273 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1275 // /* For all processes */
1277 // * if kernel thread, if stack[0] is unknown, set to syscall
1280 // /* else, if stack[0] is unknown, set to user mode, running */
1281 // List<LttngProcessState> processes = traceSt.getProcesses();
1282 // TmfTimestamp time = trcEvent.getTimestamp();
1284 // for (LttngProcessState process : processes) {
1285 // fix_process(process, time);
1296 * Private method used to establish the first execution state in the stack
1297 * for a given process
1302 // private void fix_process(LttngProcessState process,
1303 // TmfTimestamp timestamp) {
1305 // LttngExecutionState es;
1306 // Stack<LttngExecutionState> procStack = process
1307 // .getExecution_stack();
1309 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1310 // es = procStack.firstElement();
1312 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1313 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1315 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1317 // es.setEntry_Time(timestamp);
1318 // es.setChage_Time(timestamp);
1319 // es.setCum_cpu_time(0L);
1320 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1321 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1325 // es = procStack.firstElement();
1326 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1327 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1329 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1331 // es.setEntry_Time(timestamp);
1332 // es.setChage_Time(timestamp);
1333 // es.setCum_cpu_time(0L);
1334 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1335 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1338 // if (procStack.size() == 1) {
1340 // * Still in bottom unknown mode, means never did a
1341 // * system call May be either in user mode, syscall
1342 // * mode, running or waiting.
1345 // * FIXME : we may be tagging syscall mode when being
1348 // // Get a new execution State
1349 // es = new LttngExecutionState();
1351 // // initialize values
1352 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1354 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1356 // es.setEntry_Time(timestamp);
1357 // es.setChage_Time(timestamp);
1358 // es.setCum_cpu_time(0L);
1359 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1361 // // Push the new state to the stack
1362 // procStack.push(es);
1373 * Handles: LTT_EVENT_PROCESS_STATE
1376 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1377 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1383 final ILttngEventProcessor
getEnumProcessStateHandler() {
1384 AbsStateUpdate handler
= new AbsStateUpdate() {
1388 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1394 // Long cpu = trcEvent.getCpuId();
1395 // LttngProcessState process = traceSt.getRunning_process().get(
1397 // LttngProcessState parent_process;
1399 // // String mode, submode, status;
1400 // LttngExecutionState es;
1403 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1406 // parent_pid = getAFieldLong(trcEvent, traceSt,
1407 // Fields.LTT_FIELD_PARENT_PID);
1409 // /* Command name */
1410 // command = getAFieldString(trcEvent, traceSt,
1411 // Fields.LTT_FIELD_NAME);
1413 // /* TODO: type field, Values need to be verified */
1415 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1416 // Fields.LTT_FIELD_TYPE);
1417 // if (typeVal == 0L) {
1418 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1420 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1423 // // FIXME: type is rarely used, enum must match possible
1427 // // mode = getAFieldString(trcEvent, traceSt,
1428 // // Fields.LTT_FIELD_MODE);
1431 // // submode = getAFieldString(trcEvent, traceSt,
1432 // // Fields.LTT_FIELD_SUBMODE);
1435 // // status = getAFieldString(trcEvent, traceSt,
1436 // // Fields.LTT_FIELD_STATUS);
1439 // tgid = getAFieldLong(trcEvent, traceSt,
1440 // Fields.LTT_FIELD_TGID);
1441 // if (tgid == null) {
1446 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1447 // process = lttv_state_find_process(traceSt, acpu, pid);
1448 // if (process != null) {
1449 // process.setPpid(parent_pid);
1450 // process.setTgid(tgid);
1451 // process.setName(command);
1453 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1455 // StringBuilder sb = new StringBuilder(
1456 // "Unexpected, null process read from the TraceState list of processes, event time: "
1457 // + trcEvent.getTimestamp());
1458 // TraceDebug.debug(sb.toString());
1463 // * The process might exist if a process was forked while
1464 // * performing the state dump.
1466 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1467 // if (process == null) {
1468 // parent_process = lttv_state_find_process(traceSt,
1469 // ANY_CPU, parent_pid);
1470 // process = create_process(traceSt, cpu, pid, tgid,
1471 // command, trcEvent.getTimestamp());
1472 // if (parent_process != null) {
1473 // process.setPpid(parent_process.getPid());
1476 // /* Keep the stack bottom : a running user mode */
1478 // * Disabled because of inconsistencies in the current
1479 // * statedump states.
1481 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1484 // * FIXME Kernel thread : can be in syscall or
1485 // * interrupt or trap.
1488 // * Will cause expected trap when in fact being
1489 // * syscall (even after end of statedump event) Will
1490 // * cause expected interrupt when being syscall.
1491 // * (only before end of statedump event)
1494 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1497 // // es->t = LTTV_STATE_SYSCALL;
1498 // // es->s = status;
1499 // // es->n = submode;
1503 // * User space process : bottom : user mode either
1504 // * currently running or scheduled out. can be
1505 // * scheduled out because interrupted in (user mode
1506 // * or in syscall) or because of an explicit call to
1507 // * the scheduler in syscall. Note that the scheduler
1508 // * call comes after the irq_exit, so never in
1509 // * interrupt context.
1511 // // temp workaround : set size to 1 : only have user
1513 // // bottom of stack.
1514 // // will cause g_info message of expected syscall
1517 // // in user mode. Can also cause expected trap when
1520 // // mode in the event of a page fault reenabling
1522 // // in the handler.
1523 // // Expected syscall and trap can also happen after
1526 // // This will cause a
1527 // // "popping last state on stack, ignoring it."
1529 // // process->execution_stack =
1530 // // g_array_set_size(process->execution_stack, 1);
1531 // // es = process->state =
1532 // // &g_array_index(process->execution_stack,
1533 // // LttvExecutionState, 0);
1534 // // a new process must have only one state in the
1536 // // be the same as the current state
1537 // // es = process.getState();
1538 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1539 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1542 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1543 // // .getInName());
1546 // // es->t = LTTV_STATE_USER_MODE;
1547 // // es->s = status;
1548 // // es->n = submode;
1551 // // TODO: clean up comments above: Moved repeated code
1553 // // if / else blocks above,
1554 // // comments left temporarily for easier visualization
1556 // // comparision with c code
1557 // es = process.getState();
1558 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1559 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1561 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1564 // // /* UNKNOWN STATE */
1566 // // es = process->state =
1567 // // &g_array_index(process->execution_stack,
1568 // // LttvExecutionState, 1);
1569 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1570 // // es->s = LTTV_STATE_UNNAMED;
1571 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1576 // * The process has already been created : Probably was
1577 // * forked while dumping the process state or was simply
1578 // * scheduled in prior to get the state dump event.
1580 // process.setPpid(parent_pid);
1581 // process.setTgid(tgid);
1582 // process.setName(command);
1583 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1586 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1588 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1592 // // &g_array_index(process->execution_stack,
1593 // // LttvExecutionState,
1596 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1597 // // if(type == LTTV_STATE_KERNEL_THREAD)
1598 // // es->t = LTTV_STATE_SYSCALL;
1600 // // es->t = LTTV_STATE_USER_MODE;
1604 // * Don't mess around with the stack, it will eventually
1605 // * become ok after the end of state dump.