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 @SuppressWarnings("nls")
32 class StateAfterUpdateHandlers
{
34 final ILttngEventProcessor
getSyscallEntryHandler() {
35 AbsStateUpdate handler
= new AbsStateUpdate() {
39 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
40 // TraceDebug.debug("After event called");
42 Long cpu
= trcEvent
.getCpuId();
44 // No syscall_entry update for initialization process
45 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
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(cpu
);
96 /* There can be no system call from PID 0 : unknown state */
97 if (process
.getPid() == 0L) {
100 .debug("Unexpected pid from before and after verfication methods, before pid: "
103 + process
.getPid_time());
109 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
110 // traceSt, trcEvent.getTimestamp());
119 * Update stacks related to the parsing of an LttngEvent
123 final ILttngEventProcessor
getTrapEntryHandler() {
124 AbsStateUpdate handler
= new AbsStateUpdate() {
128 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
129 // Long cpu = trcEvent.getCpuId();
131 // Long trap = getAFieldLong(trcEvent, traceSt,
132 // Fields.LTT_FIELD_TRAP_ID);
133 // if (trap == null) {
137 // String submode = traceSt.getSyscall_names()
140 // if (submode == null) {
141 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
145 // /* update process state */
146 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
147 // submode, trcEvent.getTimestamp(), traceSt);
149 // /* update cpu status */
150 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
151 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
152 // cpust.setLast_trap(trap); /* update trap status */
154 // // update Trap State
155 // LttngTrapState trap_state = traceSt.getTrap_states().get(
157 // trap_state.incrementRunning();
170 final ILttngEventProcessor
getTrapExitHandler() {
171 AbsStateUpdate handler
= new AbsStateUpdate() {
175 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
177 // Long cpu = trcEvent.getCpuId();
178 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
179 // Long trap = cpust.getLast_trap();
181 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
185 // /* update cpu status */
186 // cpu_pop_mode(cpust);
188 // /* update trap status */
189 // if (trap != -1L) {
190 // traceSt.getTrap_states().get(trap).decrementRunning();
203 final ILttngEventProcessor
getIrqEntryHandler() {
204 AbsStateUpdate handler
= new AbsStateUpdate() {
208 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
210 // Long cpu = trcEvent.getCpuId();
212 // Long irq = getAFieldLong(trcEvent, traceSt,
213 // Fields.LTT_FIELD_IRQ_ID);
214 // if (irq == null) {
219 // submode = traceSt.getIrq_names().get(irq);
221 // if (submode == null) {
223 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
227 // * Do something with the info about being in user or system
231 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
233 // .getTimestamp(), traceSt);
235 // /* update cpu state */
236 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
237 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
238 // cpust.setLast_irq(irq); /* last irq */
240 // /* udpate irq state */
241 // irq_push_mode(traceSt.getIrq_states().get(irq),
242 // IRQMode.LTTV_IRQ_BUSY);
254 final ILttngEventProcessor
getSoftIrqExitHandler() {
255 AbsStateUpdate handler
= new AbsStateUpdate() {
259 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
261 // Long cpu = trcEvent.getCpuId();
262 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
263 // Long softirq = cpust.getLast_soft_irq();
264 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
265 // trcEvent.getTimestamp());
267 // /* update softirq status */
268 // if (softirq != -1) {
269 // LttngSoftIRQState softIrqstate = traceSt
270 // .getSoft_irq_states().get(softirq);
271 // softIrqstate.decrementRunning();
274 // /* update cpu status */
275 // cpu_pop_mode(cpust);
287 final ILttngEventProcessor
getIrqExitHandler() {
288 AbsStateUpdate handler
= new AbsStateUpdate() {
292 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
294 // Long cpu = trcEvent.getCpuId();
296 // /* update process state */
297 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
301 // /* update cpu status */
302 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
303 // cpu_pop_mode(cpust);
305 // /* update irq status */
306 // Long last_irq = cpust.getLast_irq();
307 // if (last_irq != -1L) {
308 // LttngIRQState irq_state = traceSt.getIrq_states().get(
310 // irq_pop_mode(irq_state);
324 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
325 AbsStateUpdate handler
= new AbsStateUpdate() {
329 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
331 // // Long cpu = trcEvent.getCpuId();
333 // // get event field
334 // Long softirq = getAFieldLong(trcEvent, traceSt,
335 // Fields.LTT_FIELD_SOFT_IRQ_ID);
337 // if (softirq == null) {
341 // // String submode;
342 // // String[] softIrqNames = traceSt.getSoft_irq_names();
343 // // if (softirq < softIrqNames.length) {
344 // // submode = softIrqNames[softirq];
346 // // submode = "softirq " + softirq;
349 // /* update softirq status */
350 // /* a soft irq raises are not cumulative */
351 // LttngSoftIRQState irqState =
352 // traceSt.getSoft_irq_states().get(
354 // if (irqState != null) {
355 // irqState.setPending(1L);
358 // .debug("unexpected soft irq id value: " + softirq);
372 final ILttngEventProcessor
getSoftIrqEntryHandler() {
373 AbsStateUpdate handler
= new AbsStateUpdate() {
377 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
380 // Long cpu = trcEvent.getCpuId();
382 // // get event field
383 // Long softirq = getAFieldLong(trcEvent, traceSt,
384 // Fields.LTT_FIELD_SOFT_IRQ_ID);
386 // if (softirq == null) {
391 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
392 // String submode = softIrqNames.get(softirq);
393 // if (submode == null) {
394 // submode = "softirq " + softirq;
395 // softIrqNames.put(softirq, submode);
398 // /* update softirq status */
399 // LttngSoftIRQState irqState =
400 // traceSt.getSoft_irq_states().get(
402 // if (irqState != null) {
403 // irqState.decrementPending();
404 // irqState.incrementRunning();
407 // .debug("unexpected soft irq id value: " + softirq);
410 // /* update cpu state */
411 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
412 // cpu_state.setLast_soft_irq(softirq);
413 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
415 // /* update process execution mode state stack */
416 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
417 // trcEvent.getTimestamp(), traceSt);
427 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
431 final ILttngEventProcessor
getEnumInterruptHandler() {
432 AbsStateUpdate handler
= new AbsStateUpdate() {
436 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
437 // String action = getAFieldString(trcEvent, traceSt,
438 // Fields.LTT_FIELD_ACTION);
439 // Long irq = getAFieldLong(trcEvent, traceSt,
440 // Fields.LTT_FIELD_IRQ_ID);
442 // Map<Long, String> irq_names = traceSt.getIrq_names();
444 // irq_names.put(irq, action);
453 * Handle the event LTT_EVENT_REQUEST_ISSUE
457 final ILttngEventProcessor
getBdevRequestIssueHandler() {
458 AbsStateUpdate handler
= new AbsStateUpdate() {
462 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
465 // Long major = getAFieldLong(trcEvent, traceSt,
466 // Fields.LTT_FIELD_MAJOR);
467 // Long minor = getAFieldLong(trcEvent, traceSt,
468 // Fields.LTT_FIELD_MINOR);
469 // Long operation = getAFieldLong(trcEvent, traceSt,
470 // Fields.LTT_FIELD_OPERATION);
472 // // calculate bdevcode
473 // Long devcode = mkdev(major, minor);
475 // if (devcode == null) {
477 // .debug("incorrect calcualtion of bdevcode input( major: "
481 // + " operation: " + operation);
485 // Map<Long, LttngBdevState> bdev_states = traceSt
486 // .getBdev_states();
487 // // Get the instance
488 // LttngBdevState bdevState = bdev_states.get(devcode);
489 // if (bdevState == null) {
490 // bdevState = new LttngBdevState();
493 // // update the mode in the stack
494 // if (operation == 0L) {
495 // bdevState.getMode_stack().push(
496 // BdevMode.LTTV_BDEV_BUSY_READING);
498 // bdevState.getMode_stack().push(
499 // BdevMode.LTTV_BDEV_BUSY_WRITING);
502 // // make sure it is included in the set
503 // bdev_states.put(devcode, bdevState);
513 * Handling event: LTT_EVENT_REQUEST_COMPLETE
516 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
521 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
522 AbsStateUpdate handler
= new AbsStateUpdate() {
526 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
529 // Long major = getAFieldLong(trcEvent, traceSt,
530 // Fields.LTT_FIELD_MAJOR);
531 // Long minor = getAFieldLong(trcEvent, traceSt,
532 // Fields.LTT_FIELD_MINOR);
533 // Long operation = getAFieldLong(trcEvent, traceSt,
534 // Fields.LTT_FIELD_OPERATION);
536 // // calculate bdevcode
537 // Long devcode = mkdev(major, minor);
539 // if (devcode == null) {
541 // .debug("incorrect calcualtion of bdevcode input( major: "
545 // + " operation: " + operation);
549 // Map<Long, LttngBdevState> bdev_states = traceSt
550 // .getBdev_states();
551 // // Get the instance
552 // LttngBdevState bdevState = bdev_states.get(devcode);
553 // if (bdevState == null) {
554 // bdevState = new LttngBdevState();
557 // /* update block device */
558 // bdev_pop_mode(bdevState);
569 * Handles event: LTT_EVENT_FUNCTION_ENTRY
572 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
577 final ILttngEventProcessor
getFunctionEntryHandler() {
578 AbsStateUpdate handler
= new AbsStateUpdate() {
582 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
583 // Long cpu = trcEvent.getCpuId();
584 // Long funcptr = getAFieldLong(trcEvent, traceSt,
585 // Fields.LTT_FIELD_THIS_FN);
587 // push_function(traceSt, funcptr, cpu);
599 final ILttngEventProcessor
getFunctionExitHandler() {
600 AbsStateUpdate handler
= new AbsStateUpdate() {
604 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
606 // Long funcptr = getAFieldLong(trcEvent, traceSt,
607 // Fields.LTT_FIELD_THIS_FN);
609 // pop_function(traceSt, trcEvent, funcptr);
619 * process event: LTT_EVENT_SYS_CALL_TABLE
622 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
627 final ILttngEventProcessor
getDumpSyscallHandler() {
628 AbsStateUpdate handler
= new AbsStateUpdate() {
632 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
633 // // obtain the syscall id
634 // Long id = getAFieldLong(trcEvent, traceSt,
635 // Fields.LTT_FIELD_ID);
637 // // Long address = getAFieldLong(trcEvent, traceSt,
638 // // Fields.LTT_FIELD_ADDRESS);
640 // // Obtain the symbol
641 // String symbol = getAFieldString(trcEvent, traceSt,
642 // Fields.LTT_FIELD_SYMBOL);
644 // // fill the symbol to the sycall_names collection
645 // traceSt.getSyscall_names().put(id, symbol);
655 * Handles event: LTT_EVENT_KPROBE_TABLE
658 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
663 final ILttngEventProcessor
getDumpKprobeHandler() {
664 AbsStateUpdate handler
= new AbsStateUpdate() {
668 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
670 // Long ip = getAFieldLong(trcEvent, traceSt,
671 // Fields.LTT_FIELD_IP);
672 // String symbol = getAFieldString(trcEvent, traceSt,
673 // Fields.LTT_FIELD_SYMBOL);
675 // traceSt.getKprobe_table().put(ip, symbol);
686 * Handles: LTT_EVENT_SOFTIRQ_VEC
689 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
694 final ILttngEventProcessor
getDumpSoftIrqHandler() {
695 AbsStateUpdate handler
= new AbsStateUpdate() {
699 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
702 // Long id = getAFieldLong(trcEvent, traceSt,
703 // Fields.LTT_FIELD_ID);
705 // // Address not needed
706 // // Long address = ltt_event_get_long_unsigned(e,
707 // // lttv_trace_get_hook_field(th,
711 // String symbol = getAFieldString(trcEvent, traceSt,
712 // Fields.LTT_FIELD_SYMBOL);
714 // // Register the soft irq name
715 // traceSt.getSoft_irq_names().put(id, symbol);
725 * Handles: LTT_EVENT_SCHED_SCHEDULE
728 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
733 final ILttngEventProcessor
getSchedChangeHandler() {
734 AbsStateUpdate handler
= new AbsStateUpdate() {
738 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
740 // Long cpu = trcEvent.getCpuId();
741 // TmfTimestamp eventTime = trcEvent.getTimestamp();
743 // LttngProcessState process = traceSt.getRunning_process().get(
746 // Long pid_out = getAFieldLong(trcEvent, traceSt,
747 // Fields.LTT_FIELD_PREV_PID);
748 // Long pid_in = getAFieldLong(trcEvent, traceSt,
749 // Fields.LTT_FIELD_NEXT_PID);
750 // Long state_out = getAFieldLong(trcEvent, traceSt,
751 // Fields.LTT_FIELD_PREV_STATE);
753 // if (process != null) {
756 // * We could not know but it was not the idle process
757 // * executing. This should only happen at the beginning,
758 // * before the first schedule event, and when the initial
759 // * information (current process for each CPU) is missing. It
760 // * is not obvious how we could, after the fact, compensate
761 // * the wrongly attributed statistics.
764 // // This test only makes sense once the state is known and if
767 // // missing events. We need to silently ignore schedchange
770 // // process_free, or it causes glitches. (FIXME)
771 // // if(unlikely(process->pid != pid_out)) {
772 // // g_assert(process->pid == 0);
774 // if (process.getPid() == 0
775 // && process.getState().getExec_mode() ==
776 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
777 // if (pid_out == 0) {
779 // * Scheduling out of pid 0 at beginning of the trace
780 // * : we know for sure it is in syscall mode at this
783 // int stackSize = process.getExecution_stack().size();
784 // if (stackSize != 1) {
786 // .debug("unpexpected process execution stack size, expected 1, received: ");
789 // process.getState().setExec_mode(
790 // ExecutionMode.LTTV_STATE_SYSCALL);
791 // process.getState().setProc_status(
792 // ProcessStatus.LTTV_STATE_WAIT);
793 // process.getState().setChage_Time(
794 // trcEvent.getTimestamp());
795 // process.getState().setEntry_Time(
796 // trcEvent.getTimestamp());
799 // if (process.getState().getProc_status() ==
800 // ProcessStatus.LTTV_STATE_EXIT) {
801 // process.getState().setProc_status(
802 // ProcessStatus.LTTV_STATE_ZOMBIE);
803 // process.getState().setChage_Time(
804 // trcEvent.getTimestamp());
806 // if (state_out == 0L) {
807 // process.getState().setProc_status(
808 // ProcessStatus.LTTV_STATE_WAIT_CPU);
810 // process.getState().setProc_status(
811 // ProcessStatus.LTTV_STATE_WAIT);
814 // process.getState().setChage_Time(
815 // trcEvent.getTimestamp());
818 // if (state_out == 32L || state_out == 64L) { /*
823 // /* see sched.h for states */
824 // if (!exit_process(traceSt, process)) {
825 // process.getState().setProc_status(
826 // ProcessStatus.LTTV_STATE_DEAD);
827 // process.getState().setChage_Time(
828 // trcEvent.getTimestamp());
833 // process = lttv_state_find_process_or_create(traceSt, cpu,
834 // pid_in, eventTime);
836 // traceSt.getRunning_process().put(cpu, process);
838 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
839 // process.getState().setChage_Time(eventTime);
840 // process.setCpu(cpu);
841 // // process->state->s = LTTV_STATE_RUN;
842 // // if(process->usertrace)
843 // // process->usertrace->cpu = cpu;
844 // // process->last_cpu_index =
845 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
847 // // process->state->change = s->parent.timestamp;
849 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
850 // /* update cpu status */
851 // if (pid_in == 0) {
853 // /* going to idle task */
854 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
857 // * scheduling a real task. we must be careful here: if we
858 // * just schedule()'ed to a process that is in a trap, we
859 // * must put the cpu in trap mode
861 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
862 // if (process.getState().getExec_mode() ==
863 // ExecutionMode.LTTV_STATE_TRAP) {
864 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
876 * Handles: LTT_EVENT_PROCESS_FORK
879 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
880 * LTT_FIELD_CHILD_TGID)
885 final ILttngEventProcessor
getProcessForkHandler() {
886 AbsStateUpdate handler
= new AbsStateUpdate() {
890 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
892 // Long cpu = trcEvent.getCpuId();
893 // LttngProcessState process = traceSt.getRunning_process().get(
895 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
897 // // /* Parent PID */
898 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
899 // // Fields.LTT_FIELD_PARENT_PID);
902 // /* In the Linux Kernel, there is one PID per thread. */
903 // Long child_pid = getAFieldLong(trcEvent, traceSt,
904 // Fields.LTT_FIELD_CHILD_PID);
907 // /* tgid in the Linux kernel is the "real" POSIX PID. */
908 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
909 // Fields.LTT_FIELD_CHILD_TGID);
910 // if (child_tgid == null) {
915 // * Mathieu : it seems like the process might have been
917 // * in before the fork, and, in a rare case, might be the
919 // * process. This might happen in a SMP case where we don't
921 // * enough precision on the clocks.
923 // * Test reenabled after precision fixes on time. (Mathieu)
926 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
929 // // if(unlikely(zombie_process != NULL)) {
930 // // /* Reutilisation of PID. Only now we are sure that the old
932 // // * has been released. FIXME : should know when release_task
936 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
938 // // for(i=0; i< num_cpus; i++) {
939 // // g_assert(zombie_process != ts->running_process[i]);
942 // // exit_process(s, zombie_process);
946 // if (process.getPid() == child_pid) {
948 // .debug("Unexpected, process pid equal to child pid: "
951 // + trcEvent.getTimestamp());
954 // // g_assert(process->pid != child_pid);
955 // // FIXME : Add this test in the "known state" section
956 // // g_assert(process->pid == parent_pid);
957 // LttngProcessState child_process = lttv_state_find_process(
958 // traceSt, ANY_CPU, child_pid);
959 // if (child_process == null) {
960 // child_process = create_process(traceSt, cpu, child_pid,
961 // child_tgid, timeStamp);
964 // * The process has already been created : due to time
965 // * imprecision between multiple CPUs : it has been scheduled
966 // * in before creation. Note that we shouldn't have this kind
969 // * Simply put a correct parent.
971 // StringBuilder sb = new StringBuilder("Process " + child_pid);
972 // sb.append(" has been created at ["
973 // + child_process.getCration_time() + "] ");
974 // sb.append("and inserted at ["
975 // + child_process.getInsertion_time() + "] ");
976 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
977 // + trcEvent + "]\n.");
979 // .append("Probably an unsynchronized TSD problem on the traced machine.");
980 // TraceDebug.debug(sb.toString());
982 // // g_assert(0); /* This is a problematic case : the process
985 // // before the fork event */
986 // child_process.setPpid(process.getPid());
987 // child_process.setTgid(child_tgid);
990 // if (!child_process.getName().equals(
991 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
992 // TraceDebug.debug("Unexpected child process status: "
993 // + child_process.getName());
996 // child_process.setName(process.getName());
997 // child_process.setBrand(process.getBrand());
1008 * Handles: LTT_EVENT_KTHREAD_CREATE
1011 * Fields: LTT_FIELD_PID
1016 final ILttngEventProcessor
getProcessKernelThreadHandler() {
1017 AbsStateUpdate handler
= new AbsStateUpdate() {
1021 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1023 // * We stamp a newly created process as kernel_thread. The
1025 // * should not be running yet.
1028 // LttngExecutionState exState;
1030 // LttngProcessState process;
1033 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1034 // // s->parent.target_pid = pid;
1036 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1037 // pid, new TmfTimestamp());
1039 // if (!process.getState().getProc_status().equals(
1040 // ProcessStatus.LTTV_STATE_DEAD)) {
1041 // // Leave only the first element in the stack with execution
1044 // Stack<LttngExecutionState> processExStack = process
1045 // .getExecution_stack();
1046 // exState = processExStack.firstElement();
1047 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1048 // if (processExStack.size() > 1) {
1049 // processExStack.clear();
1050 // processExStack.add(exState);
1053 // // update the process state to the only one in the stack
1054 // process.setState(exState);
1057 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1068 * Handles: LTT_EVENT_PROCESS_EXIT
1076 final ILttngEventProcessor
getProcessExitHandler() {
1077 AbsStateUpdate handler
= new AbsStateUpdate() {
1081 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1084 // LttngProcessState process;
1086 // pid = getAFieldLong(trcEvent, traceSt,
1087 // Fields.LTT_FIELD_PID);
1088 // // s->parent.target_pid = pid;
1090 // // FIXME : Add this test in the "known state" section
1091 // // g_assert(process->pid == pid);
1093 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1094 // if (process != null) {
1095 // process.getState().setProc_status(
1096 // ProcessStatus.LTTV_STATE_EXIT);
1107 * Handles: LTT_EVENT_PROCESS_FREE
1110 * Fields: LTT_FIELD_PID
1115 final ILttngEventProcessor
getProcessFreeHandler() {
1116 AbsStateUpdate handler
= new AbsStateUpdate() {
1120 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1122 // Long release_pid;
1123 // LttngProcessState process;
1125 // /* PID of the process to release */
1126 // release_pid = getAFieldLong(trcEvent, traceSt,
1127 // Fields.LTT_FIELD_PID);
1128 // // s->parent.target_pid = release_pid;
1130 // if (release_pid == 0) {
1131 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1132 // + trcEvent.getTimestamp());
1135 // process = lttv_state_find_process(traceSt, ANY_CPU,
1137 // if (process != null) {
1138 // exit_process(traceSt, process);
1143 // if(process != null) {
1145 * release_task is happening at kernel level : we can now safely
1146 * release the data structure of the process
1148 // This test is fun, though, as it may happen that
1149 // at time t : CPU 0 : process_free
1150 // at time t+150ns : CPU 1 : schedule out
1151 // Clearly due to time imprecision, we disable it. (Mathieu)
1152 // If this weird case happen, we have no choice but to put the
1153 // Currently running process on the cpu to 0.
1154 // I re-enable it following time precision fixes. (Mathieu)
1155 // Well, in the case where an process is freed by a process on
1158 // and still scheduled, it happens that this is the schedchange
1161 // drop the last reference count. Do not free it here!
1163 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1165 // for(i=0; i< num_cpus; i++) {
1166 // //g_assert(process != ts->running_process[i]);
1167 // if(process == ts->running_process[i]) {
1168 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1172 // if(i == num_cpus) /* process is not scheduled */
1173 // exit_process(s, process);
1185 * Handles: LTT_EVENT_EXEC
1188 * FIELDS: LTT_FIELD_FILENAME
1193 final ILttngEventProcessor
getProcessExecHandler() {
1194 AbsStateUpdate handler
= new AbsStateUpdate() {
1198 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1200 // Long cpu = trcEvent.getCpuId();
1201 // LttngProcessState process = traceSt.getRunning_process().get(
1204 // // #if 0//how to use a sequence that must be transformed in a
1206 // // /* PID of the process to release */
1207 // // guint64 name_len = ltt_event_field_element_number(e,
1208 // // lttv_trace_get_hook_field(th, 0));
1209 // // //name = ltt_event_get_string(e,
1210 // // lttv_trace_get_hook_field(th, 0));
1211 // // LttField *child = ltt_event_field_element_select(e,
1212 // // lttv_trace_get_hook_field(th, 0), 0);
1213 // // gchar *name_begin =
1214 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1216 // // gchar *null_term_name = g_new(gchar, name_len+1);
1217 // // memcpy(null_term_name, name_begin, name_len);
1218 // // null_term_name[name_len] = '\0';
1219 // // process->name = g_quark_from_string(null_term_name);
1222 // process.setName(getAFieldString(trcEvent, traceSt,
1223 // Fields.LTT_FIELD_FILENAME));
1224 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1234 * LTT_EVENT_THREAD_BRAND
1237 * FIELDS: LTT_FIELD_NAME
1242 final ILttngEventProcessor
GetThreadBrandHandler() {
1243 AbsStateUpdate handler
= new AbsStateUpdate() {
1247 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1250 // Long cpu = trcEvent.getCpuId();
1251 // LttngProcessState process = traceSt.getRunning_process().get(
1254 // name = getAFieldString(trcEvent, traceSt,
1255 // Fields.LTT_FIELD_NAME);
1256 // process.setBrand(name);
1267 final ILttngEventProcessor
getStateDumpEndHandler() {
1268 AbsStateUpdate handler
= new AbsStateUpdate() {
1272 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1274 // /* For all processes */
1276 // * if kernel thread, if stack[0] is unknown, set to syscall
1279 // /* else, if stack[0] is unknown, set to user mode, running */
1280 // List<LttngProcessState> processes = traceSt.getProcesses();
1281 // TmfTimestamp time = trcEvent.getTimestamp();
1283 // for (LttngProcessState process : processes) {
1284 // fix_process(process, time);
1295 * Private method used to establish the first execution state in the stack
1296 * for a given process
1301 // private void fix_process(LttngProcessState process,
1302 // TmfTimestamp timestamp) {
1304 // LttngExecutionState es;
1305 // Stack<LttngExecutionState> procStack = process
1306 // .getExecution_stack();
1308 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1309 // es = procStack.firstElement();
1311 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1312 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1314 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1316 // es.setEntry_Time(timestamp);
1317 // es.setChage_Time(timestamp);
1318 // es.setCum_cpu_time(0L);
1319 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1320 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1324 // es = procStack.firstElement();
1325 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1326 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1328 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1330 // es.setEntry_Time(timestamp);
1331 // es.setChage_Time(timestamp);
1332 // es.setCum_cpu_time(0L);
1333 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1334 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1337 // if (procStack.size() == 1) {
1339 // * Still in bottom unknown mode, means never did a
1340 // * system call May be either in user mode, syscall
1341 // * mode, running or waiting.
1344 // * FIXME : we may be tagging syscall mode when being
1347 // // Get a new execution State
1348 // es = new LttngExecutionState();
1350 // // initialize values
1351 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1353 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1355 // es.setEntry_Time(timestamp);
1356 // es.setChage_Time(timestamp);
1357 // es.setCum_cpu_time(0L);
1358 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1360 // // Push the new state to the stack
1361 // procStack.push(es);
1372 * Handles: LTT_EVENT_PROCESS_STATE
1375 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1376 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1382 final ILttngEventProcessor
getEnumProcessStateHandler() {
1383 AbsStateUpdate handler
= new AbsStateUpdate() {
1387 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1393 // Long cpu = trcEvent.getCpuId();
1394 // LttngProcessState process = traceSt.getRunning_process().get(
1396 // LttngProcessState parent_process;
1398 // // String mode, submode, status;
1399 // LttngExecutionState es;
1402 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1405 // parent_pid = getAFieldLong(trcEvent, traceSt,
1406 // Fields.LTT_FIELD_PARENT_PID);
1408 // /* Command name */
1409 // command = getAFieldString(trcEvent, traceSt,
1410 // Fields.LTT_FIELD_NAME);
1412 // /* TODO: type field, Values need to be verified */
1414 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1415 // Fields.LTT_FIELD_TYPE);
1416 // if (typeVal == 0L) {
1417 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1419 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1422 // // FIXME: type is rarely used, enum must match possible
1426 // // mode = getAFieldString(trcEvent, traceSt,
1427 // // Fields.LTT_FIELD_MODE);
1430 // // submode = getAFieldString(trcEvent, traceSt,
1431 // // Fields.LTT_FIELD_SUBMODE);
1434 // // status = getAFieldString(trcEvent, traceSt,
1435 // // Fields.LTT_FIELD_STATUS);
1438 // tgid = getAFieldLong(trcEvent, traceSt,
1439 // Fields.LTT_FIELD_TGID);
1440 // if (tgid == null) {
1445 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1446 // process = lttv_state_find_process(traceSt, acpu, pid);
1447 // if (process != null) {
1448 // process.setPpid(parent_pid);
1449 // process.setTgid(tgid);
1450 // process.setName(command);
1452 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1454 // StringBuilder sb = new StringBuilder(
1455 // "Unexpected, null process read from the TraceState list of processes, event time: "
1456 // + trcEvent.getTimestamp());
1457 // TraceDebug.debug(sb.toString());
1462 // * The process might exist if a process was forked while
1463 // * performing the state dump.
1465 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1466 // if (process == null) {
1467 // parent_process = lttv_state_find_process(traceSt,
1468 // ANY_CPU, parent_pid);
1469 // process = create_process(traceSt, cpu, pid, tgid,
1470 // command, trcEvent.getTimestamp());
1471 // if (parent_process != null) {
1472 // process.setPpid(parent_process.getPid());
1475 // /* Keep the stack bottom : a running user mode */
1477 // * Disabled because of inconsistencies in the current
1478 // * statedump states.
1480 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1483 // * FIXME Kernel thread : can be in syscall or
1484 // * interrupt or trap.
1487 // * Will cause expected trap when in fact being
1488 // * syscall (even after end of statedump event) Will
1489 // * cause expected interrupt when being syscall.
1490 // * (only before end of statedump event)
1493 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1496 // // es->t = LTTV_STATE_SYSCALL;
1497 // // es->s = status;
1498 // // es->n = submode;
1502 // * User space process : bottom : user mode either
1503 // * currently running or scheduled out. can be
1504 // * scheduled out because interrupted in (user mode
1505 // * or in syscall) or because of an explicit call to
1506 // * the scheduler in syscall. Note that the scheduler
1507 // * call comes after the irq_exit, so never in
1508 // * interrupt context.
1510 // // temp workaround : set size to 1 : only have user
1512 // // bottom of stack.
1513 // // will cause g_info message of expected syscall
1516 // // in user mode. Can also cause expected trap when
1519 // // mode in the event of a page fault reenabling
1521 // // in the handler.
1522 // // Expected syscall and trap can also happen after
1525 // // This will cause a
1526 // // "popping last state on stack, ignoring it."
1528 // // process->execution_stack =
1529 // // g_array_set_size(process->execution_stack, 1);
1530 // // es = process->state =
1531 // // &g_array_index(process->execution_stack,
1532 // // LttvExecutionState, 0);
1533 // // a new process must have only one state in the
1535 // // be the same as the current state
1536 // // es = process.getState();
1537 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1538 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1541 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1542 // // .getInName());
1545 // // es->t = LTTV_STATE_USER_MODE;
1546 // // es->s = status;
1547 // // es->n = submode;
1550 // // TODO: clean up comments above: Moved repeated code
1552 // // if / else blocks above,
1553 // // comments left temporarily for easier visualization
1555 // // comparision with c code
1556 // es = process.getState();
1557 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1558 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1560 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1563 // // /* UNKNOWN STATE */
1565 // // es = process->state =
1566 // // &g_array_index(process->execution_stack,
1567 // // LttvExecutionState, 1);
1568 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1569 // // es->s = LTTV_STATE_UNNAMED;
1570 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1575 // * The process has already been created : Probably was
1576 // * forked while dumping the process state or was simply
1577 // * scheduled in prior to get the state dump event.
1579 // process.setPpid(parent_pid);
1580 // process.setTgid(tgid);
1581 // process.setName(command);
1582 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1585 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1587 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1591 // // &g_array_index(process->execution_stack,
1592 // // LttvExecutionState,
1595 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1596 // // if(type == LTTV_STATE_KERNEL_THREAD)
1597 // // es->t = LTTV_STATE_SYSCALL;
1599 // // es->t = LTTV_STATE_USER_MODE;
1603 // * Don't mess around with the stack, it will eventually
1604 // * become ok after the end of state dump.