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(
48 if (pid
!= process
.getPid()) {
50 .debug("pid values don't match from before and after verification check");
53 if (process
.getPid() == 0L) {
57 // Make sure the top of the stack and the state of the stack are
60 LttngExecutionState stackState
= process
.peekFromExecutionStack();
61 if (stackState
!= process
.getState()) {
63 .debug("The top of the stack does not match to the process state");
66 if (stackState
.getExec_mode().getInName() != ExecutionMode
.LTTV_STATE_SYSCALL
68 TraceDebug
.debug("Unexpected ExecutionMode: "
69 + stackState
.getExec_mode().getInName()
71 + ExecutionMode
.LTTV_STATE_SYSCALL
.getInName());
74 if (stackState
.getEntry_LttTime() != trcEvent
.getTimestamp().getValue()) {
75 TraceDebug
.debug("Unexpected Entry time: "
76 + trcEvent
.getTimestamp() + " Expected: "
77 + stackState
.getEntry_LttTime());
86 final ILttngEventProcessor
getsySyscallExitHandler() {
87 AbsStateUpdate handler
= new AbsStateUpdate() {
91 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
93 // TraceDebug.debug("Syscall Exit After event called");
94 Long cpu
= trcEvent
.getCpuId();
95 LttngProcessState process
= traceSt
.getRunning_process().get(
98 /* There can be no system call from PID 0 : unknown state */
99 if (process
.getPid() == 0L) {
102 .debug("Unexpected pid from before and after verfication methods, before pid: "
105 + process
.getPid_time());
111 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
112 // traceSt, trcEvent.getTimestamp());
121 * Update stacks related to the parsing of an LttngEvent
125 final ILttngEventProcessor
getTrapEntryHandler() {
126 AbsStateUpdate handler
= new AbsStateUpdate() {
130 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
131 // Long cpu = trcEvent.getCpuId();
133 // Long trap = getAFieldLong(trcEvent, traceSt,
134 // Fields.LTT_FIELD_TRAP_ID);
135 // if (trap == null) {
139 // String submode = traceSt.getSyscall_names()
142 // if (submode == null) {
143 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
147 // /* update process state */
148 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
149 // submode, trcEvent.getTimestamp(), traceSt);
151 // /* update cpu status */
152 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
153 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
154 // cpust.setLast_trap(trap); /* update trap status */
156 // // update Trap State
157 // LttngTrapState trap_state = traceSt.getTrap_states().get(
159 // trap_state.incrementRunning();
172 final ILttngEventProcessor
getTrapExitHandler() {
173 AbsStateUpdate handler
= new AbsStateUpdate() {
177 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
179 // Long cpu = trcEvent.getCpuId();
180 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
181 // Long trap = cpust.getLast_trap();
183 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
187 // /* update cpu status */
188 // cpu_pop_mode(cpust);
190 // /* update trap status */
191 // if (trap != -1L) {
192 // traceSt.getTrap_states().get(trap).decrementRunning();
205 final ILttngEventProcessor
getIrqEntryHandler() {
206 AbsStateUpdate handler
= new AbsStateUpdate() {
210 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
212 // Long cpu = trcEvent.getCpuId();
214 // Long irq = getAFieldLong(trcEvent, traceSt,
215 // Fields.LTT_FIELD_IRQ_ID);
216 // if (irq == null) {
221 // submode = traceSt.getIrq_names().get(irq);
223 // if (submode == null) {
225 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
229 // * Do something with the info about being in user or system
233 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
235 // .getTimestamp(), traceSt);
237 // /* update cpu state */
238 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
239 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
240 // cpust.setLast_irq(irq); /* last irq */
242 // /* udpate irq state */
243 // irq_push_mode(traceSt.getIrq_states().get(irq),
244 // IRQMode.LTTV_IRQ_BUSY);
256 final ILttngEventProcessor
getSoftIrqExitHandler() {
257 AbsStateUpdate handler
= new AbsStateUpdate() {
261 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
263 // Long cpu = trcEvent.getCpuId();
264 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
265 // Long softirq = cpust.getLast_soft_irq();
266 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
267 // trcEvent.getTimestamp());
269 // /* update softirq status */
270 // if (softirq != -1) {
271 // LttngSoftIRQState softIrqstate = traceSt
272 // .getSoft_irq_states().get(softirq);
273 // softIrqstate.decrementRunning();
276 // /* update cpu status */
277 // cpu_pop_mode(cpust);
289 final ILttngEventProcessor
getIrqExitHandler() {
290 AbsStateUpdate handler
= new AbsStateUpdate() {
294 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
296 // Long cpu = trcEvent.getCpuId();
298 // /* update process state */
299 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
303 // /* update cpu status */
304 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
305 // cpu_pop_mode(cpust);
307 // /* update irq status */
308 // Long last_irq = cpust.getLast_irq();
309 // if (last_irq != -1L) {
310 // LttngIRQState irq_state = traceSt.getIrq_states().get(
312 // irq_pop_mode(irq_state);
326 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
327 AbsStateUpdate handler
= new AbsStateUpdate() {
331 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
333 // // Long cpu = trcEvent.getCpuId();
335 // // get event field
336 // Long softirq = getAFieldLong(trcEvent, traceSt,
337 // Fields.LTT_FIELD_SOFT_IRQ_ID);
339 // if (softirq == null) {
343 // // String submode;
344 // // String[] softIrqNames = traceSt.getSoft_irq_names();
345 // // if (softirq < softIrqNames.length) {
346 // // submode = softIrqNames[softirq];
348 // // submode = "softirq " + softirq;
351 // /* update softirq status */
352 // /* a soft irq raises are not cumulative */
353 // LttngSoftIRQState irqState =
354 // traceSt.getSoft_irq_states().get(
356 // if (irqState != null) {
357 // irqState.setPending(1L);
360 // .debug("unexpected soft irq id value: " + softirq);
374 final ILttngEventProcessor
getSoftIrqEntryHandler() {
375 AbsStateUpdate handler
= new AbsStateUpdate() {
379 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
382 // Long cpu = trcEvent.getCpuId();
384 // // get event field
385 // Long softirq = getAFieldLong(trcEvent, traceSt,
386 // Fields.LTT_FIELD_SOFT_IRQ_ID);
388 // if (softirq == null) {
393 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
394 // String submode = softIrqNames.get(softirq);
395 // if (submode == null) {
396 // submode = "softirq " + softirq;
397 // softIrqNames.put(softirq, submode);
400 // /* update softirq status */
401 // LttngSoftIRQState irqState =
402 // traceSt.getSoft_irq_states().get(
404 // if (irqState != null) {
405 // irqState.decrementPending();
406 // irqState.incrementRunning();
409 // .debug("unexpected soft irq id value: " + softirq);
412 // /* update cpu state */
413 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
414 // cpu_state.setLast_soft_irq(softirq);
415 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
417 // /* update process execution mode state stack */
418 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
419 // trcEvent.getTimestamp(), traceSt);
429 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
433 final ILttngEventProcessor
getEnumInterruptHandler() {
434 AbsStateUpdate handler
= new AbsStateUpdate() {
438 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
439 // String action = getAFieldString(trcEvent, traceSt,
440 // Fields.LTT_FIELD_ACTION);
441 // Long irq = getAFieldLong(trcEvent, traceSt,
442 // Fields.LTT_FIELD_IRQ_ID);
444 // Map<Long, String> irq_names = traceSt.getIrq_names();
446 // irq_names.put(irq, action);
455 * Handle the event LTT_EVENT_REQUEST_ISSUE
459 final ILttngEventProcessor
getBdevRequestIssueHandler() {
460 AbsStateUpdate handler
= new AbsStateUpdate() {
464 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
467 // Long major = getAFieldLong(trcEvent, traceSt,
468 // Fields.LTT_FIELD_MAJOR);
469 // Long minor = getAFieldLong(trcEvent, traceSt,
470 // Fields.LTT_FIELD_MINOR);
471 // Long operation = getAFieldLong(trcEvent, traceSt,
472 // Fields.LTT_FIELD_OPERATION);
474 // // calculate bdevcode
475 // Long devcode = mkdev(major, minor);
477 // if (devcode == null) {
479 // .debug("incorrect calcualtion of bdevcode input( major: "
483 // + " operation: " + operation);
487 // Map<Long, LttngBdevState> bdev_states = traceSt
488 // .getBdev_states();
489 // // Get the instance
490 // LttngBdevState bdevState = bdev_states.get(devcode);
491 // if (bdevState == null) {
492 // bdevState = new LttngBdevState();
495 // // update the mode in the stack
496 // if (operation == 0L) {
497 // bdevState.getMode_stack().push(
498 // BdevMode.LTTV_BDEV_BUSY_READING);
500 // bdevState.getMode_stack().push(
501 // BdevMode.LTTV_BDEV_BUSY_WRITING);
504 // // make sure it is included in the set
505 // bdev_states.put(devcode, bdevState);
515 * Handling event: LTT_EVENT_REQUEST_COMPLETE
518 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
523 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
524 AbsStateUpdate handler
= new AbsStateUpdate() {
528 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
531 // Long major = getAFieldLong(trcEvent, traceSt,
532 // Fields.LTT_FIELD_MAJOR);
533 // Long minor = getAFieldLong(trcEvent, traceSt,
534 // Fields.LTT_FIELD_MINOR);
535 // Long operation = getAFieldLong(trcEvent, traceSt,
536 // Fields.LTT_FIELD_OPERATION);
538 // // calculate bdevcode
539 // Long devcode = mkdev(major, minor);
541 // if (devcode == null) {
543 // .debug("incorrect calcualtion of bdevcode input( major: "
547 // + " operation: " + operation);
551 // Map<Long, LttngBdevState> bdev_states = traceSt
552 // .getBdev_states();
553 // // Get the instance
554 // LttngBdevState bdevState = bdev_states.get(devcode);
555 // if (bdevState == null) {
556 // bdevState = new LttngBdevState();
559 // /* update block device */
560 // bdev_pop_mode(bdevState);
571 * Handles event: LTT_EVENT_FUNCTION_ENTRY
574 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
579 final ILttngEventProcessor
getFunctionEntryHandler() {
580 AbsStateUpdate handler
= new AbsStateUpdate() {
584 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
585 // Long cpu = trcEvent.getCpuId();
586 // Long funcptr = getAFieldLong(trcEvent, traceSt,
587 // Fields.LTT_FIELD_THIS_FN);
589 // push_function(traceSt, funcptr, cpu);
601 final ILttngEventProcessor
getFunctionExitHandler() {
602 AbsStateUpdate handler
= new AbsStateUpdate() {
606 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
608 // Long funcptr = getAFieldLong(trcEvent, traceSt,
609 // Fields.LTT_FIELD_THIS_FN);
611 // pop_function(traceSt, trcEvent, funcptr);
621 * process event: LTT_EVENT_SYS_CALL_TABLE
624 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
629 final ILttngEventProcessor
getDumpSyscallHandler() {
630 AbsStateUpdate handler
= new AbsStateUpdate() {
634 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
635 // // obtain the syscall id
636 // Long id = getAFieldLong(trcEvent, traceSt,
637 // Fields.LTT_FIELD_ID);
639 // // Long address = getAFieldLong(trcEvent, traceSt,
640 // // Fields.LTT_FIELD_ADDRESS);
642 // // Obtain the symbol
643 // String symbol = getAFieldString(trcEvent, traceSt,
644 // Fields.LTT_FIELD_SYMBOL);
646 // // fill the symbol to the sycall_names collection
647 // traceSt.getSyscall_names().put(id, symbol);
657 * Handles event: LTT_EVENT_KPROBE_TABLE
660 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
665 final ILttngEventProcessor
getDumpKprobeHandler() {
666 AbsStateUpdate handler
= new AbsStateUpdate() {
670 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
672 // Long ip = getAFieldLong(trcEvent, traceSt,
673 // Fields.LTT_FIELD_IP);
674 // String symbol = getAFieldString(trcEvent, traceSt,
675 // Fields.LTT_FIELD_SYMBOL);
677 // traceSt.getKprobe_table().put(ip, symbol);
688 * Handles: LTT_EVENT_SOFTIRQ_VEC
691 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
696 final ILttngEventProcessor
getDumpSoftIrqHandler() {
697 AbsStateUpdate handler
= new AbsStateUpdate() {
701 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
704 // Long id = getAFieldLong(trcEvent, traceSt,
705 // Fields.LTT_FIELD_ID);
707 // // Address not needed
708 // // Long address = ltt_event_get_long_unsigned(e,
709 // // lttv_trace_get_hook_field(th,
713 // String symbol = getAFieldString(trcEvent, traceSt,
714 // Fields.LTT_FIELD_SYMBOL);
716 // // Register the soft irq name
717 // traceSt.getSoft_irq_names().put(id, symbol);
727 * Handles: LTT_EVENT_SCHED_SCHEDULE
730 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
735 final ILttngEventProcessor
getSchedChangeHandler() {
736 AbsStateUpdate handler
= new AbsStateUpdate() {
740 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
742 // Long cpu = trcEvent.getCpuId();
743 // TmfTimestamp eventTime = trcEvent.getTimestamp();
745 // LttngProcessState process = traceSt.getRunning_process().get(
748 // Long pid_out = getAFieldLong(trcEvent, traceSt,
749 // Fields.LTT_FIELD_PREV_PID);
750 // Long pid_in = getAFieldLong(trcEvent, traceSt,
751 // Fields.LTT_FIELD_NEXT_PID);
752 // Long state_out = getAFieldLong(trcEvent, traceSt,
753 // Fields.LTT_FIELD_PREV_STATE);
755 // if (process != null) {
758 // * We could not know but it was not the idle process
759 // * executing. This should only happen at the beginning,
760 // * before the first schedule event, and when the initial
761 // * information (current process for each CPU) is missing. It
762 // * is not obvious how we could, after the fact, compensate
763 // * the wrongly attributed statistics.
766 // // This test only makes sense once the state is known and if
769 // // missing events. We need to silently ignore schedchange
772 // // process_free, or it causes glitches. (FIXME)
773 // // if(unlikely(process->pid != pid_out)) {
774 // // g_assert(process->pid == 0);
776 // if (process.getPid() == 0
777 // && process.getState().getExec_mode() ==
778 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
779 // if (pid_out == 0) {
781 // * Scheduling out of pid 0 at beginning of the trace
782 // * : we know for sure it is in syscall mode at this
785 // int stackSize = process.getExecution_stack().size();
786 // if (stackSize != 1) {
788 // .debug("unpexpected process execution stack size, expected 1, received: ");
791 // process.getState().setExec_mode(
792 // ExecutionMode.LTTV_STATE_SYSCALL);
793 // process.getState().setProc_status(
794 // ProcessStatus.LTTV_STATE_WAIT);
795 // process.getState().setChage_Time(
796 // trcEvent.getTimestamp());
797 // process.getState().setEntry_Time(
798 // trcEvent.getTimestamp());
801 // if (process.getState().getProc_status() ==
802 // ProcessStatus.LTTV_STATE_EXIT) {
803 // process.getState().setProc_status(
804 // ProcessStatus.LTTV_STATE_ZOMBIE);
805 // process.getState().setChage_Time(
806 // trcEvent.getTimestamp());
808 // if (state_out == 0L) {
809 // process.getState().setProc_status(
810 // ProcessStatus.LTTV_STATE_WAIT_CPU);
812 // process.getState().setProc_status(
813 // ProcessStatus.LTTV_STATE_WAIT);
816 // process.getState().setChage_Time(
817 // trcEvent.getTimestamp());
820 // if (state_out == 32L || state_out == 64L) { /*
825 // /* see sched.h for states */
826 // if (!exit_process(traceSt, process)) {
827 // process.getState().setProc_status(
828 // ProcessStatus.LTTV_STATE_DEAD);
829 // process.getState().setChage_Time(
830 // trcEvent.getTimestamp());
835 // process = lttv_state_find_process_or_create(traceSt, cpu,
836 // pid_in, eventTime);
838 // traceSt.getRunning_process().put(cpu, process);
840 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
841 // process.getState().setChage_Time(eventTime);
842 // process.setCpu(cpu);
843 // // process->state->s = LTTV_STATE_RUN;
844 // // if(process->usertrace)
845 // // process->usertrace->cpu = cpu;
846 // // process->last_cpu_index =
847 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
849 // // process->state->change = s->parent.timestamp;
851 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
852 // /* update cpu status */
853 // if (pid_in == 0) {
855 // /* going to idle task */
856 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
859 // * scheduling a real task. we must be careful here: if we
860 // * just schedule()'ed to a process that is in a trap, we
861 // * must put the cpu in trap mode
863 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
864 // if (process.getState().getExec_mode() ==
865 // ExecutionMode.LTTV_STATE_TRAP) {
866 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
878 * Handles: LTT_EVENT_PROCESS_FORK
881 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
882 * LTT_FIELD_CHILD_TGID)
887 final ILttngEventProcessor
getProcessForkHandler() {
888 AbsStateUpdate handler
= new AbsStateUpdate() {
892 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
894 // Long cpu = trcEvent.getCpuId();
895 // LttngProcessState process = traceSt.getRunning_process().get(
897 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
899 // // /* Parent PID */
900 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
901 // // Fields.LTT_FIELD_PARENT_PID);
904 // /* In the Linux Kernel, there is one PID per thread. */
905 // Long child_pid = getAFieldLong(trcEvent, traceSt,
906 // Fields.LTT_FIELD_CHILD_PID);
909 // /* tgid in the Linux kernel is the "real" POSIX PID. */
910 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
911 // Fields.LTT_FIELD_CHILD_TGID);
912 // if (child_tgid == null) {
917 // * Mathieu : it seems like the process might have been
919 // * in before the fork, and, in a rare case, might be the
921 // * process. This might happen in a SMP case where we don't
923 // * enough precision on the clocks.
925 // * Test reenabled after precision fixes on time. (Mathieu)
928 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
931 // // if(unlikely(zombie_process != NULL)) {
932 // // /* Reutilisation of PID. Only now we are sure that the old
934 // // * has been released. FIXME : should know when release_task
938 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
940 // // for(i=0; i< num_cpus; i++) {
941 // // g_assert(zombie_process != ts->running_process[i]);
944 // // exit_process(s, zombie_process);
948 // if (process.getPid() == child_pid) {
950 // .debug("Unexpected, process pid equal to child pid: "
953 // + trcEvent.getTimestamp());
956 // // g_assert(process->pid != child_pid);
957 // // FIXME : Add this test in the "known state" section
958 // // g_assert(process->pid == parent_pid);
959 // LttngProcessState child_process = lttv_state_find_process(
960 // traceSt, ANY_CPU, child_pid);
961 // if (child_process == null) {
962 // child_process = create_process(traceSt, cpu, child_pid,
963 // child_tgid, timeStamp);
966 // * The process has already been created : due to time
967 // * imprecision between multiple CPUs : it has been scheduled
968 // * in before creation. Note that we shouldn't have this kind
971 // * Simply put a correct parent.
973 // StringBuilder sb = new StringBuilder("Process " + child_pid);
974 // sb.append(" has been created at ["
975 // + child_process.getCration_time() + "] ");
976 // sb.append("and inserted at ["
977 // + child_process.getInsertion_time() + "] ");
978 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
979 // + trcEvent + "]\n.");
981 // .append("Probably an unsynchronized TSD problem on the traced machine.");
982 // TraceDebug.debug(sb.toString());
984 // // g_assert(0); /* This is a problematic case : the process
987 // // before the fork event */
988 // child_process.setPpid(process.getPid());
989 // child_process.setTgid(child_tgid);
992 // if (!child_process.getName().equals(
993 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
994 // TraceDebug.debug("Unexpected child process status: "
995 // + child_process.getName());
998 // child_process.setName(process.getName());
999 // child_process.setBrand(process.getBrand());
1010 * Handles: LTT_EVENT_KTHREAD_CREATE
1013 * Fields: LTT_FIELD_PID
1018 final ILttngEventProcessor
getProcessKernelThreadHandler() {
1019 AbsStateUpdate handler
= new AbsStateUpdate() {
1023 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1025 // * We stamp a newly created process as kernel_thread. The
1027 // * should not be running yet.
1030 // LttngExecutionState exState;
1032 // LttngProcessState process;
1035 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1036 // // s->parent.target_pid = pid;
1038 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1039 // pid, new TmfTimestamp());
1041 // if (!process.getState().getProc_status().equals(
1042 // ProcessStatus.LTTV_STATE_DEAD)) {
1043 // // Leave only the first element in the stack with execution
1046 // Stack<LttngExecutionState> processExStack = process
1047 // .getExecution_stack();
1048 // exState = processExStack.firstElement();
1049 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1050 // if (processExStack.size() > 1) {
1051 // processExStack.clear();
1052 // processExStack.add(exState);
1055 // // update the process state to the only one in the stack
1056 // process.setState(exState);
1059 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1070 * Handles: LTT_EVENT_PROCESS_EXIT
1078 final ILttngEventProcessor
getProcessExitHandler() {
1079 AbsStateUpdate handler
= new AbsStateUpdate() {
1083 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1086 // LttngProcessState process;
1088 // pid = getAFieldLong(trcEvent, traceSt,
1089 // Fields.LTT_FIELD_PID);
1090 // // s->parent.target_pid = pid;
1092 // // FIXME : Add this test in the "known state" section
1093 // // g_assert(process->pid == pid);
1095 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1096 // if (process != null) {
1097 // process.getState().setProc_status(
1098 // ProcessStatus.LTTV_STATE_EXIT);
1109 * Handles: LTT_EVENT_PROCESS_FREE
1112 * Fields: LTT_FIELD_PID
1117 final ILttngEventProcessor
getProcessFreeHandler() {
1118 AbsStateUpdate handler
= new AbsStateUpdate() {
1122 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1124 // Long release_pid;
1125 // LttngProcessState process;
1127 // /* PID of the process to release */
1128 // release_pid = getAFieldLong(trcEvent, traceSt,
1129 // Fields.LTT_FIELD_PID);
1130 // // s->parent.target_pid = release_pid;
1132 // if (release_pid == 0) {
1133 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1134 // + trcEvent.getTimestamp());
1137 // process = lttv_state_find_process(traceSt, ANY_CPU,
1139 // if (process != null) {
1140 // exit_process(traceSt, process);
1145 // if(process != null) {
1147 * release_task is happening at kernel level : we can now safely
1148 * release the data structure of the process
1150 // This test is fun, though, as it may happen that
1151 // at time t : CPU 0 : process_free
1152 // at time t+150ns : CPU 1 : schedule out
1153 // Clearly due to time imprecision, we disable it. (Mathieu)
1154 // If this weird case happen, we have no choice but to put the
1155 // Currently running process on the cpu to 0.
1156 // I re-enable it following time precision fixes. (Mathieu)
1157 // Well, in the case where an process is freed by a process on
1160 // and still scheduled, it happens that this is the schedchange
1163 // drop the last reference count. Do not free it here!
1165 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1167 // for(i=0; i< num_cpus; i++) {
1168 // //g_assert(process != ts->running_process[i]);
1169 // if(process == ts->running_process[i]) {
1170 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1174 // if(i == num_cpus) /* process is not scheduled */
1175 // exit_process(s, process);
1187 * Handles: LTT_EVENT_EXEC
1190 * FIELDS: LTT_FIELD_FILENAME
1195 final ILttngEventProcessor
getProcessExecHandler() {
1196 AbsStateUpdate handler
= new AbsStateUpdate() {
1200 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1202 // Long cpu = trcEvent.getCpuId();
1203 // LttngProcessState process = traceSt.getRunning_process().get(
1206 // // #if 0//how to use a sequence that must be transformed in a
1208 // // /* PID of the process to release */
1209 // // guint64 name_len = ltt_event_field_element_number(e,
1210 // // lttv_trace_get_hook_field(th, 0));
1211 // // //name = ltt_event_get_string(e,
1212 // // lttv_trace_get_hook_field(th, 0));
1213 // // LttField *child = ltt_event_field_element_select(e,
1214 // // lttv_trace_get_hook_field(th, 0), 0);
1215 // // gchar *name_begin =
1216 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1218 // // gchar *null_term_name = g_new(gchar, name_len+1);
1219 // // memcpy(null_term_name, name_begin, name_len);
1220 // // null_term_name[name_len] = '\0';
1221 // // process->name = g_quark_from_string(null_term_name);
1224 // process.setName(getAFieldString(trcEvent, traceSt,
1225 // Fields.LTT_FIELD_FILENAME));
1226 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1236 * LTT_EVENT_THREAD_BRAND
1239 * FIELDS: LTT_FIELD_NAME
1244 final ILttngEventProcessor
GetThreadBrandHandler() {
1245 AbsStateUpdate handler
= new AbsStateUpdate() {
1249 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1252 // Long cpu = trcEvent.getCpuId();
1253 // LttngProcessState process = traceSt.getRunning_process().get(
1256 // name = getAFieldString(trcEvent, traceSt,
1257 // Fields.LTT_FIELD_NAME);
1258 // process.setBrand(name);
1269 final ILttngEventProcessor
getStateDumpEndHandler() {
1270 AbsStateUpdate handler
= new AbsStateUpdate() {
1274 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1276 // /* For all processes */
1278 // * if kernel thread, if stack[0] is unknown, set to syscall
1281 // /* else, if stack[0] is unknown, set to user mode, running */
1282 // List<LttngProcessState> processes = traceSt.getProcesses();
1283 // TmfTimestamp time = trcEvent.getTimestamp();
1285 // for (LttngProcessState process : processes) {
1286 // fix_process(process, time);
1297 * Private method used to establish the first execution state in the stack
1298 * for a given process
1303 // private void fix_process(LttngProcessState process,
1304 // TmfTimestamp timestamp) {
1306 // LttngExecutionState es;
1307 // Stack<LttngExecutionState> procStack = process
1308 // .getExecution_stack();
1310 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1311 // es = procStack.firstElement();
1313 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1314 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1316 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1318 // es.setEntry_Time(timestamp);
1319 // es.setChage_Time(timestamp);
1320 // es.setCum_cpu_time(0L);
1321 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1322 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1326 // es = procStack.firstElement();
1327 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1328 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1330 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1332 // es.setEntry_Time(timestamp);
1333 // es.setChage_Time(timestamp);
1334 // es.setCum_cpu_time(0L);
1335 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1336 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1339 // if (procStack.size() == 1) {
1341 // * Still in bottom unknown mode, means never did a
1342 // * system call May be either in user mode, syscall
1343 // * mode, running or waiting.
1346 // * FIXME : we may be tagging syscall mode when being
1349 // // Get a new execution State
1350 // es = new LttngExecutionState();
1352 // // initialize values
1353 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1355 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1357 // es.setEntry_Time(timestamp);
1358 // es.setChage_Time(timestamp);
1359 // es.setCum_cpu_time(0L);
1360 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1362 // // Push the new state to the stack
1363 // procStack.push(es);
1374 * Handles: LTT_EVENT_PROCESS_STATE
1377 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1378 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1384 final ILttngEventProcessor
getEnumProcessStateHandler() {
1385 AbsStateUpdate handler
= new AbsStateUpdate() {
1389 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1395 // Long cpu = trcEvent.getCpuId();
1396 // LttngProcessState process = traceSt.getRunning_process().get(
1398 // LttngProcessState parent_process;
1400 // // String mode, submode, status;
1401 // LttngExecutionState es;
1404 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1407 // parent_pid = getAFieldLong(trcEvent, traceSt,
1408 // Fields.LTT_FIELD_PARENT_PID);
1410 // /* Command name */
1411 // command = getAFieldString(trcEvent, traceSt,
1412 // Fields.LTT_FIELD_NAME);
1414 // /* TODO: type field, Values need to be verified */
1416 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1417 // Fields.LTT_FIELD_TYPE);
1418 // if (typeVal == 0L) {
1419 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1421 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1424 // // FIXME: type is rarely used, enum must match possible
1428 // // mode = getAFieldString(trcEvent, traceSt,
1429 // // Fields.LTT_FIELD_MODE);
1432 // // submode = getAFieldString(trcEvent, traceSt,
1433 // // Fields.LTT_FIELD_SUBMODE);
1436 // // status = getAFieldString(trcEvent, traceSt,
1437 // // Fields.LTT_FIELD_STATUS);
1440 // tgid = getAFieldLong(trcEvent, traceSt,
1441 // Fields.LTT_FIELD_TGID);
1442 // if (tgid == null) {
1447 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1448 // process = lttv_state_find_process(traceSt, acpu, pid);
1449 // if (process != null) {
1450 // process.setPpid(parent_pid);
1451 // process.setTgid(tgid);
1452 // process.setName(command);
1454 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1456 // StringBuilder sb = new StringBuilder(
1457 // "Unexpected, null process read from the TraceState list of processes, event time: "
1458 // + trcEvent.getTimestamp());
1459 // TraceDebug.debug(sb.toString());
1464 // * The process might exist if a process was forked while
1465 // * performing the state dump.
1467 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1468 // if (process == null) {
1469 // parent_process = lttv_state_find_process(traceSt,
1470 // ANY_CPU, parent_pid);
1471 // process = create_process(traceSt, cpu, pid, tgid,
1472 // command, trcEvent.getTimestamp());
1473 // if (parent_process != null) {
1474 // process.setPpid(parent_process.getPid());
1477 // /* Keep the stack bottom : a running user mode */
1479 // * Disabled because of inconsistencies in the current
1480 // * statedump states.
1482 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1485 // * FIXME Kernel thread : can be in syscall or
1486 // * interrupt or trap.
1489 // * Will cause expected trap when in fact being
1490 // * syscall (even after end of statedump event) Will
1491 // * cause expected interrupt when being syscall.
1492 // * (only before end of statedump event)
1495 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1498 // // es->t = LTTV_STATE_SYSCALL;
1499 // // es->s = status;
1500 // // es->n = submode;
1504 // * User space process : bottom : user mode either
1505 // * currently running or scheduled out. can be
1506 // * scheduled out because interrupted in (user mode
1507 // * or in syscall) or because of an explicit call to
1508 // * the scheduler in syscall. Note that the scheduler
1509 // * call comes after the irq_exit, so never in
1510 // * interrupt context.
1512 // // temp workaround : set size to 1 : only have user
1514 // // bottom of stack.
1515 // // will cause g_info message of expected syscall
1518 // // in user mode. Can also cause expected trap when
1521 // // mode in the event of a page fault reenabling
1523 // // in the handler.
1524 // // Expected syscall and trap can also happen after
1527 // // This will cause a
1528 // // "popping last state on stack, ignoring it."
1530 // // process->execution_stack =
1531 // // g_array_set_size(process->execution_stack, 1);
1532 // // es = process->state =
1533 // // &g_array_index(process->execution_stack,
1534 // // LttvExecutionState, 0);
1535 // // a new process must have only one state in the
1537 // // be the same as the current state
1538 // // es = process.getState();
1539 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1540 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1543 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1544 // // .getInName());
1547 // // es->t = LTTV_STATE_USER_MODE;
1548 // // es->s = status;
1549 // // es->n = submode;
1552 // // TODO: clean up comments above: Moved repeated code
1554 // // if / else blocks above,
1555 // // comments left temporarily for easier visualization
1557 // // comparision with c code
1558 // es = process.getState();
1559 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1560 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1562 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1565 // // /* UNKNOWN STATE */
1567 // // es = process->state =
1568 // // &g_array_index(process->execution_stack,
1569 // // LttvExecutionState, 1);
1570 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1571 // // es->s = LTTV_STATE_UNNAMED;
1572 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1577 // * The process has already been created : Probably was
1578 // * forked while dumping the process state or was simply
1579 // * scheduled in prior to get the state dump event.
1581 // process.setPpid(parent_pid);
1582 // process.setTgid(tgid);
1583 // process.setName(command);
1584 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1587 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1589 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1593 // // &g_array_index(process->execution_stack,
1594 // // LttvExecutionState,
1597 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1598 // // if(type == LTTV_STATE_KERNEL_THREAD)
1599 // // es->t = LTTV_STATE_SYSCALL;
1601 // // es->t = LTTV_STATE_USER_MODE;
1605 // * Don't mess around with the stack, it will eventually
1606 // * become ok after the end of state dump.