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 class StateBeforeUpdateHandlers
{
33 final ILttngEventProcessor
getSyscallEntryHandler() {
34 AbsStateUpdate handler
= new AbsStateUpdate() {
37 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
38 // TraceDebug.debug("Before event called");
40 Long cpu
= trcEvent
.getCpuId();
42 // No syscall_entry update for initialization process
43 LttngProcessState process
= traceSt
.getRunning_process().get(
46 pid
= process
.getPid();
51 // Get the expected event field
52 Long syscall
= getAFieldLong(trcEvent
, traceSt
,
53 Fields
.LTT_FIELD_SYSCALL_ID
);
54 if (syscall
== null) {
55 TraceDebug
.debug("Syscall Field not found in Event: "
56 + trcEvent
.getMarkerName());
60 String submode
= traceSt
.getSyscall_names().get(syscall
);
62 if (submode
== null) {
63 TraceDebug
.debug("Submode not found in Event");
64 submode
= ExecutionSubMode
.LTTV_STATE_SUBMODE_UNKNOWN
68 exState
= new LttngExecutionState();
69 exState
.setExec_mode(ExecutionMode
.LTTV_STATE_SYSCALL
);
70 exState
.setExec_submode(submode
);
71 exState
.setEntry_Time(trcEvent
.getTimestamp().getValue());
72 exState
.setChange_Time(trcEvent
.getTimestamp().getValue());
73 exState
.setCum_cpu_time(0L);
81 final ILttngEventProcessor
getsySyscallExitHandler() {
82 AbsStateUpdate handler
= new AbsStateUpdate() {
85 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
87 Long cpu
= trcEvent
.getCpuId();
88 LttngProcessState process
= traceSt
.getRunning_process().get(
91 /* There can be no system call from PID 0 : unknown state */
92 pid
= process
.getPid();
97 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
98 // traceSt, trcEvent.getTimestamp());
107 * Update stacks related to the parsing of an LttngEvent
111 final ILttngEventProcessor
getTrapEntryHandler() {
112 AbsStateUpdate handler
= new AbsStateUpdate() {
115 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
116 // Long cpu = trcEvent.getCpuId();
118 // Long trap = getAFieldLong(trcEvent, traceSt,
119 // Fields.LTT_FIELD_TRAP_ID);
120 // if (trap == null) {
124 // String submode = traceSt.getSyscall_names()
127 // if (submode == null) {
128 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
132 // /* update process state */
133 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
134 // submode, trcEvent.getTimestamp(), traceSt);
136 // /* update cpu status */
137 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
138 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
139 // cpust.setLast_trap(trap); /* update trap status */
141 // // update Trap State
142 // LttngTrapState trap_state = traceSt.getTrap_states().get(
144 // trap_state.incrementRunning();
157 final ILttngEventProcessor
getTrapExitHandler() {
158 AbsStateUpdate handler
= new AbsStateUpdate() {
161 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
163 // Long cpu = trcEvent.getCpuId();
164 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
165 // Long trap = cpust.getLast_trap();
167 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
171 // /* update cpu status */
172 // cpu_pop_mode(cpust);
174 // /* update trap status */
175 // if (trap != -1L) {
176 // traceSt.getTrap_states().get(trap).decrementRunning();
189 final ILttngEventProcessor
getIrqEntryHandler() {
190 AbsStateUpdate handler
= new AbsStateUpdate() {
193 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
195 // Long cpu = trcEvent.getCpuId();
197 // Long irq = getAFieldLong(trcEvent, traceSt,
198 // Fields.LTT_FIELD_IRQ_ID);
199 // if (irq == null) {
204 // submode = traceSt.getIrq_names().get(irq);
206 // if (submode == null) {
208 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
212 // * Do something with the info about being in user or system
216 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
218 // .getTimestamp(), traceSt);
220 // /* update cpu state */
221 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
222 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
223 // cpust.setLast_irq(irq); /* last irq */
225 // /* udpate irq state */
226 // irq_push_mode(traceSt.getIrq_states().get(irq),
227 // IRQMode.LTTV_IRQ_BUSY);
239 final ILttngEventProcessor
getSoftIrqExitHandler() {
240 AbsStateUpdate handler
= new AbsStateUpdate() {
243 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
245 // Long cpu = trcEvent.getCpuId();
246 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
247 // Long softirq = cpust.getLast_soft_irq();
248 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
249 // trcEvent.getTimestamp());
251 // /* update softirq status */
252 // if (softirq != -1) {
253 // LttngSoftIRQState softIrqstate = traceSt
254 // .getSoft_irq_states().get(softirq);
255 // softIrqstate.decrementRunning();
258 // /* update cpu status */
259 // cpu_pop_mode(cpust);
271 final ILttngEventProcessor
getIrqExitHandler() {
272 AbsStateUpdate handler
= new AbsStateUpdate() {
275 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
277 // Long cpu = trcEvent.getCpuId();
279 // /* update process state */
280 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
284 // /* update cpu status */
285 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
286 // cpu_pop_mode(cpust);
288 // /* update irq status */
289 // Long last_irq = cpust.getLast_irq();
290 // if (last_irq != -1L) {
291 // LttngIRQState irq_state = traceSt.getIrq_states().get(
293 // irq_pop_mode(irq_state);
307 final ILttngEventProcessor
getSoftIrqRaiseHandler() {
308 AbsStateUpdate handler
= new AbsStateUpdate() {
311 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
313 // // Long cpu = trcEvent.getCpuId();
315 // // get event field
316 // Long softirq = getAFieldLong(trcEvent, traceSt,
317 // Fields.LTT_FIELD_SOFT_IRQ_ID);
319 // if (softirq == null) {
323 // // String submode;
324 // // String[] softIrqNames = traceSt.getSoft_irq_names();
325 // // if (softirq < softIrqNames.length) {
326 // // submode = softIrqNames[softirq];
328 // // submode = "softirq " + softirq;
331 // /* update softirq status */
332 // /* a soft irq raises are not cumulative */
333 // LttngSoftIRQState irqState =
334 // traceSt.getSoft_irq_states().get(
336 // if (irqState != null) {
337 // irqState.setPending(1L);
340 // .debug("unexpected soft irq id value: " + softirq);
354 final ILttngEventProcessor
getSoftIrqEntryHandler() {
355 AbsStateUpdate handler
= new AbsStateUpdate() {
358 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
361 // Long cpu = trcEvent.getCpuId();
363 // // get event field
364 // Long softirq = getAFieldLong(trcEvent, traceSt,
365 // Fields.LTT_FIELD_SOFT_IRQ_ID);
367 // if (softirq == null) {
372 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
373 // String submode = softIrqNames.get(softirq);
374 // if (submode == null) {
375 // submode = "softirq " + softirq;
376 // softIrqNames.put(softirq, submode);
379 // /* update softirq status */
380 // LttngSoftIRQState irqState =
381 // traceSt.getSoft_irq_states().get(
383 // if (irqState != null) {
384 // irqState.decrementPending();
385 // irqState.incrementRunning();
388 // .debug("unexpected soft irq id value: " + softirq);
391 // /* update cpu state */
392 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
393 // cpu_state.setLast_soft_irq(softirq);
394 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
396 // /* update process execution mode state stack */
397 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
398 // trcEvent.getTimestamp(), traceSt);
408 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
412 final ILttngEventProcessor
getEnumInterruptHandler() {
413 AbsStateUpdate handler
= new AbsStateUpdate() {
416 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
417 // String action = getAFieldString(trcEvent, traceSt,
418 // Fields.LTT_FIELD_ACTION);
419 // Long irq = getAFieldLong(trcEvent, traceSt,
420 // Fields.LTT_FIELD_IRQ_ID);
422 // Map<Long, String> irq_names = traceSt.getIrq_names();
424 // irq_names.put(irq, action);
433 * Handle the event LTT_EVENT_REQUEST_ISSUE
437 final ILttngEventProcessor
getBdevRequestIssueHandler() {
438 AbsStateUpdate handler
= new AbsStateUpdate() {
441 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
444 // Long major = getAFieldLong(trcEvent, traceSt,
445 // Fields.LTT_FIELD_MAJOR);
446 // Long minor = getAFieldLong(trcEvent, traceSt,
447 // Fields.LTT_FIELD_MINOR);
448 // Long operation = getAFieldLong(trcEvent, traceSt,
449 // Fields.LTT_FIELD_OPERATION);
451 // // calculate bdevcode
452 // Long devcode = mkdev(major, minor);
454 // if (devcode == null) {
456 // .debug("incorrect calcualtion of bdevcode input( major: "
460 // + " operation: " + operation);
464 // Map<Long, LttngBdevState> bdev_states = traceSt
465 // .getBdev_states();
466 // // Get the instance
467 // LttngBdevState bdevState = bdev_states.get(devcode);
468 // if (bdevState == null) {
469 // bdevState = new LttngBdevState();
472 // // update the mode in the stack
473 // if (operation == 0L) {
474 // bdevState.getMode_stack().push(
475 // BdevMode.LTTV_BDEV_BUSY_READING);
477 // bdevState.getMode_stack().push(
478 // BdevMode.LTTV_BDEV_BUSY_WRITING);
481 // // make sure it is included in the set
482 // bdev_states.put(devcode, bdevState);
492 * Handling event: LTT_EVENT_REQUEST_COMPLETE
495 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
500 final ILttngEventProcessor
getBdevRequestCompleteHandler() {
501 AbsStateUpdate handler
= new AbsStateUpdate() {
504 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
507 // Long major = getAFieldLong(trcEvent, traceSt,
508 // Fields.LTT_FIELD_MAJOR);
509 // Long minor = getAFieldLong(trcEvent, traceSt,
510 // Fields.LTT_FIELD_MINOR);
511 // Long operation = getAFieldLong(trcEvent, traceSt,
512 // Fields.LTT_FIELD_OPERATION);
514 // // calculate bdevcode
515 // Long devcode = mkdev(major, minor);
517 // if (devcode == null) {
519 // .debug("incorrect calcualtion of bdevcode input( major: "
523 // + " operation: " + operation);
527 // Map<Long, LttngBdevState> bdev_states = traceSt
528 // .getBdev_states();
529 // // Get the instance
530 // LttngBdevState bdevState = bdev_states.get(devcode);
531 // if (bdevState == null) {
532 // bdevState = new LttngBdevState();
535 // /* update block device */
536 // bdev_pop_mode(bdevState);
547 * Handles event: LTT_EVENT_FUNCTION_ENTRY
550 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
555 final ILttngEventProcessor
getFunctionEntryHandler() {
556 AbsStateUpdate handler
= new AbsStateUpdate() {
559 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
560 // Long cpu = trcEvent.getCpuId();
561 // Long funcptr = getAFieldLong(trcEvent, traceSt,
562 // Fields.LTT_FIELD_THIS_FN);
564 // push_function(traceSt, funcptr, cpu);
576 final ILttngEventProcessor
getFunctionExitHandler() {
577 AbsStateUpdate handler
= new AbsStateUpdate() {
580 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
582 // Long funcptr = getAFieldLong(trcEvent, traceSt,
583 // Fields.LTT_FIELD_THIS_FN);
585 // pop_function(traceSt, trcEvent, funcptr);
595 * process event: LTT_EVENT_SYS_CALL_TABLE
598 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
603 final ILttngEventProcessor
getDumpSyscallHandler() {
604 AbsStateUpdate handler
= new AbsStateUpdate() {
607 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
608 // // obtain the syscall id
609 // Long id = getAFieldLong(trcEvent, traceSt,
610 // Fields.LTT_FIELD_ID);
612 // // Long address = getAFieldLong(trcEvent, traceSt,
613 // // Fields.LTT_FIELD_ADDRESS);
615 // // Obtain the symbol
616 // String symbol = getAFieldString(trcEvent, traceSt,
617 // Fields.LTT_FIELD_SYMBOL);
619 // // fill the symbol to the sycall_names collection
620 // traceSt.getSyscall_names().put(id, symbol);
630 * Handles event: LTT_EVENT_KPROBE_TABLE
633 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
638 final ILttngEventProcessor
getDumpKprobeHandler() {
639 AbsStateUpdate handler
= new AbsStateUpdate() {
642 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
644 // Long ip = getAFieldLong(trcEvent, traceSt,
645 // Fields.LTT_FIELD_IP);
646 // String symbol = getAFieldString(trcEvent, traceSt,
647 // Fields.LTT_FIELD_SYMBOL);
649 // traceSt.getKprobe_table().put(ip, symbol);
660 * Handles: LTT_EVENT_SOFTIRQ_VEC
663 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
668 final ILttngEventProcessor
getDumpSoftIrqHandler() {
669 AbsStateUpdate handler
= new AbsStateUpdate() {
672 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
675 // Long id = getAFieldLong(trcEvent, traceSt,
676 // Fields.LTT_FIELD_ID);
678 // // Address not needed
679 // // Long address = ltt_event_get_long_unsigned(e,
680 // // lttv_trace_get_hook_field(th,
684 // String symbol = getAFieldString(trcEvent, traceSt,
685 // Fields.LTT_FIELD_SYMBOL);
687 // // Register the soft irq name
688 // traceSt.getSoft_irq_names().put(id, symbol);
698 * Handles: LTT_EVENT_SCHED_SCHEDULE
701 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
706 final ILttngEventProcessor
getSchedChangeHandler() {
707 AbsStateUpdate handler
= new AbsStateUpdate() {
710 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
712 // Long cpu = trcEvent.getCpuId();
713 // TmfTimestamp eventTime = trcEvent.getTimestamp();
715 // LttngProcessState process = traceSt.getRunning_process().get(
718 // Long pid_out = getAFieldLong(trcEvent, traceSt,
719 // Fields.LTT_FIELD_PREV_PID);
720 // Long pid_in = getAFieldLong(trcEvent, traceSt,
721 // Fields.LTT_FIELD_NEXT_PID);
722 // Long state_out = getAFieldLong(trcEvent, traceSt,
723 // Fields.LTT_FIELD_PREV_STATE);
725 // if (process != null) {
728 // * We could not know but it was not the idle process
729 // * executing. This should only happen at the beginning,
730 // * before the first schedule event, and when the initial
731 // * information (current process for each CPU) is missing. It
732 // * is not obvious how we could, after the fact, compensate
733 // * the wrongly attributed statistics.
736 // // This test only makes sense once the state is known and if
739 // // missing events. We need to silently ignore schedchange
742 // // process_free, or it causes glitches. (FIXME)
743 // // if(unlikely(process->pid != pid_out)) {
744 // // g_assert(process->pid == 0);
746 // if (process.getPid() == 0
747 // && process.getState().getExec_mode() ==
748 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
749 // if (pid_out == 0) {
751 // * Scheduling out of pid 0 at beginning of the trace
752 // * : we know for sure it is in syscall mode at this
755 // int stackSize = process.getExecution_stack().size();
756 // if (stackSize != 1) {
758 // .debug("unpexpected process execution stack size, expected 1, received: ");
761 // process.getState().setExec_mode(
762 // ExecutionMode.LTTV_STATE_SYSCALL);
763 // process.getState().setProc_status(
764 // ProcessStatus.LTTV_STATE_WAIT);
765 // process.getState().setChage_Time(
766 // trcEvent.getTimestamp());
767 // process.getState().setEntry_Time(
768 // trcEvent.getTimestamp());
771 // if (process.getState().getProc_status() ==
772 // ProcessStatus.LTTV_STATE_EXIT) {
773 // process.getState().setProc_status(
774 // ProcessStatus.LTTV_STATE_ZOMBIE);
775 // process.getState().setChage_Time(
776 // trcEvent.getTimestamp());
778 // if (state_out == 0L) {
779 // process.getState().setProc_status(
780 // ProcessStatus.LTTV_STATE_WAIT_CPU);
782 // process.getState().setProc_status(
783 // ProcessStatus.LTTV_STATE_WAIT);
786 // process.getState().setChage_Time(
787 // trcEvent.getTimestamp());
790 // if (state_out == 32L || state_out == 64L) { /*
795 // /* see sched.h for states */
796 // if (!exit_process(traceSt, process)) {
797 // process.getState().setProc_status(
798 // ProcessStatus.LTTV_STATE_DEAD);
799 // process.getState().setChage_Time(
800 // trcEvent.getTimestamp());
805 // process = lttv_state_find_process_or_create(traceSt, cpu,
806 // pid_in, eventTime);
808 // traceSt.getRunning_process().put(cpu, process);
810 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
811 // process.getState().setChage_Time(eventTime);
812 // process.setCpu(cpu);
813 // // process->state->s = LTTV_STATE_RUN;
814 // // if(process->usertrace)
815 // // process->usertrace->cpu = cpu;
816 // // process->last_cpu_index =
817 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
819 // // process->state->change = s->parent.timestamp;
821 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
822 // /* update cpu status */
823 // if (pid_in == 0) {
825 // /* going to idle task */
826 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
829 // * scheduling a real task. we must be careful here: if we
830 // * just schedule()'ed to a process that is in a trap, we
831 // * must put the cpu in trap mode
833 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
834 // if (process.getState().getExec_mode() ==
835 // ExecutionMode.LTTV_STATE_TRAP) {
836 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
848 * Handles: LTT_EVENT_PROCESS_FORK
851 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
852 * LTT_FIELD_CHILD_TGID)
857 final ILttngEventProcessor
getProcessForkHandler() {
858 AbsStateUpdate handler
= new AbsStateUpdate() {
861 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
863 // Long cpu = trcEvent.getCpuId();
864 // LttngProcessState process = traceSt.getRunning_process().get(
866 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
868 // // /* Parent PID */
869 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
870 // // Fields.LTT_FIELD_PARENT_PID);
873 // /* In the Linux Kernel, there is one PID per thread. */
874 // Long child_pid = getAFieldLong(trcEvent, traceSt,
875 // Fields.LTT_FIELD_CHILD_PID);
878 // /* tgid in the Linux kernel is the "real" POSIX PID. */
879 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
880 // Fields.LTT_FIELD_CHILD_TGID);
881 // if (child_tgid == null) {
886 // * Mathieu : it seems like the process might have been
888 // * in before the fork, and, in a rare case, might be the
890 // * process. This might happen in a SMP case where we don't
892 // * enough precision on the clocks.
894 // * Test reenabled after precision fixes on time. (Mathieu)
897 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
900 // // if(unlikely(zombie_process != NULL)) {
901 // // /* Reutilisation of PID. Only now we are sure that the old
903 // // * has been released. FIXME : should know when release_task
907 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
909 // // for(i=0; i< num_cpus; i++) {
910 // // g_assert(zombie_process != ts->running_process[i]);
913 // // exit_process(s, zombie_process);
917 // if (process.getPid() == child_pid) {
919 // .debug("Unexpected, process pid equal to child pid: "
922 // + trcEvent.getTimestamp());
925 // // g_assert(process->pid != child_pid);
926 // // FIXME : Add this test in the "known state" section
927 // // g_assert(process->pid == parent_pid);
928 // LttngProcessState child_process = lttv_state_find_process(
929 // traceSt, ANY_CPU, child_pid);
930 // if (child_process == null) {
931 // child_process = create_process(traceSt, cpu, child_pid,
932 // child_tgid, timeStamp);
935 // * The process has already been created : due to time
936 // * imprecision between multiple CPUs : it has been scheduled
937 // * in before creation. Note that we shouldn't have this kind
940 // * Simply put a correct parent.
942 // StringBuilder sb = new StringBuilder("Process " + child_pid);
943 // sb.append(" has been created at ["
944 // + child_process.getCration_time() + "] ");
945 // sb.append("and inserted at ["
946 // + child_process.getInsertion_time() + "] ");
947 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
948 // + trcEvent + "]\n.");
950 // .append("Probably an unsynchronized TSD problem on the traced machine.");
951 // TraceDebug.debug(sb.toString());
953 // // g_assert(0); /* This is a problematic case : the process
956 // // before the fork event */
957 // child_process.setPpid(process.getPid());
958 // child_process.setTgid(child_tgid);
961 // if (!child_process.getName().equals(
962 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
963 // TraceDebug.debug("Unexpected child process status: "
964 // + child_process.getName());
967 // child_process.setName(process.getName());
968 // child_process.setBrand(process.getBrand());
979 * Handles: LTT_EVENT_KTHREAD_CREATE
982 * Fields: LTT_FIELD_PID
987 final ILttngEventProcessor
getProcessKernelThreadHandler() {
988 AbsStateUpdate handler
= new AbsStateUpdate() {
991 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
993 // * We stamp a newly created process as kernel_thread. The
995 // * should not be running yet.
998 // LttngExecutionState exState;
1000 // LttngProcessState process;
1003 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1004 // // s->parent.target_pid = pid;
1006 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1007 // pid, new TmfTimestamp());
1009 // if (!process.getState().getProc_status().equals(
1010 // ProcessStatus.LTTV_STATE_DEAD)) {
1011 // // Leave only the first element in the stack with execution
1014 // Stack<LttngExecutionState> processExStack = process
1015 // .getExecution_stack();
1016 // exState = processExStack.firstElement();
1017 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1018 // if (processExStack.size() > 1) {
1019 // processExStack.clear();
1020 // processExStack.add(exState);
1023 // // update the process state to the only one in the stack
1024 // process.setState(exState);
1027 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1038 * Handles: LTT_EVENT_PROCESS_EXIT
1046 final ILttngEventProcessor
getProcessExitHandler() {
1047 AbsStateUpdate handler
= new AbsStateUpdate() {
1050 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1053 // LttngProcessState process;
1055 // pid = getAFieldLong(trcEvent, traceSt,
1056 // Fields.LTT_FIELD_PID);
1057 // // s->parent.target_pid = pid;
1059 // // FIXME : Add this test in the "known state" section
1060 // // g_assert(process->pid == pid);
1062 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1063 // if (process != null) {
1064 // process.getState().setProc_status(
1065 // ProcessStatus.LTTV_STATE_EXIT);
1076 * Handles: LTT_EVENT_PROCESS_FREE
1079 * Fields: LTT_FIELD_PID
1084 final ILttngEventProcessor
getProcessFreeHandler() {
1085 AbsStateUpdate handler
= new AbsStateUpdate() {
1088 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1090 // Long release_pid;
1091 // LttngProcessState process;
1093 // /* PID of the process to release */
1094 // release_pid = getAFieldLong(trcEvent, traceSt,
1095 // Fields.LTT_FIELD_PID);
1096 // // s->parent.target_pid = release_pid;
1098 // if (release_pid == 0) {
1099 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1100 // + trcEvent.getTimestamp());
1103 // process = lttv_state_find_process(traceSt, ANY_CPU,
1105 // if (process != null) {
1106 // exit_process(traceSt, process);
1111 // if(process != null) {
1113 * release_task is happening at kernel level : we can now safely
1114 * release the data structure of the process
1116 // This test is fun, though, as it may happen that
1117 // at time t : CPU 0 : process_free
1118 // at time t+150ns : CPU 1 : schedule out
1119 // Clearly due to time imprecision, we disable it. (Mathieu)
1120 // If this weird case happen, we have no choice but to put the
1121 // Currently running process on the cpu to 0.
1122 // I re-enable it following time precision fixes. (Mathieu)
1123 // Well, in the case where an process is freed by a process on
1126 // and still scheduled, it happens that this is the schedchange
1129 // drop the last reference count. Do not free it here!
1131 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1133 // for(i=0; i< num_cpus; i++) {
1134 // //g_assert(process != ts->running_process[i]);
1135 // if(process == ts->running_process[i]) {
1136 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1140 // if(i == num_cpus) /* process is not scheduled */
1141 // exit_process(s, process);
1153 * Handles: LTT_EVENT_EXEC
1156 * FIELDS: LTT_FIELD_FILENAME
1161 final ILttngEventProcessor
getProcessExecHandler() {
1162 AbsStateUpdate handler
= new AbsStateUpdate() {
1165 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1167 // Long cpu = trcEvent.getCpuId();
1168 // LttngProcessState process = traceSt.getRunning_process().get(
1171 // // #if 0//how to use a sequence that must be transformed in a
1173 // // /* PID of the process to release */
1174 // // guint64 name_len = ltt_event_field_element_number(e,
1175 // // lttv_trace_get_hook_field(th, 0));
1176 // // //name = ltt_event_get_string(e,
1177 // // lttv_trace_get_hook_field(th, 0));
1178 // // LttField *child = ltt_event_field_element_select(e,
1179 // // lttv_trace_get_hook_field(th, 0), 0);
1180 // // gchar *name_begin =
1181 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1183 // // gchar *null_term_name = g_new(gchar, name_len+1);
1184 // // memcpy(null_term_name, name_begin, name_len);
1185 // // null_term_name[name_len] = '\0';
1186 // // process->name = g_quark_from_string(null_term_name);
1189 // process.setName(getAFieldString(trcEvent, traceSt,
1190 // Fields.LTT_FIELD_FILENAME));
1191 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1201 * LTT_EVENT_THREAD_BRAND
1204 * FIELDS: LTT_FIELD_NAME
1209 final ILttngEventProcessor
GetThreadBrandHandler() {
1210 AbsStateUpdate handler
= new AbsStateUpdate() {
1213 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1216 // Long cpu = trcEvent.getCpuId();
1217 // LttngProcessState process = traceSt.getRunning_process().get(
1220 // name = getAFieldString(trcEvent, traceSt,
1221 // Fields.LTT_FIELD_NAME);
1222 // process.setBrand(name);
1233 final ILttngEventProcessor
getStateDumpEndHandler() {
1234 AbsStateUpdate handler
= new AbsStateUpdate() {
1237 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1239 // /* For all processes */
1241 // * if kernel thread, if stack[0] is unknown, set to syscall
1244 // /* else, if stack[0] is unknown, set to user mode, running */
1245 // List<LttngProcessState> processes = traceSt.getProcesses();
1246 // TmfTimestamp time = trcEvent.getTimestamp();
1248 // for (LttngProcessState process : processes) {
1249 // fix_process(process, time);
1260 * Private method used to establish the first execution state in the stack
1261 * for a given process
1266 // private void fix_process(LttngProcessState process,
1267 // TmfTimestamp timestamp) {
1269 // LttngExecutionState es;
1270 // Stack<LttngExecutionState> procStack = process
1271 // .getExecution_stack();
1273 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1274 // es = procStack.firstElement();
1276 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1277 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1279 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1281 // es.setEntry_Time(timestamp);
1282 // es.setChage_Time(timestamp);
1283 // es.setCum_cpu_time(0L);
1284 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1285 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1289 // es = procStack.firstElement();
1290 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1291 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1293 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1295 // es.setEntry_Time(timestamp);
1296 // es.setChage_Time(timestamp);
1297 // es.setCum_cpu_time(0L);
1298 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1299 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1302 // if (procStack.size() == 1) {
1304 // * Still in bottom unknown mode, means never did a
1305 // * system call May be either in user mode, syscall
1306 // * mode, running or waiting.
1309 // * FIXME : we may be tagging syscall mode when being
1312 // // Get a new execution State
1313 // es = new LttngExecutionState();
1315 // // initialize values
1316 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1318 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1320 // es.setEntry_Time(timestamp);
1321 // es.setChage_Time(timestamp);
1322 // es.setCum_cpu_time(0L);
1323 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1325 // // Push the new state to the stack
1326 // procStack.push(es);
1337 * Handles: LTT_EVENT_PROCESS_STATE
1340 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1341 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1347 final ILttngEventProcessor
getEnumProcessStateHandler() {
1348 AbsStateUpdate handler
= new AbsStateUpdate() {
1351 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1357 // Long cpu = trcEvent.getCpuId();
1358 // LttngProcessState process = traceSt.getRunning_process().get(
1360 // LttngProcessState parent_process;
1362 // // String mode, submode, status;
1363 // LttngExecutionState es;
1366 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1369 // parent_pid = getAFieldLong(trcEvent, traceSt,
1370 // Fields.LTT_FIELD_PARENT_PID);
1372 // /* Command name */
1373 // command = getAFieldString(trcEvent, traceSt,
1374 // Fields.LTT_FIELD_NAME);
1376 // /* TODO: type field, Values need to be verified */
1378 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1379 // Fields.LTT_FIELD_TYPE);
1380 // if (typeVal == 0L) {
1381 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1383 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1386 // // FIXME: type is rarely used, enum must match possible
1390 // // mode = getAFieldString(trcEvent, traceSt,
1391 // // Fields.LTT_FIELD_MODE);
1394 // // submode = getAFieldString(trcEvent, traceSt,
1395 // // Fields.LTT_FIELD_SUBMODE);
1398 // // status = getAFieldString(trcEvent, traceSt,
1399 // // Fields.LTT_FIELD_STATUS);
1402 // tgid = getAFieldLong(trcEvent, traceSt,
1403 // Fields.LTT_FIELD_TGID);
1404 // if (tgid == null) {
1409 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1410 // process = lttv_state_find_process(traceSt, acpu, pid);
1411 // if (process != null) {
1412 // process.setPpid(parent_pid);
1413 // process.setTgid(tgid);
1414 // process.setName(command);
1416 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1418 // StringBuilder sb = new StringBuilder(
1419 // "Unexpected, null process read from the TraceState list of processes, event time: "
1420 // + trcEvent.getTimestamp());
1421 // TraceDebug.debug(sb.toString());
1426 // * The process might exist if a process was forked while
1427 // * performing the state dump.
1429 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1430 // if (process == null) {
1431 // parent_process = lttv_state_find_process(traceSt,
1432 // ANY_CPU, parent_pid);
1433 // process = create_process(traceSt, cpu, pid, tgid,
1434 // command, trcEvent.getTimestamp());
1435 // if (parent_process != null) {
1436 // process.setPpid(parent_process.getPid());
1439 // /* Keep the stack bottom : a running user mode */
1441 // * Disabled because of inconsistencies in the current
1442 // * statedump states.
1444 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1447 // * FIXME Kernel thread : can be in syscall or
1448 // * interrupt or trap.
1451 // * Will cause expected trap when in fact being
1452 // * syscall (even after end of statedump event) Will
1453 // * cause expected interrupt when being syscall.
1454 // * (only before end of statedump event)
1457 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1460 // // es->t = LTTV_STATE_SYSCALL;
1461 // // es->s = status;
1462 // // es->n = submode;
1466 // * User space process : bottom : user mode either
1467 // * currently running or scheduled out. can be
1468 // * scheduled out because interrupted in (user mode
1469 // * or in syscall) or because of an explicit call to
1470 // * the scheduler in syscall. Note that the scheduler
1471 // * call comes after the irq_exit, so never in
1472 // * interrupt context.
1474 // // temp workaround : set size to 1 : only have user
1476 // // bottom of stack.
1477 // // will cause g_info message of expected syscall
1480 // // in user mode. Can also cause expected trap when
1483 // // mode in the event of a page fault reenabling
1485 // // in the handler.
1486 // // Expected syscall and trap can also happen after
1489 // // This will cause a
1490 // // "popping last state on stack, ignoring it."
1492 // // process->execution_stack =
1493 // // g_array_set_size(process->execution_stack, 1);
1494 // // es = process->state =
1495 // // &g_array_index(process->execution_stack,
1496 // // LttvExecutionState, 0);
1497 // // a new process must have only one state in the
1499 // // be the same as the current state
1500 // // es = process.getState();
1501 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1502 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1505 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1506 // // .getInName());
1509 // // es->t = LTTV_STATE_USER_MODE;
1510 // // es->s = status;
1511 // // es->n = submode;
1514 // // TODO: clean up comments above: Moved repeated code
1516 // // if / else blocks above,
1517 // // comments left temporarily for easier visualization
1519 // // comparision with c code
1520 // es = process.getState();
1521 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1522 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1524 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1527 // // /* UNKNOWN STATE */
1529 // // es = process->state =
1530 // // &g_array_index(process->execution_stack,
1531 // // LttvExecutionState, 1);
1532 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1533 // // es->s = LTTV_STATE_UNNAMED;
1534 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1539 // * The process has already been created : Probably was
1540 // * forked while dumping the process state or was simply
1541 // * scheduled in prior to get the state dump event.
1543 // process.setPpid(parent_pid);
1544 // process.setTgid(tgid);
1545 // process.setName(command);
1546 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1549 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1551 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1555 // // &g_array_index(process->execution_stack,
1556 // // LttvExecutionState,
1559 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1560 // // if(type == LTTV_STATE_KERNEL_THREAD)
1561 // // es->t = LTTV_STATE_SYSCALL;
1563 // // es->t = LTTV_STATE_USER_MODE;
1567 // * Don't mess around with the stack, it will eventually
1568 // * become ok after the end of state dump.