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(
48 pid
= process
.getPid();
53 // Get the expected event field
54 Long syscall
= getAFieldLong(trcEvent
, traceSt
,
55 Fields
.LTT_FIELD_SYSCALL_ID
);
56 if (syscall
== null) {
57 TraceDebug
.debug("Syscall Field not found in Event: "
58 + trcEvent
.getMarkerName());
62 String submode
= traceSt
.getSyscall_names().get(syscall
);
64 if (submode
== null) {
65 TraceDebug
.debug("Submode not found in Event");
66 submode
= ExecutionSubMode
.LTTV_STATE_SUBMODE_UNKNOWN
70 exState
= new LttngExecutionState();
71 exState
.setExec_mode(ExecutionMode
.LTTV_STATE_SYSCALL
);
72 exState
.setExec_submode(submode
);
73 exState
.setEntry_Time(trcEvent
.getTimestamp().getValue());
74 exState
.setChange_Time(trcEvent
.getTimestamp().getValue());
75 exState
.setCum_cpu_time(0L);
83 final ILttngEventProcessor
getsySyscallExitHandler() {
84 AbsStateUpdate handler
= new AbsStateUpdate() {
88 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
90 Long cpu
= trcEvent
.getCpuId();
91 LttngProcessState process
= traceSt
.getRunning_process().get(
94 /* There can be no system call from PID 0 : unknown state */
95 pid
= process
.getPid();
100 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
101 // traceSt, trcEvent.getTimestamp());
110 * Update stacks related to the parsing of an LttngEvent
114 final ILttngEventProcessor
getTrapEntryHandler() {
115 AbsStateUpdate handler
= new AbsStateUpdate() {
119 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
120 // Long cpu = trcEvent.getCpuId();
122 // Long trap = getAFieldLong(trcEvent, traceSt,
123 // Fields.LTT_FIELD_TRAP_ID);
124 // if (trap == null) {
128 // String submode = traceSt.getSyscall_names()
131 // if (submode == null) {
132 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
136 // /* update process state */
137 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
138 // submode, trcEvent.getTimestamp(), traceSt);
140 // /* update cpu status */
141 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
142 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
143 // cpust.setLast_trap(trap); /* update trap status */
145 // // update Trap State
146 // LttngTrapState trap_state = traceSt.getTrap_states().get(
148 // trap_state.incrementRunning();
161 final ILttngEventProcessor
getTrapExitHandler() {
162 AbsStateUpdate handler
= new AbsStateUpdate() {
166 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
168 // Long cpu = trcEvent.getCpuId();
169 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
170 // Long trap = cpust.getLast_trap();
172 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
176 // /* update cpu status */
177 // cpu_pop_mode(cpust);
179 // /* update trap status */
180 // if (trap != -1L) {
181 // traceSt.getTrap_states().get(trap).decrementRunning();
194 final ILttngEventProcessor
getIrqEntryHandler() {
195 AbsStateUpdate handler
= new AbsStateUpdate() {
199 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
201 // Long cpu = trcEvent.getCpuId();
203 // Long irq = getAFieldLong(trcEvent, traceSt,
204 // Fields.LTT_FIELD_IRQ_ID);
205 // if (irq == null) {
210 // submode = traceSt.getIrq_names().get(irq);
212 // if (submode == null) {
214 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
218 // * Do something with the info about being in user or system
222 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
224 // .getTimestamp(), traceSt);
226 // /* update cpu state */
227 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
228 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
229 // cpust.setLast_irq(irq); /* last irq */
231 // /* udpate irq state */
232 // irq_push_mode(traceSt.getIrq_states().get(irq),
233 // IRQMode.LTTV_IRQ_BUSY);
245 final ILttngEventProcessor
getSoftIrqExitHandler() {
246 AbsStateUpdate handler
= new AbsStateUpdate() {
250 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
252 // Long cpu = trcEvent.getCpuId();
253 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
254 // Long softirq = cpust.getLast_soft_irq();
255 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
256 // trcEvent.getTimestamp());
258 // /* update softirq status */
259 // if (softirq != -1) {
260 // LttngSoftIRQState softIrqstate = traceSt
261 // .getSoft_irq_states().get(softirq);
262 // softIrqstate.decrementRunning();
265 // /* update cpu status */
266 // cpu_pop_mode(cpust);
278 final ILttngEventProcessor
getIrqExitHandler() {
279 AbsStateUpdate handler
= new AbsStateUpdate() {
283 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
285 // Long cpu = trcEvent.getCpuId();
287 // /* update process state */
288 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
292 // /* update cpu status */
293 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
294 // cpu_pop_mode(cpust);
296 // /* update irq status */
297 // Long last_irq = cpust.getLast_irq();
298 // if (last_irq != -1L) {
299 // LttngIRQState irq_state = traceSt.getIrq_states().get(
301 // irq_pop_mode(irq_state);
315 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
316 AbsStateUpdate handler
= new AbsStateUpdate() {
320 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
322 // // Long cpu = trcEvent.getCpuId();
324 // // get event field
325 // Long softirq = getAFieldLong(trcEvent, traceSt,
326 // Fields.LTT_FIELD_SOFT_IRQ_ID);
328 // if (softirq == null) {
332 // // String submode;
333 // // String[] softIrqNames = traceSt.getSoft_irq_names();
334 // // if (softirq < softIrqNames.length) {
335 // // submode = softIrqNames[softirq];
337 // // submode = "softirq " + softirq;
340 // /* update softirq status */
341 // /* a soft irq raises are not cumulative */
342 // LttngSoftIRQState irqState =
343 // traceSt.getSoft_irq_states().get(
345 // if (irqState != null) {
346 // irqState.setPending(1L);
349 // .debug("unexpected soft irq id value: " + softirq);
363 final ILttngEventProcessor
getSoftIrqEntryHandler() {
364 AbsStateUpdate handler
= new AbsStateUpdate() {
368 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
371 // Long cpu = trcEvent.getCpuId();
373 // // get event field
374 // Long softirq = getAFieldLong(trcEvent, traceSt,
375 // Fields.LTT_FIELD_SOFT_IRQ_ID);
377 // if (softirq == null) {
382 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
383 // String submode = softIrqNames.get(softirq);
384 // if (submode == null) {
385 // submode = "softirq " + softirq;
386 // softIrqNames.put(softirq, submode);
389 // /* update softirq status */
390 // LttngSoftIRQState irqState =
391 // traceSt.getSoft_irq_states().get(
393 // if (irqState != null) {
394 // irqState.decrementPending();
395 // irqState.incrementRunning();
398 // .debug("unexpected soft irq id value: " + softirq);
401 // /* update cpu state */
402 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
403 // cpu_state.setLast_soft_irq(softirq);
404 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
406 // /* update process execution mode state stack */
407 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
408 // trcEvent.getTimestamp(), traceSt);
418 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
422 final ILttngEventProcessor
getEnumInterruptHandler() {
423 AbsStateUpdate handler
= new AbsStateUpdate() {
427 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
428 // String action = getAFieldString(trcEvent, traceSt,
429 // Fields.LTT_FIELD_ACTION);
430 // Long irq = getAFieldLong(trcEvent, traceSt,
431 // Fields.LTT_FIELD_IRQ_ID);
433 // Map<Long, String> irq_names = traceSt.getIrq_names();
435 // irq_names.put(irq, action);
444 * Handle the event LTT_EVENT_REQUEST_ISSUE
448 final ILttngEventProcessor
getBdevRequestIssueHandler() {
449 AbsStateUpdate handler
= new AbsStateUpdate() {
453 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
456 // Long major = getAFieldLong(trcEvent, traceSt,
457 // Fields.LTT_FIELD_MAJOR);
458 // Long minor = getAFieldLong(trcEvent, traceSt,
459 // Fields.LTT_FIELD_MINOR);
460 // Long operation = getAFieldLong(trcEvent, traceSt,
461 // Fields.LTT_FIELD_OPERATION);
463 // // calculate bdevcode
464 // Long devcode = mkdev(major, minor);
466 // if (devcode == null) {
468 // .debug("incorrect calcualtion of bdevcode input( major: "
472 // + " operation: " + operation);
476 // Map<Long, LttngBdevState> bdev_states = traceSt
477 // .getBdev_states();
478 // // Get the instance
479 // LttngBdevState bdevState = bdev_states.get(devcode);
480 // if (bdevState == null) {
481 // bdevState = new LttngBdevState();
484 // // update the mode in the stack
485 // if (operation == 0L) {
486 // bdevState.getMode_stack().push(
487 // BdevMode.LTTV_BDEV_BUSY_READING);
489 // bdevState.getMode_stack().push(
490 // BdevMode.LTTV_BDEV_BUSY_WRITING);
493 // // make sure it is included in the set
494 // bdev_states.put(devcode, bdevState);
504 * Handling event: LTT_EVENT_REQUEST_COMPLETE
507 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
512 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
513 AbsStateUpdate handler
= new AbsStateUpdate() {
517 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
520 // Long major = getAFieldLong(trcEvent, traceSt,
521 // Fields.LTT_FIELD_MAJOR);
522 // Long minor = getAFieldLong(trcEvent, traceSt,
523 // Fields.LTT_FIELD_MINOR);
524 // Long operation = getAFieldLong(trcEvent, traceSt,
525 // Fields.LTT_FIELD_OPERATION);
527 // // calculate bdevcode
528 // Long devcode = mkdev(major, minor);
530 // if (devcode == null) {
532 // .debug("incorrect calcualtion of bdevcode input( major: "
536 // + " operation: " + operation);
540 // Map<Long, LttngBdevState> bdev_states = traceSt
541 // .getBdev_states();
542 // // Get the instance
543 // LttngBdevState bdevState = bdev_states.get(devcode);
544 // if (bdevState == null) {
545 // bdevState = new LttngBdevState();
548 // /* update block device */
549 // bdev_pop_mode(bdevState);
560 * Handles event: LTT_EVENT_FUNCTION_ENTRY
563 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
568 final ILttngEventProcessor
getFunctionEntryHandler() {
569 AbsStateUpdate handler
= new AbsStateUpdate() {
573 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
574 // Long cpu = trcEvent.getCpuId();
575 // Long funcptr = getAFieldLong(trcEvent, traceSt,
576 // Fields.LTT_FIELD_THIS_FN);
578 // push_function(traceSt, funcptr, cpu);
590 final ILttngEventProcessor
getFunctionExitHandler() {
591 AbsStateUpdate handler
= new AbsStateUpdate() {
595 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
597 // Long funcptr = getAFieldLong(trcEvent, traceSt,
598 // Fields.LTT_FIELD_THIS_FN);
600 // pop_function(traceSt, trcEvent, funcptr);
610 * process event: LTT_EVENT_SYS_CALL_TABLE
613 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
618 final ILttngEventProcessor
getDumpSyscallHandler() {
619 AbsStateUpdate handler
= new AbsStateUpdate() {
623 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
624 // // obtain the syscall id
625 // Long id = getAFieldLong(trcEvent, traceSt,
626 // Fields.LTT_FIELD_ID);
628 // // Long address = getAFieldLong(trcEvent, traceSt,
629 // // Fields.LTT_FIELD_ADDRESS);
631 // // Obtain the symbol
632 // String symbol = getAFieldString(trcEvent, traceSt,
633 // Fields.LTT_FIELD_SYMBOL);
635 // // fill the symbol to the sycall_names collection
636 // traceSt.getSyscall_names().put(id, symbol);
646 * Handles event: LTT_EVENT_KPROBE_TABLE
649 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
654 final ILttngEventProcessor
getDumpKprobeHandler() {
655 AbsStateUpdate handler
= new AbsStateUpdate() {
659 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
661 // Long ip = getAFieldLong(trcEvent, traceSt,
662 // Fields.LTT_FIELD_IP);
663 // String symbol = getAFieldString(trcEvent, traceSt,
664 // Fields.LTT_FIELD_SYMBOL);
666 // traceSt.getKprobe_table().put(ip, symbol);
677 * Handles: LTT_EVENT_SOFTIRQ_VEC
680 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
685 final ILttngEventProcessor
getDumpSoftIrqHandler() {
686 AbsStateUpdate handler
= new AbsStateUpdate() {
690 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
693 // Long id = getAFieldLong(trcEvent, traceSt,
694 // Fields.LTT_FIELD_ID);
696 // // Address not needed
697 // // Long address = ltt_event_get_long_unsigned(e,
698 // // lttv_trace_get_hook_field(th,
702 // String symbol = getAFieldString(trcEvent, traceSt,
703 // Fields.LTT_FIELD_SYMBOL);
705 // // Register the soft irq name
706 // traceSt.getSoft_irq_names().put(id, symbol);
716 * Handles: LTT_EVENT_SCHED_SCHEDULE
719 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
724 final ILttngEventProcessor
getSchedChangeHandler() {
725 AbsStateUpdate handler
= new AbsStateUpdate() {
729 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
731 // Long cpu = trcEvent.getCpuId();
732 // TmfTimestamp eventTime = trcEvent.getTimestamp();
734 // LttngProcessState process = traceSt.getRunning_process().get(
737 // Long pid_out = getAFieldLong(trcEvent, traceSt,
738 // Fields.LTT_FIELD_PREV_PID);
739 // Long pid_in = getAFieldLong(trcEvent, traceSt,
740 // Fields.LTT_FIELD_NEXT_PID);
741 // Long state_out = getAFieldLong(trcEvent, traceSt,
742 // Fields.LTT_FIELD_PREV_STATE);
744 // if (process != null) {
747 // * We could not know but it was not the idle process
748 // * executing. This should only happen at the beginning,
749 // * before the first schedule event, and when the initial
750 // * information (current process for each CPU) is missing. It
751 // * is not obvious how we could, after the fact, compensate
752 // * the wrongly attributed statistics.
755 // // This test only makes sense once the state is known and if
758 // // missing events. We need to silently ignore schedchange
761 // // process_free, or it causes glitches. (FIXME)
762 // // if(unlikely(process->pid != pid_out)) {
763 // // g_assert(process->pid == 0);
765 // if (process.getPid() == 0
766 // && process.getState().getExec_mode() ==
767 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
768 // if (pid_out == 0) {
770 // * Scheduling out of pid 0 at beginning of the trace
771 // * : we know for sure it is in syscall mode at this
774 // int stackSize = process.getExecution_stack().size();
775 // if (stackSize != 1) {
777 // .debug("unpexpected process execution stack size, expected 1, received: ");
780 // process.getState().setExec_mode(
781 // ExecutionMode.LTTV_STATE_SYSCALL);
782 // process.getState().setProc_status(
783 // ProcessStatus.LTTV_STATE_WAIT);
784 // process.getState().setChage_Time(
785 // trcEvent.getTimestamp());
786 // process.getState().setEntry_Time(
787 // trcEvent.getTimestamp());
790 // if (process.getState().getProc_status() ==
791 // ProcessStatus.LTTV_STATE_EXIT) {
792 // process.getState().setProc_status(
793 // ProcessStatus.LTTV_STATE_ZOMBIE);
794 // process.getState().setChage_Time(
795 // trcEvent.getTimestamp());
797 // if (state_out == 0L) {
798 // process.getState().setProc_status(
799 // ProcessStatus.LTTV_STATE_WAIT_CPU);
801 // process.getState().setProc_status(
802 // ProcessStatus.LTTV_STATE_WAIT);
805 // process.getState().setChage_Time(
806 // trcEvent.getTimestamp());
809 // if (state_out == 32L || state_out == 64L) { /*
814 // /* see sched.h for states */
815 // if (!exit_process(traceSt, process)) {
816 // process.getState().setProc_status(
817 // ProcessStatus.LTTV_STATE_DEAD);
818 // process.getState().setChage_Time(
819 // trcEvent.getTimestamp());
824 // process = lttv_state_find_process_or_create(traceSt, cpu,
825 // pid_in, eventTime);
827 // traceSt.getRunning_process().put(cpu, process);
829 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
830 // process.getState().setChage_Time(eventTime);
831 // process.setCpu(cpu);
832 // // process->state->s = LTTV_STATE_RUN;
833 // // if(process->usertrace)
834 // // process->usertrace->cpu = cpu;
835 // // process->last_cpu_index =
836 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
838 // // process->state->change = s->parent.timestamp;
840 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
841 // /* update cpu status */
842 // if (pid_in == 0) {
844 // /* going to idle task */
845 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
848 // * scheduling a real task. we must be careful here: if we
849 // * just schedule()'ed to a process that is in a trap, we
850 // * must put the cpu in trap mode
852 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
853 // if (process.getState().getExec_mode() ==
854 // ExecutionMode.LTTV_STATE_TRAP) {
855 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
867 * Handles: LTT_EVENT_PROCESS_FORK
870 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
871 * LTT_FIELD_CHILD_TGID)
876 final ILttngEventProcessor
getProcessForkHandler() {
877 AbsStateUpdate handler
= new AbsStateUpdate() {
881 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
883 // Long cpu = trcEvent.getCpuId();
884 // LttngProcessState process = traceSt.getRunning_process().get(
886 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
888 // // /* Parent PID */
889 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
890 // // Fields.LTT_FIELD_PARENT_PID);
893 // /* In the Linux Kernel, there is one PID per thread. */
894 // Long child_pid = getAFieldLong(trcEvent, traceSt,
895 // Fields.LTT_FIELD_CHILD_PID);
898 // /* tgid in the Linux kernel is the "real" POSIX PID. */
899 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
900 // Fields.LTT_FIELD_CHILD_TGID);
901 // if (child_tgid == null) {
906 // * Mathieu : it seems like the process might have been
908 // * in before the fork, and, in a rare case, might be the
910 // * process. This might happen in a SMP case where we don't
912 // * enough precision on the clocks.
914 // * Test reenabled after precision fixes on time. (Mathieu)
917 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
920 // // if(unlikely(zombie_process != NULL)) {
921 // // /* Reutilisation of PID. Only now we are sure that the old
923 // // * has been released. FIXME : should know when release_task
927 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
929 // // for(i=0; i< num_cpus; i++) {
930 // // g_assert(zombie_process != ts->running_process[i]);
933 // // exit_process(s, zombie_process);
937 // if (process.getPid() == child_pid) {
939 // .debug("Unexpected, process pid equal to child pid: "
942 // + trcEvent.getTimestamp());
945 // // g_assert(process->pid != child_pid);
946 // // FIXME : Add this test in the "known state" section
947 // // g_assert(process->pid == parent_pid);
948 // LttngProcessState child_process = lttv_state_find_process(
949 // traceSt, ANY_CPU, child_pid);
950 // if (child_process == null) {
951 // child_process = create_process(traceSt, cpu, child_pid,
952 // child_tgid, timeStamp);
955 // * The process has already been created : due to time
956 // * imprecision between multiple CPUs : it has been scheduled
957 // * in before creation. Note that we shouldn't have this kind
960 // * Simply put a correct parent.
962 // StringBuilder sb = new StringBuilder("Process " + child_pid);
963 // sb.append(" has been created at ["
964 // + child_process.getCration_time() + "] ");
965 // sb.append("and inserted at ["
966 // + child_process.getInsertion_time() + "] ");
967 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
968 // + trcEvent + "]\n.");
970 // .append("Probably an unsynchronized TSD problem on the traced machine.");
971 // TraceDebug.debug(sb.toString());
973 // // g_assert(0); /* This is a problematic case : the process
976 // // before the fork event */
977 // child_process.setPpid(process.getPid());
978 // child_process.setTgid(child_tgid);
981 // if (!child_process.getName().equals(
982 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
983 // TraceDebug.debug("Unexpected child process status: "
984 // + child_process.getName());
987 // child_process.setName(process.getName());
988 // child_process.setBrand(process.getBrand());
999 * Handles: LTT_EVENT_KTHREAD_CREATE
1002 * Fields: LTT_FIELD_PID
1007 final ILttngEventProcessor
getProcessKernelThreadHandler() {
1008 AbsStateUpdate handler
= new AbsStateUpdate() {
1012 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1014 // * We stamp a newly created process as kernel_thread. The
1016 // * should not be running yet.
1019 // LttngExecutionState exState;
1021 // LttngProcessState process;
1024 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1025 // // s->parent.target_pid = pid;
1027 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1028 // pid, new TmfTimestamp());
1030 // if (!process.getState().getProc_status().equals(
1031 // ProcessStatus.LTTV_STATE_DEAD)) {
1032 // // Leave only the first element in the stack with execution
1035 // Stack<LttngExecutionState> processExStack = process
1036 // .getExecution_stack();
1037 // exState = processExStack.firstElement();
1038 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1039 // if (processExStack.size() > 1) {
1040 // processExStack.clear();
1041 // processExStack.add(exState);
1044 // // update the process state to the only one in the stack
1045 // process.setState(exState);
1048 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1059 * Handles: LTT_EVENT_PROCESS_EXIT
1067 final ILttngEventProcessor
getProcessExitHandler() {
1068 AbsStateUpdate handler
= new AbsStateUpdate() {
1072 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1075 // LttngProcessState process;
1077 // pid = getAFieldLong(trcEvent, traceSt,
1078 // Fields.LTT_FIELD_PID);
1079 // // s->parent.target_pid = pid;
1081 // // FIXME : Add this test in the "known state" section
1082 // // g_assert(process->pid == pid);
1084 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1085 // if (process != null) {
1086 // process.getState().setProc_status(
1087 // ProcessStatus.LTTV_STATE_EXIT);
1098 * Handles: LTT_EVENT_PROCESS_FREE
1101 * Fields: LTT_FIELD_PID
1106 final ILttngEventProcessor
getProcessFreeHandler() {
1107 AbsStateUpdate handler
= new AbsStateUpdate() {
1111 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1113 // Long release_pid;
1114 // LttngProcessState process;
1116 // /* PID of the process to release */
1117 // release_pid = getAFieldLong(trcEvent, traceSt,
1118 // Fields.LTT_FIELD_PID);
1119 // // s->parent.target_pid = release_pid;
1121 // if (release_pid == 0) {
1122 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1123 // + trcEvent.getTimestamp());
1126 // process = lttv_state_find_process(traceSt, ANY_CPU,
1128 // if (process != null) {
1129 // exit_process(traceSt, process);
1134 // if(process != null) {
1136 * release_task is happening at kernel level : we can now safely
1137 * release the data structure of the process
1139 // This test is fun, though, as it may happen that
1140 // at time t : CPU 0 : process_free
1141 // at time t+150ns : CPU 1 : schedule out
1142 // Clearly due to time imprecision, we disable it. (Mathieu)
1143 // If this weird case happen, we have no choice but to put the
1144 // Currently running process on the cpu to 0.
1145 // I re-enable it following time precision fixes. (Mathieu)
1146 // Well, in the case where an process is freed by a process on
1149 // and still scheduled, it happens that this is the schedchange
1152 // drop the last reference count. Do not free it here!
1154 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1156 // for(i=0; i< num_cpus; i++) {
1157 // //g_assert(process != ts->running_process[i]);
1158 // if(process == ts->running_process[i]) {
1159 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1163 // if(i == num_cpus) /* process is not scheduled */
1164 // exit_process(s, process);
1176 * Handles: LTT_EVENT_EXEC
1179 * FIELDS: LTT_FIELD_FILENAME
1184 final ILttngEventProcessor
getProcessExecHandler() {
1185 AbsStateUpdate handler
= new AbsStateUpdate() {
1189 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1191 // Long cpu = trcEvent.getCpuId();
1192 // LttngProcessState process = traceSt.getRunning_process().get(
1195 // // #if 0//how to use a sequence that must be transformed in a
1197 // // /* PID of the process to release */
1198 // // guint64 name_len = ltt_event_field_element_number(e,
1199 // // lttv_trace_get_hook_field(th, 0));
1200 // // //name = ltt_event_get_string(e,
1201 // // lttv_trace_get_hook_field(th, 0));
1202 // // LttField *child = ltt_event_field_element_select(e,
1203 // // lttv_trace_get_hook_field(th, 0), 0);
1204 // // gchar *name_begin =
1205 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1207 // // gchar *null_term_name = g_new(gchar, name_len+1);
1208 // // memcpy(null_term_name, name_begin, name_len);
1209 // // null_term_name[name_len] = '\0';
1210 // // process->name = g_quark_from_string(null_term_name);
1213 // process.setName(getAFieldString(trcEvent, traceSt,
1214 // Fields.LTT_FIELD_FILENAME));
1215 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1225 * LTT_EVENT_THREAD_BRAND
1228 * FIELDS: LTT_FIELD_NAME
1233 final ILttngEventProcessor
GetThreadBrandHandler() {
1234 AbsStateUpdate handler
= new AbsStateUpdate() {
1238 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1241 // Long cpu = trcEvent.getCpuId();
1242 // LttngProcessState process = traceSt.getRunning_process().get(
1245 // name = getAFieldString(trcEvent, traceSt,
1246 // Fields.LTT_FIELD_NAME);
1247 // process.setBrand(name);
1258 final ILttngEventProcessor
getStateDumpEndHandler() {
1259 AbsStateUpdate handler
= new AbsStateUpdate() {
1263 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1265 // /* For all processes */
1267 // * if kernel thread, if stack[0] is unknown, set to syscall
1270 // /* else, if stack[0] is unknown, set to user mode, running */
1271 // List<LttngProcessState> processes = traceSt.getProcesses();
1272 // TmfTimestamp time = trcEvent.getTimestamp();
1274 // for (LttngProcessState process : processes) {
1275 // fix_process(process, time);
1286 * Private method used to establish the first execution state in the stack
1287 * for a given process
1292 // private void fix_process(LttngProcessState process,
1293 // TmfTimestamp timestamp) {
1295 // LttngExecutionState es;
1296 // Stack<LttngExecutionState> procStack = process
1297 // .getExecution_stack();
1299 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1300 // es = procStack.firstElement();
1302 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1303 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1305 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1307 // es.setEntry_Time(timestamp);
1308 // es.setChage_Time(timestamp);
1309 // es.setCum_cpu_time(0L);
1310 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1311 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1315 // es = procStack.firstElement();
1316 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1317 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1319 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1321 // es.setEntry_Time(timestamp);
1322 // es.setChage_Time(timestamp);
1323 // es.setCum_cpu_time(0L);
1324 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1325 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1328 // if (procStack.size() == 1) {
1330 // * Still in bottom unknown mode, means never did a
1331 // * system call May be either in user mode, syscall
1332 // * mode, running or waiting.
1335 // * FIXME : we may be tagging syscall mode when being
1338 // // Get a new execution State
1339 // es = new LttngExecutionState();
1341 // // initialize values
1342 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1344 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1346 // es.setEntry_Time(timestamp);
1347 // es.setChage_Time(timestamp);
1348 // es.setCum_cpu_time(0L);
1349 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1351 // // Push the new state to the stack
1352 // procStack.push(es);
1363 * Handles: LTT_EVENT_PROCESS_STATE
1366 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1367 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1373 final ILttngEventProcessor
getEnumProcessStateHandler() {
1374 AbsStateUpdate handler
= new AbsStateUpdate() {
1378 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1384 // Long cpu = trcEvent.getCpuId();
1385 // LttngProcessState process = traceSt.getRunning_process().get(
1387 // LttngProcessState parent_process;
1389 // // String mode, submode, status;
1390 // LttngExecutionState es;
1393 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1396 // parent_pid = getAFieldLong(trcEvent, traceSt,
1397 // Fields.LTT_FIELD_PARENT_PID);
1399 // /* Command name */
1400 // command = getAFieldString(trcEvent, traceSt,
1401 // Fields.LTT_FIELD_NAME);
1403 // /* TODO: type field, Values need to be verified */
1405 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1406 // Fields.LTT_FIELD_TYPE);
1407 // if (typeVal == 0L) {
1408 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1410 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1413 // // FIXME: type is rarely used, enum must match possible
1417 // // mode = getAFieldString(trcEvent, traceSt,
1418 // // Fields.LTT_FIELD_MODE);
1421 // // submode = getAFieldString(trcEvent, traceSt,
1422 // // Fields.LTT_FIELD_SUBMODE);
1425 // // status = getAFieldString(trcEvent, traceSt,
1426 // // Fields.LTT_FIELD_STATUS);
1429 // tgid = getAFieldLong(trcEvent, traceSt,
1430 // Fields.LTT_FIELD_TGID);
1431 // if (tgid == null) {
1436 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1437 // process = lttv_state_find_process(traceSt, acpu, pid);
1438 // if (process != null) {
1439 // process.setPpid(parent_pid);
1440 // process.setTgid(tgid);
1441 // process.setName(command);
1443 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1445 // StringBuilder sb = new StringBuilder(
1446 // "Unexpected, null process read from the TraceState list of processes, event time: "
1447 // + trcEvent.getTimestamp());
1448 // TraceDebug.debug(sb.toString());
1453 // * The process might exist if a process was forked while
1454 // * performing the state dump.
1456 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1457 // if (process == null) {
1458 // parent_process = lttv_state_find_process(traceSt,
1459 // ANY_CPU, parent_pid);
1460 // process = create_process(traceSt, cpu, pid, tgid,
1461 // command, trcEvent.getTimestamp());
1462 // if (parent_process != null) {
1463 // process.setPpid(parent_process.getPid());
1466 // /* Keep the stack bottom : a running user mode */
1468 // * Disabled because of inconsistencies in the current
1469 // * statedump states.
1471 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1474 // * FIXME Kernel thread : can be in syscall or
1475 // * interrupt or trap.
1478 // * Will cause expected trap when in fact being
1479 // * syscall (even after end of statedump event) Will
1480 // * cause expected interrupt when being syscall.
1481 // * (only before end of statedump event)
1484 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1487 // // es->t = LTTV_STATE_SYSCALL;
1488 // // es->s = status;
1489 // // es->n = submode;
1493 // * User space process : bottom : user mode either
1494 // * currently running or scheduled out. can be
1495 // * scheduled out because interrupted in (user mode
1496 // * or in syscall) or because of an explicit call to
1497 // * the scheduler in syscall. Note that the scheduler
1498 // * call comes after the irq_exit, so never in
1499 // * interrupt context.
1501 // // temp workaround : set size to 1 : only have user
1503 // // bottom of stack.
1504 // // will cause g_info message of expected syscall
1507 // // in user mode. Can also cause expected trap when
1510 // // mode in the event of a page fault reenabling
1512 // // in the handler.
1513 // // Expected syscall and trap can also happen after
1516 // // This will cause a
1517 // // "popping last state on stack, ignoring it."
1519 // // process->execution_stack =
1520 // // g_array_set_size(process->execution_stack, 1);
1521 // // es = process->state =
1522 // // &g_array_index(process->execution_stack,
1523 // // LttvExecutionState, 0);
1524 // // a new process must have only one state in the
1526 // // be the same as the current state
1527 // // es = process.getState();
1528 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1529 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1532 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1533 // // .getInName());
1536 // // es->t = LTTV_STATE_USER_MODE;
1537 // // es->s = status;
1538 // // es->n = submode;
1541 // // TODO: clean up comments above: Moved repeated code
1543 // // if / else blocks above,
1544 // // comments left temporarily for easier visualization
1546 // // comparision with c code
1547 // es = process.getState();
1548 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1549 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1551 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1554 // // /* UNKNOWN STATE */
1556 // // es = process->state =
1557 // // &g_array_index(process->execution_stack,
1558 // // LttvExecutionState, 1);
1559 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1560 // // es->s = LTTV_STATE_UNNAMED;
1561 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1566 // * The process has already been created : Probably was
1567 // * forked while dumping the process state or was simply
1568 // * scheduled in prior to get the state dump event.
1570 // process.setPpid(parent_pid);
1571 // process.setTgid(tgid);
1572 // process.setName(command);
1573 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1576 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1578 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1582 // // &g_array_index(process->execution_stack,
1583 // // LttvExecutionState,
1586 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1587 // // if(type == LTTV_STATE_KERNEL_THREAD)
1588 // // es->t = LTTV_STATE_SYSCALL;
1590 // // es->t = LTTV_STATE_USER_MODE;
1594 // * Don't mess around with the stack, it will eventually
1595 // * become ok after the end of state dump.