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() {
37 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
38 // TraceDebug.debug("After event called");
40 Long cpu
= trcEvent
.getCpuId();
42 // No syscall_entry update for initialization process
43 LttngProcessState process
= traceSt
.getRunning_process().get(
46 if (pid
!= process
.getPid()) {
48 .debug("pid values don't match from before and after verification check");
51 if (process
.getPid() == 0L) {
55 // Make sure the top of the stack and the state of the stack are
58 LttngExecutionState stackState
= process
.peekFromExecutionStack();
59 if (stackState
!= process
.getState()) {
61 .debug("The top of the stack does not match to the process state");
64 if (stackState
.getExec_mode().getInName() != ExecutionMode
.LTTV_STATE_SYSCALL
66 TraceDebug
.debug("Unexpected ExecutionMode: "
67 + stackState
.getExec_mode().getInName()
69 + ExecutionMode
.LTTV_STATE_SYSCALL
.getInName());
72 if (stackState
.getEntry_LttTime() != trcEvent
.getTimestamp().getValue()) {
73 TraceDebug
.debug("Unexpected Entry time: "
74 + trcEvent
.getTimestamp() + " Expected: "
75 + stackState
.getEntry_LttTime());
84 final ILttngEventProcessor
getsySyscallExitHandler() {
85 AbsStateUpdate handler
= new AbsStateUpdate() {
88 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
90 // TraceDebug.debug("Syscall Exit After event called");
91 Long cpu
= trcEvent
.getCpuId();
92 LttngProcessState process
= traceSt
.getRunning_process().get(
95 /* There can be no system call from PID 0 : unknown state */
96 if (process
.getPid() == 0L) {
99 .debug("Unexpected pid from before and after verfication methods, before pid: "
102 + process
.getPid_time());
108 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
109 // traceSt, trcEvent.getTimestamp());
118 * Update stacks related to the parsing of an LttngEvent
122 final ILttngEventProcessor
getTrapEntryHandler() {
123 AbsStateUpdate handler
= new AbsStateUpdate() {
126 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
127 // Long cpu = trcEvent.getCpuId();
129 // Long trap = getAFieldLong(trcEvent, traceSt,
130 // Fields.LTT_FIELD_TRAP_ID);
131 // if (trap == null) {
135 // String submode = traceSt.getSyscall_names()
138 // if (submode == null) {
139 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
143 // /* update process state */
144 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
145 // submode, trcEvent.getTimestamp(), traceSt);
147 // /* update cpu status */
148 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
149 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
150 // cpust.setLast_trap(trap); /* update trap status */
152 // // update Trap State
153 // LttngTrapState trap_state = traceSt.getTrap_states().get(
155 // trap_state.incrementRunning();
168 final ILttngEventProcessor
getTrapExitHandler() {
169 AbsStateUpdate handler
= new AbsStateUpdate() {
172 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
174 // Long cpu = trcEvent.getCpuId();
175 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
176 // Long trap = cpust.getLast_trap();
178 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
182 // /* update cpu status */
183 // cpu_pop_mode(cpust);
185 // /* update trap status */
186 // if (trap != -1L) {
187 // traceSt.getTrap_states().get(trap).decrementRunning();
200 final ILttngEventProcessor
getIrqEntryHandler() {
201 AbsStateUpdate handler
= new AbsStateUpdate() {
204 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
206 // Long cpu = trcEvent.getCpuId();
208 // Long irq = getAFieldLong(trcEvent, traceSt,
209 // Fields.LTT_FIELD_IRQ_ID);
210 // if (irq == null) {
215 // submode = traceSt.getIrq_names().get(irq);
217 // if (submode == null) {
219 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
223 // * Do something with the info about being in user or system
227 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
229 // .getTimestamp(), traceSt);
231 // /* update cpu state */
232 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
233 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
234 // cpust.setLast_irq(irq); /* last irq */
236 // /* udpate irq state */
237 // irq_push_mode(traceSt.getIrq_states().get(irq),
238 // IRQMode.LTTV_IRQ_BUSY);
250 final ILttngEventProcessor
getSoftIrqExitHandler() {
251 AbsStateUpdate handler
= new AbsStateUpdate() {
254 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
256 // Long cpu = trcEvent.getCpuId();
257 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
258 // Long softirq = cpust.getLast_soft_irq();
259 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
260 // trcEvent.getTimestamp());
262 // /* update softirq status */
263 // if (softirq != -1) {
264 // LttngSoftIRQState softIrqstate = traceSt
265 // .getSoft_irq_states().get(softirq);
266 // softIrqstate.decrementRunning();
269 // /* update cpu status */
270 // cpu_pop_mode(cpust);
282 final ILttngEventProcessor
getIrqExitHandler() {
283 AbsStateUpdate handler
= new AbsStateUpdate() {
286 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
288 // Long cpu = trcEvent.getCpuId();
290 // /* update process state */
291 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
295 // /* update cpu status */
296 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
297 // cpu_pop_mode(cpust);
299 // /* update irq status */
300 // Long last_irq = cpust.getLast_irq();
301 // if (last_irq != -1L) {
302 // LttngIRQState irq_state = traceSt.getIrq_states().get(
304 // irq_pop_mode(irq_state);
318 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
319 AbsStateUpdate handler
= new AbsStateUpdate() {
322 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
324 // // Long cpu = trcEvent.getCpuId();
326 // // get event field
327 // Long softirq = getAFieldLong(trcEvent, traceSt,
328 // Fields.LTT_FIELD_SOFT_IRQ_ID);
330 // if (softirq == null) {
334 // // String submode;
335 // // String[] softIrqNames = traceSt.getSoft_irq_names();
336 // // if (softirq < softIrqNames.length) {
337 // // submode = softIrqNames[softirq];
339 // // submode = "softirq " + softirq;
342 // /* update softirq status */
343 // /* a soft irq raises are not cumulative */
344 // LttngSoftIRQState irqState =
345 // traceSt.getSoft_irq_states().get(
347 // if (irqState != null) {
348 // irqState.setPending(1L);
351 // .debug("unexpected soft irq id value: " + softirq);
365 final ILttngEventProcessor
getSoftIrqEntryHandler() {
366 AbsStateUpdate handler
= new AbsStateUpdate() {
369 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
372 // Long cpu = trcEvent.getCpuId();
374 // // get event field
375 // Long softirq = getAFieldLong(trcEvent, traceSt,
376 // Fields.LTT_FIELD_SOFT_IRQ_ID);
378 // if (softirq == null) {
383 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
384 // String submode = softIrqNames.get(softirq);
385 // if (submode == null) {
386 // submode = "softirq " + softirq;
387 // softIrqNames.put(softirq, submode);
390 // /* update softirq status */
391 // LttngSoftIRQState irqState =
392 // traceSt.getSoft_irq_states().get(
394 // if (irqState != null) {
395 // irqState.decrementPending();
396 // irqState.incrementRunning();
399 // .debug("unexpected soft irq id value: " + softirq);
402 // /* update cpu state */
403 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
404 // cpu_state.setLast_soft_irq(softirq);
405 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
407 // /* update process execution mode state stack */
408 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
409 // trcEvent.getTimestamp(), traceSt);
419 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
423 final ILttngEventProcessor
getEnumInterruptHandler() {
424 AbsStateUpdate handler
= new AbsStateUpdate() {
427 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
428 // String action = getAFieldString(trcEvent, traceSt,
429 // Fields.LTT_FIELD_ACTION);
430 // Long irq = getAFieldLong(trcEvent, traceSt,
431 // Fields.LTT_FIELD_IRQ_ID);
433 // Map<Long, String> irq_names = traceSt.getIrq_names();
435 // irq_names.put(irq, action);
444 * Handle the event LTT_EVENT_REQUEST_ISSUE
448 final ILttngEventProcessor
getBdevRequestIssueHandler() {
449 AbsStateUpdate handler
= new AbsStateUpdate() {
452 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
455 // Long major = getAFieldLong(trcEvent, traceSt,
456 // Fields.LTT_FIELD_MAJOR);
457 // Long minor = getAFieldLong(trcEvent, traceSt,
458 // Fields.LTT_FIELD_MINOR);
459 // Long operation = getAFieldLong(trcEvent, traceSt,
460 // Fields.LTT_FIELD_OPERATION);
462 // // calculate bdevcode
463 // Long devcode = mkdev(major, minor);
465 // if (devcode == null) {
467 // .debug("incorrect calcualtion of bdevcode input( major: "
471 // + " operation: " + operation);
475 // Map<Long, LttngBdevState> bdev_states = traceSt
476 // .getBdev_states();
477 // // Get the instance
478 // LttngBdevState bdevState = bdev_states.get(devcode);
479 // if (bdevState == null) {
480 // bdevState = new LttngBdevState();
483 // // update the mode in the stack
484 // if (operation == 0L) {
485 // bdevState.getMode_stack().push(
486 // BdevMode.LTTV_BDEV_BUSY_READING);
488 // bdevState.getMode_stack().push(
489 // BdevMode.LTTV_BDEV_BUSY_WRITING);
492 // // make sure it is included in the set
493 // bdev_states.put(devcode, bdevState);
503 * Handling event: LTT_EVENT_REQUEST_COMPLETE
506 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
511 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
512 AbsStateUpdate handler
= new AbsStateUpdate() {
515 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
518 // Long major = getAFieldLong(trcEvent, traceSt,
519 // Fields.LTT_FIELD_MAJOR);
520 // Long minor = getAFieldLong(trcEvent, traceSt,
521 // Fields.LTT_FIELD_MINOR);
522 // Long operation = getAFieldLong(trcEvent, traceSt,
523 // Fields.LTT_FIELD_OPERATION);
525 // // calculate bdevcode
526 // Long devcode = mkdev(major, minor);
528 // if (devcode == null) {
530 // .debug("incorrect calcualtion of bdevcode input( major: "
534 // + " operation: " + operation);
538 // Map<Long, LttngBdevState> bdev_states = traceSt
539 // .getBdev_states();
540 // // Get the instance
541 // LttngBdevState bdevState = bdev_states.get(devcode);
542 // if (bdevState == null) {
543 // bdevState = new LttngBdevState();
546 // /* update block device */
547 // bdev_pop_mode(bdevState);
558 * Handles event: LTT_EVENT_FUNCTION_ENTRY
561 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
566 final ILttngEventProcessor
getFunctionEntryHandler() {
567 AbsStateUpdate handler
= new AbsStateUpdate() {
570 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
571 // Long cpu = trcEvent.getCpuId();
572 // Long funcptr = getAFieldLong(trcEvent, traceSt,
573 // Fields.LTT_FIELD_THIS_FN);
575 // push_function(traceSt, funcptr, cpu);
587 final ILttngEventProcessor
getFunctionExitHandler() {
588 AbsStateUpdate handler
= new AbsStateUpdate() {
591 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
593 // Long funcptr = getAFieldLong(trcEvent, traceSt,
594 // Fields.LTT_FIELD_THIS_FN);
596 // pop_function(traceSt, trcEvent, funcptr);
606 * process event: LTT_EVENT_SYS_CALL_TABLE
609 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
614 final ILttngEventProcessor
getDumpSyscallHandler() {
615 AbsStateUpdate handler
= new AbsStateUpdate() {
618 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
619 // // obtain the syscall id
620 // Long id = getAFieldLong(trcEvent, traceSt,
621 // Fields.LTT_FIELD_ID);
623 // // Long address = getAFieldLong(trcEvent, traceSt,
624 // // Fields.LTT_FIELD_ADDRESS);
626 // // Obtain the symbol
627 // String symbol = getAFieldString(trcEvent, traceSt,
628 // Fields.LTT_FIELD_SYMBOL);
630 // // fill the symbol to the sycall_names collection
631 // traceSt.getSyscall_names().put(id, symbol);
641 * Handles event: LTT_EVENT_KPROBE_TABLE
644 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
649 final ILttngEventProcessor
getDumpKprobeHandler() {
650 AbsStateUpdate handler
= new AbsStateUpdate() {
653 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
655 // Long ip = getAFieldLong(trcEvent, traceSt,
656 // Fields.LTT_FIELD_IP);
657 // String symbol = getAFieldString(trcEvent, traceSt,
658 // Fields.LTT_FIELD_SYMBOL);
660 // traceSt.getKprobe_table().put(ip, symbol);
671 * Handles: LTT_EVENT_SOFTIRQ_VEC
674 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
679 final ILttngEventProcessor
getDumpSoftIrqHandler() {
680 AbsStateUpdate handler
= new AbsStateUpdate() {
683 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
686 // Long id = getAFieldLong(trcEvent, traceSt,
687 // Fields.LTT_FIELD_ID);
689 // // Address not needed
690 // // Long address = ltt_event_get_long_unsigned(e,
691 // // lttv_trace_get_hook_field(th,
695 // String symbol = getAFieldString(trcEvent, traceSt,
696 // Fields.LTT_FIELD_SYMBOL);
698 // // Register the soft irq name
699 // traceSt.getSoft_irq_names().put(id, symbol);
709 * Handles: LTT_EVENT_SCHED_SCHEDULE
712 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
717 final ILttngEventProcessor
getSchedChangeHandler() {
718 AbsStateUpdate handler
= new AbsStateUpdate() {
721 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
723 // Long cpu = trcEvent.getCpuId();
724 // TmfTimestamp eventTime = trcEvent.getTimestamp();
726 // LttngProcessState process = traceSt.getRunning_process().get(
729 // Long pid_out = getAFieldLong(trcEvent, traceSt,
730 // Fields.LTT_FIELD_PREV_PID);
731 // Long pid_in = getAFieldLong(trcEvent, traceSt,
732 // Fields.LTT_FIELD_NEXT_PID);
733 // Long state_out = getAFieldLong(trcEvent, traceSt,
734 // Fields.LTT_FIELD_PREV_STATE);
736 // if (process != null) {
739 // * We could not know but it was not the idle process
740 // * executing. This should only happen at the beginning,
741 // * before the first schedule event, and when the initial
742 // * information (current process for each CPU) is missing. It
743 // * is not obvious how we could, after the fact, compensate
744 // * the wrongly attributed statistics.
747 // // This test only makes sense once the state is known and if
750 // // missing events. We need to silently ignore schedchange
753 // // process_free, or it causes glitches. (FIXME)
754 // // if(unlikely(process->pid != pid_out)) {
755 // // g_assert(process->pid == 0);
757 // if (process.getPid() == 0
758 // && process.getState().getExec_mode() ==
759 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
760 // if (pid_out == 0) {
762 // * Scheduling out of pid 0 at beginning of the trace
763 // * : we know for sure it is in syscall mode at this
766 // int stackSize = process.getExecution_stack().size();
767 // if (stackSize != 1) {
769 // .debug("unpexpected process execution stack size, expected 1, received: ");
772 // process.getState().setExec_mode(
773 // ExecutionMode.LTTV_STATE_SYSCALL);
774 // process.getState().setProc_status(
775 // ProcessStatus.LTTV_STATE_WAIT);
776 // process.getState().setChage_Time(
777 // trcEvent.getTimestamp());
778 // process.getState().setEntry_Time(
779 // trcEvent.getTimestamp());
782 // if (process.getState().getProc_status() ==
783 // ProcessStatus.LTTV_STATE_EXIT) {
784 // process.getState().setProc_status(
785 // ProcessStatus.LTTV_STATE_ZOMBIE);
786 // process.getState().setChage_Time(
787 // trcEvent.getTimestamp());
789 // if (state_out == 0L) {
790 // process.getState().setProc_status(
791 // ProcessStatus.LTTV_STATE_WAIT_CPU);
793 // process.getState().setProc_status(
794 // ProcessStatus.LTTV_STATE_WAIT);
797 // process.getState().setChage_Time(
798 // trcEvent.getTimestamp());
801 // if (state_out == 32L || state_out == 64L) { /*
806 // /* see sched.h for states */
807 // if (!exit_process(traceSt, process)) {
808 // process.getState().setProc_status(
809 // ProcessStatus.LTTV_STATE_DEAD);
810 // process.getState().setChage_Time(
811 // trcEvent.getTimestamp());
816 // process = lttv_state_find_process_or_create(traceSt, cpu,
817 // pid_in, eventTime);
819 // traceSt.getRunning_process().put(cpu, process);
821 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
822 // process.getState().setChage_Time(eventTime);
823 // process.setCpu(cpu);
824 // // process->state->s = LTTV_STATE_RUN;
825 // // if(process->usertrace)
826 // // process->usertrace->cpu = cpu;
827 // // process->last_cpu_index =
828 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
830 // // process->state->change = s->parent.timestamp;
832 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
833 // /* update cpu status */
834 // if (pid_in == 0) {
836 // /* going to idle task */
837 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
840 // * scheduling a real task. we must be careful here: if we
841 // * just schedule()'ed to a process that is in a trap, we
842 // * must put the cpu in trap mode
844 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
845 // if (process.getState().getExec_mode() ==
846 // ExecutionMode.LTTV_STATE_TRAP) {
847 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
859 * Handles: LTT_EVENT_PROCESS_FORK
862 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
863 * LTT_FIELD_CHILD_TGID)
868 final ILttngEventProcessor
getProcessForkHandler() {
869 AbsStateUpdate handler
= new AbsStateUpdate() {
872 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
874 // Long cpu = trcEvent.getCpuId();
875 // LttngProcessState process = traceSt.getRunning_process().get(
877 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
879 // // /* Parent PID */
880 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
881 // // Fields.LTT_FIELD_PARENT_PID);
884 // /* In the Linux Kernel, there is one PID per thread. */
885 // Long child_pid = getAFieldLong(trcEvent, traceSt,
886 // Fields.LTT_FIELD_CHILD_PID);
889 // /* tgid in the Linux kernel is the "real" POSIX PID. */
890 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
891 // Fields.LTT_FIELD_CHILD_TGID);
892 // if (child_tgid == null) {
897 // * Mathieu : it seems like the process might have been
899 // * in before the fork, and, in a rare case, might be the
901 // * process. This might happen in a SMP case where we don't
903 // * enough precision on the clocks.
905 // * Test reenabled after precision fixes on time. (Mathieu)
908 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
911 // // if(unlikely(zombie_process != NULL)) {
912 // // /* Reutilisation of PID. Only now we are sure that the old
914 // // * has been released. FIXME : should know when release_task
918 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
920 // // for(i=0; i< num_cpus; i++) {
921 // // g_assert(zombie_process != ts->running_process[i]);
924 // // exit_process(s, zombie_process);
928 // if (process.getPid() == child_pid) {
930 // .debug("Unexpected, process pid equal to child pid: "
933 // + trcEvent.getTimestamp());
936 // // g_assert(process->pid != child_pid);
937 // // FIXME : Add this test in the "known state" section
938 // // g_assert(process->pid == parent_pid);
939 // LttngProcessState child_process = lttv_state_find_process(
940 // traceSt, ANY_CPU, child_pid);
941 // if (child_process == null) {
942 // child_process = create_process(traceSt, cpu, child_pid,
943 // child_tgid, timeStamp);
946 // * The process has already been created : due to time
947 // * imprecision between multiple CPUs : it has been scheduled
948 // * in before creation. Note that we shouldn't have this kind
951 // * Simply put a correct parent.
953 // StringBuilder sb = new StringBuilder("Process " + child_pid);
954 // sb.append(" has been created at ["
955 // + child_process.getCration_time() + "] ");
956 // sb.append("and inserted at ["
957 // + child_process.getInsertion_time() + "] ");
958 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
959 // + trcEvent + "]\n.");
961 // .append("Probably an unsynchronized TSD problem on the traced machine.");
962 // TraceDebug.debug(sb.toString());
964 // // g_assert(0); /* This is a problematic case : the process
967 // // before the fork event */
968 // child_process.setPpid(process.getPid());
969 // child_process.setTgid(child_tgid);
972 // if (!child_process.getName().equals(
973 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
974 // TraceDebug.debug("Unexpected child process status: "
975 // + child_process.getName());
978 // child_process.setName(process.getName());
979 // child_process.setBrand(process.getBrand());
990 * Handles: LTT_EVENT_KTHREAD_CREATE
993 * Fields: LTT_FIELD_PID
998 final ILttngEventProcessor
getProcessKernelThreadHandler() {
999 AbsStateUpdate handler
= new AbsStateUpdate() {
1002 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1004 // * We stamp a newly created process as kernel_thread. The
1006 // * should not be running yet.
1009 // LttngExecutionState exState;
1011 // LttngProcessState process;
1014 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1015 // // s->parent.target_pid = pid;
1017 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1018 // pid, new TmfTimestamp());
1020 // if (!process.getState().getProc_status().equals(
1021 // ProcessStatus.LTTV_STATE_DEAD)) {
1022 // // Leave only the first element in the stack with execution
1025 // Stack<LttngExecutionState> processExStack = process
1026 // .getExecution_stack();
1027 // exState = processExStack.firstElement();
1028 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1029 // if (processExStack.size() > 1) {
1030 // processExStack.clear();
1031 // processExStack.add(exState);
1034 // // update the process state to the only one in the stack
1035 // process.setState(exState);
1038 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1049 * Handles: LTT_EVENT_PROCESS_EXIT
1057 final ILttngEventProcessor
getProcessExitHandler() {
1058 AbsStateUpdate handler
= new AbsStateUpdate() {
1061 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1064 // LttngProcessState process;
1066 // pid = getAFieldLong(trcEvent, traceSt,
1067 // Fields.LTT_FIELD_PID);
1068 // // s->parent.target_pid = pid;
1070 // // FIXME : Add this test in the "known state" section
1071 // // g_assert(process->pid == pid);
1073 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1074 // if (process != null) {
1075 // process.getState().setProc_status(
1076 // ProcessStatus.LTTV_STATE_EXIT);
1087 * Handles: LTT_EVENT_PROCESS_FREE
1090 * Fields: LTT_FIELD_PID
1095 final ILttngEventProcessor
getProcessFreeHandler() {
1096 AbsStateUpdate handler
= new AbsStateUpdate() {
1099 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1101 // Long release_pid;
1102 // LttngProcessState process;
1104 // /* PID of the process to release */
1105 // release_pid = getAFieldLong(trcEvent, traceSt,
1106 // Fields.LTT_FIELD_PID);
1107 // // s->parent.target_pid = release_pid;
1109 // if (release_pid == 0) {
1110 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1111 // + trcEvent.getTimestamp());
1114 // process = lttv_state_find_process(traceSt, ANY_CPU,
1116 // if (process != null) {
1117 // exit_process(traceSt, process);
1122 // if(process != null) {
1124 * release_task is happening at kernel level : we can now safely
1125 * release the data structure of the process
1127 // This test is fun, though, as it may happen that
1128 // at time t : CPU 0 : process_free
1129 // at time t+150ns : CPU 1 : schedule out
1130 // Clearly due to time imprecision, we disable it. (Mathieu)
1131 // If this weird case happen, we have no choice but to put the
1132 // Currently running process on the cpu to 0.
1133 // I re-enable it following time precision fixes. (Mathieu)
1134 // Well, in the case where an process is freed by a process on
1137 // and still scheduled, it happens that this is the schedchange
1140 // drop the last reference count. Do not free it here!
1142 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1144 // for(i=0; i< num_cpus; i++) {
1145 // //g_assert(process != ts->running_process[i]);
1146 // if(process == ts->running_process[i]) {
1147 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1151 // if(i == num_cpus) /* process is not scheduled */
1152 // exit_process(s, process);
1164 * Handles: LTT_EVENT_EXEC
1167 * FIELDS: LTT_FIELD_FILENAME
1172 final ILttngEventProcessor
getProcessExecHandler() {
1173 AbsStateUpdate handler
= new AbsStateUpdate() {
1176 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1178 // Long cpu = trcEvent.getCpuId();
1179 // LttngProcessState process = traceSt.getRunning_process().get(
1182 // // #if 0//how to use a sequence that must be transformed in a
1184 // // /* PID of the process to release */
1185 // // guint64 name_len = ltt_event_field_element_number(e,
1186 // // lttv_trace_get_hook_field(th, 0));
1187 // // //name = ltt_event_get_string(e,
1188 // // lttv_trace_get_hook_field(th, 0));
1189 // // LttField *child = ltt_event_field_element_select(e,
1190 // // lttv_trace_get_hook_field(th, 0), 0);
1191 // // gchar *name_begin =
1192 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1194 // // gchar *null_term_name = g_new(gchar, name_len+1);
1195 // // memcpy(null_term_name, name_begin, name_len);
1196 // // null_term_name[name_len] = '\0';
1197 // // process->name = g_quark_from_string(null_term_name);
1200 // process.setName(getAFieldString(trcEvent, traceSt,
1201 // Fields.LTT_FIELD_FILENAME));
1202 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1212 * LTT_EVENT_THREAD_BRAND
1215 * FIELDS: LTT_FIELD_NAME
1220 final ILttngEventProcessor
GetThreadBrandHandler() {
1221 AbsStateUpdate handler
= new AbsStateUpdate() {
1224 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1227 // Long cpu = trcEvent.getCpuId();
1228 // LttngProcessState process = traceSt.getRunning_process().get(
1231 // name = getAFieldString(trcEvent, traceSt,
1232 // Fields.LTT_FIELD_NAME);
1233 // process.setBrand(name);
1244 final ILttngEventProcessor
getStateDumpEndHandler() {
1245 AbsStateUpdate handler
= new AbsStateUpdate() {
1248 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1250 // /* For all processes */
1252 // * if kernel thread, if stack[0] is unknown, set to syscall
1255 // /* else, if stack[0] is unknown, set to user mode, running */
1256 // List<LttngProcessState> processes = traceSt.getProcesses();
1257 // TmfTimestamp time = trcEvent.getTimestamp();
1259 // for (LttngProcessState process : processes) {
1260 // fix_process(process, time);
1271 * Private method used to establish the first execution state in the stack
1272 * for a given process
1277 // private void fix_process(LttngProcessState process,
1278 // TmfTimestamp timestamp) {
1280 // LttngExecutionState es;
1281 // Stack<LttngExecutionState> procStack = process
1282 // .getExecution_stack();
1284 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1285 // es = procStack.firstElement();
1287 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1288 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1290 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1292 // es.setEntry_Time(timestamp);
1293 // es.setChage_Time(timestamp);
1294 // es.setCum_cpu_time(0L);
1295 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1296 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1300 // es = procStack.firstElement();
1301 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1302 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1304 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1306 // es.setEntry_Time(timestamp);
1307 // es.setChage_Time(timestamp);
1308 // es.setCum_cpu_time(0L);
1309 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1310 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1313 // if (procStack.size() == 1) {
1315 // * Still in bottom unknown mode, means never did a
1316 // * system call May be either in user mode, syscall
1317 // * mode, running or waiting.
1320 // * FIXME : we may be tagging syscall mode when being
1323 // // Get a new execution State
1324 // es = new LttngExecutionState();
1326 // // initialize values
1327 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
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 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1336 // // Push the new state to the stack
1337 // procStack.push(es);
1348 * Handles: LTT_EVENT_PROCESS_STATE
1351 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1352 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1358 final ILttngEventProcessor
getEnumProcessStateHandler() {
1359 AbsStateUpdate handler
= new AbsStateUpdate() {
1362 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1368 // Long cpu = trcEvent.getCpuId();
1369 // LttngProcessState process = traceSt.getRunning_process().get(
1371 // LttngProcessState parent_process;
1373 // // String mode, submode, status;
1374 // LttngExecutionState es;
1377 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1380 // parent_pid = getAFieldLong(trcEvent, traceSt,
1381 // Fields.LTT_FIELD_PARENT_PID);
1383 // /* Command name */
1384 // command = getAFieldString(trcEvent, traceSt,
1385 // Fields.LTT_FIELD_NAME);
1387 // /* TODO: type field, Values need to be verified */
1389 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1390 // Fields.LTT_FIELD_TYPE);
1391 // if (typeVal == 0L) {
1392 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1394 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1397 // // FIXME: type is rarely used, enum must match possible
1401 // // mode = getAFieldString(trcEvent, traceSt,
1402 // // Fields.LTT_FIELD_MODE);
1405 // // submode = getAFieldString(trcEvent, traceSt,
1406 // // Fields.LTT_FIELD_SUBMODE);
1409 // // status = getAFieldString(trcEvent, traceSt,
1410 // // Fields.LTT_FIELD_STATUS);
1413 // tgid = getAFieldLong(trcEvent, traceSt,
1414 // Fields.LTT_FIELD_TGID);
1415 // if (tgid == null) {
1420 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1421 // process = lttv_state_find_process(traceSt, acpu, pid);
1422 // if (process != null) {
1423 // process.setPpid(parent_pid);
1424 // process.setTgid(tgid);
1425 // process.setName(command);
1427 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1429 // StringBuilder sb = new StringBuilder(
1430 // "Unexpected, null process read from the TraceState list of processes, event time: "
1431 // + trcEvent.getTimestamp());
1432 // TraceDebug.debug(sb.toString());
1437 // * The process might exist if a process was forked while
1438 // * performing the state dump.
1440 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1441 // if (process == null) {
1442 // parent_process = lttv_state_find_process(traceSt,
1443 // ANY_CPU, parent_pid);
1444 // process = create_process(traceSt, cpu, pid, tgid,
1445 // command, trcEvent.getTimestamp());
1446 // if (parent_process != null) {
1447 // process.setPpid(parent_process.getPid());
1450 // /* Keep the stack bottom : a running user mode */
1452 // * Disabled because of inconsistencies in the current
1453 // * statedump states.
1455 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1458 // * FIXME Kernel thread : can be in syscall or
1459 // * interrupt or trap.
1462 // * Will cause expected trap when in fact being
1463 // * syscall (even after end of statedump event) Will
1464 // * cause expected interrupt when being syscall.
1465 // * (only before end of statedump event)
1468 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1471 // // es->t = LTTV_STATE_SYSCALL;
1472 // // es->s = status;
1473 // // es->n = submode;
1477 // * User space process : bottom : user mode either
1478 // * currently running or scheduled out. can be
1479 // * scheduled out because interrupted in (user mode
1480 // * or in syscall) or because of an explicit call to
1481 // * the scheduler in syscall. Note that the scheduler
1482 // * call comes after the irq_exit, so never in
1483 // * interrupt context.
1485 // // temp workaround : set size to 1 : only have user
1487 // // bottom of stack.
1488 // // will cause g_info message of expected syscall
1491 // // in user mode. Can also cause expected trap when
1494 // // mode in the event of a page fault reenabling
1496 // // in the handler.
1497 // // Expected syscall and trap can also happen after
1500 // // This will cause a
1501 // // "popping last state on stack, ignoring it."
1503 // // process->execution_stack =
1504 // // g_array_set_size(process->execution_stack, 1);
1505 // // es = process->state =
1506 // // &g_array_index(process->execution_stack,
1507 // // LttvExecutionState, 0);
1508 // // a new process must have only one state in the
1510 // // be the same as the current state
1511 // // es = process.getState();
1512 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1513 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1516 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1517 // // .getInName());
1520 // // es->t = LTTV_STATE_USER_MODE;
1521 // // es->s = status;
1522 // // es->n = submode;
1525 // // TODO: clean up comments above: Moved repeated code
1527 // // if / else blocks above,
1528 // // comments left temporarily for easier visualization
1530 // // comparision with c code
1531 // es = process.getState();
1532 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1533 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1535 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1538 // // /* UNKNOWN STATE */
1540 // // es = process->state =
1541 // // &g_array_index(process->execution_stack,
1542 // // LttvExecutionState, 1);
1543 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1544 // // es->s = LTTV_STATE_UNNAMED;
1545 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1550 // * The process has already been created : Probably was
1551 // * forked while dumping the process state or was simply
1552 // * scheduled in prior to get the state dump event.
1554 // process.setPpid(parent_pid);
1555 // process.setTgid(tgid);
1556 // process.setName(command);
1557 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1560 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1562 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1566 // // &g_array_index(process->execution_stack,
1567 // // LttvExecutionState,
1570 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1571 // // if(type == LTTV_STATE_KERNEL_THREAD)
1572 // // es->t = LTTV_STATE_SYSCALL;
1574 // // es->t = LTTV_STATE_USER_MODE;
1578 // * Don't mess around with the stack, it will eventually
1579 // * become ok after the end of state dump.