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
.before
;
14 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
15 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
16 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionMode
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionSubMode
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.Fields
;
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 StateBeforeUpdateHandlers
{
34 final ILttngEventProcessor
getSyscallEntryHandler() {
35 AbsStateUpdate handler
= new AbsStateUpdate() {
39 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
40 // TraceDebug.debug("Before event called");
42 Long cpu
= trcEvent
.getCpuId();
44 // No syscall_entry update for initialization process
45 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
47 pid
= process
.getPid();
52 // Get the expected event field
53 Long syscall
= getAFieldLong(trcEvent
, traceSt
,
54 Fields
.LTT_FIELD_SYSCALL_ID
);
55 if (syscall
== null) {
56 TraceDebug
.debug("Syscall Field not found in Event: "
57 + trcEvent
.getMarkerName());
61 String submode
= traceSt
.getSyscall_names().get(syscall
);
63 if (submode
== null) {
64 TraceDebug
.debug("Submode not found in Event");
65 submode
= ExecutionSubMode
.LTTV_STATE_SUBMODE_UNKNOWN
69 exState
= new LttngExecutionState();
70 exState
.setExec_mode(ExecutionMode
.LTTV_STATE_SYSCALL
);
71 exState
.setExec_submode(submode
);
72 exState
.setEntry_Time(trcEvent
.getTimestamp().getValue());
73 exState
.setChange_Time(trcEvent
.getTimestamp().getValue());
74 exState
.setCum_cpu_time(0L);
82 final ILttngEventProcessor
getsySyscallExitHandler() {
83 AbsStateUpdate handler
= new AbsStateUpdate() {
87 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
89 Long cpu
= trcEvent
.getCpuId();
90 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
92 /* There can be no system call from PID 0 : unknown state */
93 pid
= process
.getPid();
98 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
99 // traceSt, trcEvent.getTimestamp());
108 * Update stacks related to the parsing of an LttngEvent
112 final ILttngEventProcessor
getTrapEntryHandler() {
113 AbsStateUpdate handler
= new AbsStateUpdate() {
117 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
118 // Long cpu = trcEvent.getCpuId();
120 // Long trap = getAFieldLong(trcEvent, traceSt,
121 // Fields.LTT_FIELD_TRAP_ID);
122 // if (trap == null) {
126 // String submode = traceSt.getSyscall_names()
129 // if (submode == null) {
130 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
134 // /* update process state */
135 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
136 // submode, trcEvent.getTimestamp(), traceSt);
138 // /* update cpu status */
139 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
140 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
141 // cpust.setLast_trap(trap); /* update trap status */
143 // // update Trap State
144 // LttngTrapState trap_state = traceSt.getTrap_states().get(
146 // trap_state.incrementRunning();
159 final ILttngEventProcessor
getTrapExitHandler() {
160 AbsStateUpdate handler
= new AbsStateUpdate() {
164 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
166 // Long cpu = trcEvent.getCpuId();
167 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
168 // Long trap = cpust.getLast_trap();
170 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
174 // /* update cpu status */
175 // cpu_pop_mode(cpust);
177 // /* update trap status */
178 // if (trap != -1L) {
179 // traceSt.getTrap_states().get(trap).decrementRunning();
192 final ILttngEventProcessor
getIrqEntryHandler() {
193 AbsStateUpdate handler
= new AbsStateUpdate() {
197 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
199 // Long cpu = trcEvent.getCpuId();
201 // Long irq = getAFieldLong(trcEvent, traceSt,
202 // Fields.LTT_FIELD_IRQ_ID);
203 // if (irq == null) {
208 // submode = traceSt.getIrq_names().get(irq);
210 // if (submode == null) {
212 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
216 // * Do something with the info about being in user or system
220 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
222 // .getTimestamp(), traceSt);
224 // /* update cpu state */
225 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
226 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
227 // cpust.setLast_irq(irq); /* last irq */
229 // /* udpate irq state */
230 // irq_push_mode(traceSt.getIrq_states().get(irq),
231 // IRQMode.LTTV_IRQ_BUSY);
243 final ILttngEventProcessor
getSoftIrqExitHandler() {
244 AbsStateUpdate handler
= new AbsStateUpdate() {
248 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
250 // Long cpu = trcEvent.getCpuId();
251 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
252 // Long softirq = cpust.getLast_soft_irq();
253 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
254 // trcEvent.getTimestamp());
256 // /* update softirq status */
257 // if (softirq != -1) {
258 // LttngSoftIRQState softIrqstate = traceSt
259 // .getSoft_irq_states().get(softirq);
260 // softIrqstate.decrementRunning();
263 // /* update cpu status */
264 // cpu_pop_mode(cpust);
276 final ILttngEventProcessor
getIrqExitHandler() {
277 AbsStateUpdate handler
= new AbsStateUpdate() {
281 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
283 // Long cpu = trcEvent.getCpuId();
285 // /* update process state */
286 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
290 // /* update cpu status */
291 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
292 // cpu_pop_mode(cpust);
294 // /* update irq status */
295 // Long last_irq = cpust.getLast_irq();
296 // if (last_irq != -1L) {
297 // LttngIRQState irq_state = traceSt.getIrq_states().get(
299 // irq_pop_mode(irq_state);
313 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
314 AbsStateUpdate handler
= new AbsStateUpdate() {
318 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
320 // // Long cpu = trcEvent.getCpuId();
322 // // get event field
323 // Long softirq = getAFieldLong(trcEvent, traceSt,
324 // Fields.LTT_FIELD_SOFT_IRQ_ID);
326 // if (softirq == null) {
330 // // String submode;
331 // // String[] softIrqNames = traceSt.getSoft_irq_names();
332 // // if (softirq < softIrqNames.length) {
333 // // submode = softIrqNames[softirq];
335 // // submode = "softirq " + softirq;
338 // /* update softirq status */
339 // /* a soft irq raises are not cumulative */
340 // LttngSoftIRQState irqState =
341 // traceSt.getSoft_irq_states().get(
343 // if (irqState != null) {
344 // irqState.setPending(1L);
347 // .debug("unexpected soft irq id value: " + softirq);
361 final ILttngEventProcessor
getSoftIrqEntryHandler() {
362 AbsStateUpdate handler
= new AbsStateUpdate() {
366 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
369 // Long cpu = trcEvent.getCpuId();
371 // // get event field
372 // Long softirq = getAFieldLong(trcEvent, traceSt,
373 // Fields.LTT_FIELD_SOFT_IRQ_ID);
375 // if (softirq == null) {
380 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
381 // String submode = softIrqNames.get(softirq);
382 // if (submode == null) {
383 // submode = "softirq " + softirq;
384 // softIrqNames.put(softirq, submode);
387 // /* update softirq status */
388 // LttngSoftIRQState irqState =
389 // traceSt.getSoft_irq_states().get(
391 // if (irqState != null) {
392 // irqState.decrementPending();
393 // irqState.incrementRunning();
396 // .debug("unexpected soft irq id value: " + softirq);
399 // /* update cpu state */
400 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
401 // cpu_state.setLast_soft_irq(softirq);
402 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
404 // /* update process execution mode state stack */
405 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
406 // trcEvent.getTimestamp(), traceSt);
416 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
420 final ILttngEventProcessor
getEnumInterruptHandler() {
421 AbsStateUpdate handler
= new AbsStateUpdate() {
425 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
426 // String action = getAFieldString(trcEvent, traceSt,
427 // Fields.LTT_FIELD_ACTION);
428 // Long irq = getAFieldLong(trcEvent, traceSt,
429 // Fields.LTT_FIELD_IRQ_ID);
431 // Map<Long, String> irq_names = traceSt.getIrq_names();
433 // irq_names.put(irq, action);
442 * Handle the event LTT_EVENT_REQUEST_ISSUE
446 final ILttngEventProcessor
getBdevRequestIssueHandler() {
447 AbsStateUpdate handler
= new AbsStateUpdate() {
451 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
454 // Long major = getAFieldLong(trcEvent, traceSt,
455 // Fields.LTT_FIELD_MAJOR);
456 // Long minor = getAFieldLong(trcEvent, traceSt,
457 // Fields.LTT_FIELD_MINOR);
458 // Long operation = getAFieldLong(trcEvent, traceSt,
459 // Fields.LTT_FIELD_OPERATION);
461 // // calculate bdevcode
462 // Long devcode = mkdev(major, minor);
464 // if (devcode == null) {
466 // .debug("incorrect calcualtion of bdevcode input( major: "
470 // + " operation: " + operation);
474 // Map<Long, LttngBdevState> bdev_states = traceSt
475 // .getBdev_states();
476 // // Get the instance
477 // LttngBdevState bdevState = bdev_states.get(devcode);
478 // if (bdevState == null) {
479 // bdevState = new LttngBdevState();
482 // // update the mode in the stack
483 // if (operation == 0L) {
484 // bdevState.getMode_stack().push(
485 // BdevMode.LTTV_BDEV_BUSY_READING);
487 // bdevState.getMode_stack().push(
488 // BdevMode.LTTV_BDEV_BUSY_WRITING);
491 // // make sure it is included in the set
492 // bdev_states.put(devcode, bdevState);
502 * Handling event: LTT_EVENT_REQUEST_COMPLETE
505 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
510 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
511 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() {
571 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
572 // Long cpu = trcEvent.getCpuId();
573 // Long funcptr = getAFieldLong(trcEvent, traceSt,
574 // Fields.LTT_FIELD_THIS_FN);
576 // push_function(traceSt, funcptr, cpu);
588 final ILttngEventProcessor
getFunctionExitHandler() {
589 AbsStateUpdate handler
= new AbsStateUpdate() {
593 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
595 // Long funcptr = getAFieldLong(trcEvent, traceSt,
596 // Fields.LTT_FIELD_THIS_FN);
598 // pop_function(traceSt, trcEvent, funcptr);
608 * process event: LTT_EVENT_SYS_CALL_TABLE
611 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
616 final ILttngEventProcessor
getDumpSyscallHandler() {
617 AbsStateUpdate handler
= new AbsStateUpdate() {
621 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
622 // // obtain the syscall id
623 // Long id = getAFieldLong(trcEvent, traceSt,
624 // Fields.LTT_FIELD_ID);
626 // // Long address = getAFieldLong(trcEvent, traceSt,
627 // // Fields.LTT_FIELD_ADDRESS);
629 // // Obtain the symbol
630 // String symbol = getAFieldString(trcEvent, traceSt,
631 // Fields.LTT_FIELD_SYMBOL);
633 // // fill the symbol to the sycall_names collection
634 // traceSt.getSyscall_names().put(id, symbol);
644 * Handles event: LTT_EVENT_KPROBE_TABLE
647 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
652 final ILttngEventProcessor
getDumpKprobeHandler() {
653 AbsStateUpdate handler
= new AbsStateUpdate() {
657 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
659 // Long ip = getAFieldLong(trcEvent, traceSt,
660 // Fields.LTT_FIELD_IP);
661 // String symbol = getAFieldString(trcEvent, traceSt,
662 // Fields.LTT_FIELD_SYMBOL);
664 // traceSt.getKprobe_table().put(ip, symbol);
675 * Handles: LTT_EVENT_SOFTIRQ_VEC
678 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
683 final ILttngEventProcessor
getDumpSoftIrqHandler() {
684 AbsStateUpdate handler
= new AbsStateUpdate() {
688 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
691 // Long id = getAFieldLong(trcEvent, traceSt,
692 // Fields.LTT_FIELD_ID);
694 // // Address not needed
695 // // Long address = ltt_event_get_long_unsigned(e,
696 // // lttv_trace_get_hook_field(th,
700 // String symbol = getAFieldString(trcEvent, traceSt,
701 // Fields.LTT_FIELD_SYMBOL);
703 // // Register the soft irq name
704 // traceSt.getSoft_irq_names().put(id, symbol);
714 * Handles: LTT_EVENT_SCHED_SCHEDULE
717 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
722 final ILttngEventProcessor
getSchedChangeHandler() {
723 AbsStateUpdate handler
= new AbsStateUpdate() {
727 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
729 // Long cpu = trcEvent.getCpuId();
730 // TmfTimestamp eventTime = trcEvent.getTimestamp();
732 // LttngProcessState process = traceSt.getRunning_process().get(
735 // Long pid_out = getAFieldLong(trcEvent, traceSt,
736 // Fields.LTT_FIELD_PREV_PID);
737 // Long pid_in = getAFieldLong(trcEvent, traceSt,
738 // Fields.LTT_FIELD_NEXT_PID);
739 // Long state_out = getAFieldLong(trcEvent, traceSt,
740 // Fields.LTT_FIELD_PREV_STATE);
742 // if (process != null) {
745 // * We could not know but it was not the idle process
746 // * executing. This should only happen at the beginning,
747 // * before the first schedule event, and when the initial
748 // * information (current process for each CPU) is missing. It
749 // * is not obvious how we could, after the fact, compensate
750 // * the wrongly attributed statistics.
753 // // This test only makes sense once the state is known and if
756 // // missing events. We need to silently ignore schedchange
759 // // process_free, or it causes glitches. (FIXME)
760 // // if(unlikely(process->pid != pid_out)) {
761 // // g_assert(process->pid == 0);
763 // if (process.getPid() == 0
764 // && process.getState().getExec_mode() ==
765 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
766 // if (pid_out == 0) {
768 // * Scheduling out of pid 0 at beginning of the trace
769 // * : we know for sure it is in syscall mode at this
772 // int stackSize = process.getExecution_stack().size();
773 // if (stackSize != 1) {
775 // .debug("unpexpected process execution stack size, expected 1, received: ");
778 // process.getState().setExec_mode(
779 // ExecutionMode.LTTV_STATE_SYSCALL);
780 // process.getState().setProc_status(
781 // ProcessStatus.LTTV_STATE_WAIT);
782 // process.getState().setChage_Time(
783 // trcEvent.getTimestamp());
784 // process.getState().setEntry_Time(
785 // trcEvent.getTimestamp());
788 // if (process.getState().getProc_status() ==
789 // ProcessStatus.LTTV_STATE_EXIT) {
790 // process.getState().setProc_status(
791 // ProcessStatus.LTTV_STATE_ZOMBIE);
792 // process.getState().setChage_Time(
793 // trcEvent.getTimestamp());
795 // if (state_out == 0L) {
796 // process.getState().setProc_status(
797 // ProcessStatus.LTTV_STATE_WAIT_CPU);
799 // process.getState().setProc_status(
800 // ProcessStatus.LTTV_STATE_WAIT);
803 // process.getState().setChage_Time(
804 // trcEvent.getTimestamp());
807 // if (state_out == 32L || state_out == 64L) { /*
812 // /* see sched.h for states */
813 // if (!exit_process(traceSt, process)) {
814 // process.getState().setProc_status(
815 // ProcessStatus.LTTV_STATE_DEAD);
816 // process.getState().setChage_Time(
817 // trcEvent.getTimestamp());
822 // process = lttv_state_find_process_or_create(traceSt, cpu,
823 // pid_in, eventTime);
825 // traceSt.getRunning_process().put(cpu, process);
827 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
828 // process.getState().setChage_Time(eventTime);
829 // process.setCpu(cpu);
830 // // process->state->s = LTTV_STATE_RUN;
831 // // if(process->usertrace)
832 // // process->usertrace->cpu = cpu;
833 // // process->last_cpu_index =
834 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
836 // // process->state->change = s->parent.timestamp;
838 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
839 // /* update cpu status */
840 // if (pid_in == 0) {
842 // /* going to idle task */
843 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
846 // * scheduling a real task. we must be careful here: if we
847 // * just schedule()'ed to a process that is in a trap, we
848 // * must put the cpu in trap mode
850 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
851 // if (process.getState().getExec_mode() ==
852 // ExecutionMode.LTTV_STATE_TRAP) {
853 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
865 * Handles: LTT_EVENT_PROCESS_FORK
868 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
869 * LTT_FIELD_CHILD_TGID)
874 final ILttngEventProcessor
getProcessForkHandler() {
875 AbsStateUpdate handler
= new AbsStateUpdate() {
879 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
881 // Long cpu = trcEvent.getCpuId();
882 // LttngProcessState process = traceSt.getRunning_process().get(
884 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
886 // // /* Parent PID */
887 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
888 // // Fields.LTT_FIELD_PARENT_PID);
891 // /* In the Linux Kernel, there is one PID per thread. */
892 // Long child_pid = getAFieldLong(trcEvent, traceSt,
893 // Fields.LTT_FIELD_CHILD_PID);
896 // /* tgid in the Linux kernel is the "real" POSIX PID. */
897 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
898 // Fields.LTT_FIELD_CHILD_TGID);
899 // if (child_tgid == null) {
904 // * Mathieu : it seems like the process might have been
906 // * in before the fork, and, in a rare case, might be the
908 // * process. This might happen in a SMP case where we don't
910 // * enough precision on the clocks.
912 // * Test reenabled after precision fixes on time. (Mathieu)
915 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
918 // // if(unlikely(zombie_process != NULL)) {
919 // // /* Reutilisation of PID. Only now we are sure that the old
921 // // * has been released. FIXME : should know when release_task
925 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
927 // // for(i=0; i< num_cpus; i++) {
928 // // g_assert(zombie_process != ts->running_process[i]);
931 // // exit_process(s, zombie_process);
935 // if (process.getPid() == child_pid) {
937 // .debug("Unexpected, process pid equal to child pid: "
940 // + trcEvent.getTimestamp());
943 // // g_assert(process->pid != child_pid);
944 // // FIXME : Add this test in the "known state" section
945 // // g_assert(process->pid == parent_pid);
946 // LttngProcessState child_process = lttv_state_find_process(
947 // traceSt, ANY_CPU, child_pid);
948 // if (child_process == null) {
949 // child_process = create_process(traceSt, cpu, child_pid,
950 // child_tgid, timeStamp);
953 // * The process has already been created : due to time
954 // * imprecision between multiple CPUs : it has been scheduled
955 // * in before creation. Note that we shouldn't have this kind
958 // * Simply put a correct parent.
960 // StringBuilder sb = new StringBuilder("Process " + child_pid);
961 // sb.append(" has been created at ["
962 // + child_process.getCration_time() + "] ");
963 // sb.append("and inserted at ["
964 // + child_process.getInsertion_time() + "] ");
965 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
966 // + trcEvent + "]\n.");
968 // .append("Probably an unsynchronized TSD problem on the traced machine.");
969 // TraceDebug.debug(sb.toString());
971 // // g_assert(0); /* This is a problematic case : the process
974 // // before the fork event */
975 // child_process.setPpid(process.getPid());
976 // child_process.setTgid(child_tgid);
979 // if (!child_process.getName().equals(
980 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
981 // TraceDebug.debug("Unexpected child process status: "
982 // + child_process.getName());
985 // child_process.setName(process.getName());
986 // child_process.setBrand(process.getBrand());
997 * Handles: LTT_EVENT_KTHREAD_CREATE
1000 * Fields: LTT_FIELD_PID
1005 final ILttngEventProcessor
getProcessKernelThreadHandler() {
1006 AbsStateUpdate handler
= new AbsStateUpdate() {
1010 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1012 // * We stamp a newly created process as kernel_thread. The
1014 // * should not be running yet.
1017 // LttngExecutionState exState;
1019 // LttngProcessState process;
1022 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1023 // // s->parent.target_pid = pid;
1025 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1026 // pid, new TmfTimestamp());
1028 // if (!process.getState().getProc_status().equals(
1029 // ProcessStatus.LTTV_STATE_DEAD)) {
1030 // // Leave only the first element in the stack with execution
1033 // Stack<LttngExecutionState> processExStack = process
1034 // .getExecution_stack();
1035 // exState = processExStack.firstElement();
1036 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1037 // if (processExStack.size() > 1) {
1038 // processExStack.clear();
1039 // processExStack.add(exState);
1042 // // update the process state to the only one in the stack
1043 // process.setState(exState);
1046 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1057 * Handles: LTT_EVENT_PROCESS_EXIT
1065 final ILttngEventProcessor
getProcessExitHandler() {
1066 AbsStateUpdate handler
= new AbsStateUpdate() {
1070 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1073 // LttngProcessState process;
1075 // pid = getAFieldLong(trcEvent, traceSt,
1076 // Fields.LTT_FIELD_PID);
1077 // // s->parent.target_pid = pid;
1079 // // FIXME : Add this test in the "known state" section
1080 // // g_assert(process->pid == pid);
1082 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1083 // if (process != null) {
1084 // process.getState().setProc_status(
1085 // ProcessStatus.LTTV_STATE_EXIT);
1096 * Handles: LTT_EVENT_PROCESS_FREE
1099 * Fields: LTT_FIELD_PID
1104 final ILttngEventProcessor
getProcessFreeHandler() {
1105 AbsStateUpdate handler
= new AbsStateUpdate() {
1109 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1111 // Long release_pid;
1112 // LttngProcessState process;
1114 // /* PID of the process to release */
1115 // release_pid = getAFieldLong(trcEvent, traceSt,
1116 // Fields.LTT_FIELD_PID);
1117 // // s->parent.target_pid = release_pid;
1119 // if (release_pid == 0) {
1120 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1121 // + trcEvent.getTimestamp());
1124 // process = lttv_state_find_process(traceSt, ANY_CPU,
1126 // if (process != null) {
1127 // exit_process(traceSt, process);
1132 // if(process != null) {
1134 * release_task is happening at kernel level : we can now safely
1135 * release the data structure of the process
1137 // This test is fun, though, as it may happen that
1138 // at time t : CPU 0 : process_free
1139 // at time t+150ns : CPU 1 : schedule out
1140 // Clearly due to time imprecision, we disable it. (Mathieu)
1141 // If this weird case happen, we have no choice but to put the
1142 // Currently running process on the cpu to 0.
1143 // I re-enable it following time precision fixes. (Mathieu)
1144 // Well, in the case where an process is freed by a process on
1147 // and still scheduled, it happens that this is the schedchange
1150 // drop the last reference count. Do not free it here!
1152 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1154 // for(i=0; i< num_cpus; i++) {
1155 // //g_assert(process != ts->running_process[i]);
1156 // if(process == ts->running_process[i]) {
1157 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1161 // if(i == num_cpus) /* process is not scheduled */
1162 // exit_process(s, process);
1174 * Handles: LTT_EVENT_EXEC
1177 * FIELDS: LTT_FIELD_FILENAME
1182 final ILttngEventProcessor
getProcessExecHandler() {
1183 AbsStateUpdate handler
= new AbsStateUpdate() {
1187 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1189 // Long cpu = trcEvent.getCpuId();
1190 // LttngProcessState process = traceSt.getRunning_process().get(
1193 // // #if 0//how to use a sequence that must be transformed in a
1195 // // /* PID of the process to release */
1196 // // guint64 name_len = ltt_event_field_element_number(e,
1197 // // lttv_trace_get_hook_field(th, 0));
1198 // // //name = ltt_event_get_string(e,
1199 // // lttv_trace_get_hook_field(th, 0));
1200 // // LttField *child = ltt_event_field_element_select(e,
1201 // // lttv_trace_get_hook_field(th, 0), 0);
1202 // // gchar *name_begin =
1203 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1205 // // gchar *null_term_name = g_new(gchar, name_len+1);
1206 // // memcpy(null_term_name, name_begin, name_len);
1207 // // null_term_name[name_len] = '\0';
1208 // // process->name = g_quark_from_string(null_term_name);
1211 // process.setName(getAFieldString(trcEvent, traceSt,
1212 // Fields.LTT_FIELD_FILENAME));
1213 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1223 * LTT_EVENT_THREAD_BRAND
1226 * FIELDS: LTT_FIELD_NAME
1231 final ILttngEventProcessor
GetThreadBrandHandler() {
1232 AbsStateUpdate handler
= new AbsStateUpdate() {
1236 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1239 // Long cpu = trcEvent.getCpuId();
1240 // LttngProcessState process = traceSt.getRunning_process().get(
1243 // name = getAFieldString(trcEvent, traceSt,
1244 // Fields.LTT_FIELD_NAME);
1245 // process.setBrand(name);
1256 final ILttngEventProcessor
getStateDumpEndHandler() {
1257 AbsStateUpdate handler
= new AbsStateUpdate() {
1261 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1263 // /* For all processes */
1265 // * if kernel thread, if stack[0] is unknown, set to syscall
1268 // /* else, if stack[0] is unknown, set to user mode, running */
1269 // List<LttngProcessState> processes = traceSt.getProcesses();
1270 // TmfTimestamp time = trcEvent.getTimestamp();
1272 // for (LttngProcessState process : processes) {
1273 // fix_process(process, time);
1284 * Private method used to establish the first execution state in the stack
1285 * for a given process
1290 // private void fix_process(LttngProcessState process,
1291 // TmfTimestamp timestamp) {
1293 // LttngExecutionState es;
1294 // Stack<LttngExecutionState> procStack = process
1295 // .getExecution_stack();
1297 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1298 // es = procStack.firstElement();
1300 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1301 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1303 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1305 // es.setEntry_Time(timestamp);
1306 // es.setChage_Time(timestamp);
1307 // es.setCum_cpu_time(0L);
1308 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1309 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1313 // es = procStack.firstElement();
1314 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1315 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1317 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1319 // es.setEntry_Time(timestamp);
1320 // es.setChage_Time(timestamp);
1321 // es.setCum_cpu_time(0L);
1322 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1323 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1326 // if (procStack.size() == 1) {
1328 // * Still in bottom unknown mode, means never did a
1329 // * system call May be either in user mode, syscall
1330 // * mode, running or waiting.
1333 // * FIXME : we may be tagging syscall mode when being
1336 // // Get a new execution State
1337 // es = new LttngExecutionState();
1339 // // initialize values
1340 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1342 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1344 // es.setEntry_Time(timestamp);
1345 // es.setChage_Time(timestamp);
1346 // es.setCum_cpu_time(0L);
1347 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1349 // // Push the new state to the stack
1350 // procStack.push(es);
1361 * Handles: LTT_EVENT_PROCESS_STATE
1364 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1365 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1371 final ILttngEventProcessor
getEnumProcessStateHandler() {
1372 AbsStateUpdate handler
= new AbsStateUpdate() {
1376 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1382 // Long cpu = trcEvent.getCpuId();
1383 // LttngProcessState process = traceSt.getRunning_process().get(
1385 // LttngProcessState parent_process;
1387 // // String mode, submode, status;
1388 // LttngExecutionState es;
1391 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1394 // parent_pid = getAFieldLong(trcEvent, traceSt,
1395 // Fields.LTT_FIELD_PARENT_PID);
1397 // /* Command name */
1398 // command = getAFieldString(trcEvent, traceSt,
1399 // Fields.LTT_FIELD_NAME);
1401 // /* TODO: type field, Values need to be verified */
1403 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1404 // Fields.LTT_FIELD_TYPE);
1405 // if (typeVal == 0L) {
1406 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1408 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1411 // // FIXME: type is rarely used, enum must match possible
1415 // // mode = getAFieldString(trcEvent, traceSt,
1416 // // Fields.LTT_FIELD_MODE);
1419 // // submode = getAFieldString(trcEvent, traceSt,
1420 // // Fields.LTT_FIELD_SUBMODE);
1423 // // status = getAFieldString(trcEvent, traceSt,
1424 // // Fields.LTT_FIELD_STATUS);
1427 // tgid = getAFieldLong(trcEvent, traceSt,
1428 // Fields.LTT_FIELD_TGID);
1429 // if (tgid == null) {
1434 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1435 // process = lttv_state_find_process(traceSt, acpu, pid);
1436 // if (process != null) {
1437 // process.setPpid(parent_pid);
1438 // process.setTgid(tgid);
1439 // process.setName(command);
1441 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1443 // StringBuilder sb = new StringBuilder(
1444 // "Unexpected, null process read from the TraceState list of processes, event time: "
1445 // + trcEvent.getTimestamp());
1446 // TraceDebug.debug(sb.toString());
1451 // * The process might exist if a process was forked while
1452 // * performing the state dump.
1454 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1455 // if (process == null) {
1456 // parent_process = lttv_state_find_process(traceSt,
1457 // ANY_CPU, parent_pid);
1458 // process = create_process(traceSt, cpu, pid, tgid,
1459 // command, trcEvent.getTimestamp());
1460 // if (parent_process != null) {
1461 // process.setPpid(parent_process.getPid());
1464 // /* Keep the stack bottom : a running user mode */
1466 // * Disabled because of inconsistencies in the current
1467 // * statedump states.
1469 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1472 // * FIXME Kernel thread : can be in syscall or
1473 // * interrupt or trap.
1476 // * Will cause expected trap when in fact being
1477 // * syscall (even after end of statedump event) Will
1478 // * cause expected interrupt when being syscall.
1479 // * (only before end of statedump event)
1482 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1485 // // es->t = LTTV_STATE_SYSCALL;
1486 // // es->s = status;
1487 // // es->n = submode;
1491 // * User space process : bottom : user mode either
1492 // * currently running or scheduled out. can be
1493 // * scheduled out because interrupted in (user mode
1494 // * or in syscall) or because of an explicit call to
1495 // * the scheduler in syscall. Note that the scheduler
1496 // * call comes after the irq_exit, so never in
1497 // * interrupt context.
1499 // // temp workaround : set size to 1 : only have user
1501 // // bottom of stack.
1502 // // will cause g_info message of expected syscall
1505 // // in user mode. Can also cause expected trap when
1508 // // mode in the event of a page fault reenabling
1510 // // in the handler.
1511 // // Expected syscall and trap can also happen after
1514 // // This will cause a
1515 // // "popping last state on stack, ignoring it."
1517 // // process->execution_stack =
1518 // // g_array_set_size(process->execution_stack, 1);
1519 // // es = process->state =
1520 // // &g_array_index(process->execution_stack,
1521 // // LttvExecutionState, 0);
1522 // // a new process must have only one state in the
1524 // // be the same as the current state
1525 // // es = process.getState();
1526 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1527 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1530 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1531 // // .getInName());
1534 // // es->t = LTTV_STATE_USER_MODE;
1535 // // es->s = status;
1536 // // es->n = submode;
1539 // // TODO: clean up comments above: Moved repeated code
1541 // // if / else blocks above,
1542 // // comments left temporarily for easier visualization
1544 // // comparision with c code
1545 // es = process.getState();
1546 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1547 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1549 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1552 // // /* UNKNOWN STATE */
1554 // // es = process->state =
1555 // // &g_array_index(process->execution_stack,
1556 // // LttvExecutionState, 1);
1557 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1558 // // es->s = LTTV_STATE_UNNAMED;
1559 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1564 // * The process has already been created : Probably was
1565 // * forked while dumping the process state or was simply
1566 // * scheduled in prior to get the state dump event.
1568 // process.setPpid(parent_pid);
1569 // process.setTgid(tgid);
1570 // process.setName(command);
1571 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1574 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1576 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1580 // // &g_array_index(process->execution_stack,
1581 // // LttvExecutionState,
1584 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1585 // // if(type == LTTV_STATE_KERNEL_THREAD)
1586 // // es->t = LTTV_STATE_SYSCALL;
1588 // // es->t = LTTV_STATE_USER_MODE;
1592 // * Don't mess around with the stack, it will eventually
1593 // * become ok after the end of state dump.