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
.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
.Events
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionMode
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionSubMode
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.Fields
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.IEventProcessing
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.handlers
.AbsStateUpdate
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngExecutionState
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
24 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
27 * Process the system call entry event
32 class StateBeforeUpdateHandlers
{
34 final IEventProcessing
getSyscallEntryHandler() {
35 AbsStateUpdate handler
= new AbsStateUpdate() {
37 private Events eventType
= Events
.LTT_EVENT_SYSCALL_ENTRY
;
40 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
41 // TraceDebug.debug("Before event called");
43 Long cpu
= trcEvent
.getCpuId();
45 // No syscall_entry update for initialization process
46 LttngProcessState process
= traceSt
.getRunning_process().get(
49 pid
= process
.getPid();
54 // Get the expected event field
55 Long syscall
= getAFieldLong(trcEvent
, traceSt
,
56 Fields
.LTT_FIELD_SYSCALL_ID
);
57 if (syscall
== null) {
58 TraceDebug
.debug("Syscall Field not found in Event: "
59 + trcEvent
.getMarkerName());
63 String submode
= traceSt
.getSyscall_names().get(syscall
);
65 if (submode
== null) {
66 TraceDebug
.debug("Submode not found in Event");
67 submode
= ExecutionSubMode
.LTTV_STATE_SUBMODE_UNKNOWN
71 exState
= new LttngExecutionState();
72 exState
.setExec_mode(ExecutionMode
.LTTV_STATE_SYSCALL
);
73 exState
.setExec_submode(submode
);
74 exState
.setEntry_Time(trcEvent
.getTimestamp().getValue());
75 exState
.setChange_Time(trcEvent
.getTimestamp().getValue());
76 exState
.setCum_cpu_time(0L);
82 public Events
getEventHandleType() {
89 final IEventProcessing
getsySyscallExitHandler() {
90 AbsStateUpdate handler
= new AbsStateUpdate() {
92 private Events eventType
= Events
.LTT_EVENT_SYSCALL_EXIT
;
95 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
97 Long cpu
= trcEvent
.getCpuId();
98 LttngProcessState process
= traceSt
.getRunning_process().get(
101 /* There can be no system call from PID 0 : unknown state */
102 pid
= process
.getPid();
107 // pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
108 // traceSt, trcEvent.getTimestamp());
114 public Events
getEventHandleType() {
122 * Update stacks related to the parsing of an LttngEvent
126 final IEventProcessing
getTrapEntryHandler() {
127 AbsStateUpdate handler
= new AbsStateUpdate() {
129 private Events eventType
= Events
.LTT_EVENT_TRAP_ENTRY
;
132 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
133 // Long cpu = trcEvent.getCpuId();
135 // Long trap = getAFieldLong(trcEvent, traceSt,
136 // Fields.LTT_FIELD_TRAP_ID);
137 // if (trap == null) {
141 // String submode = traceSt.getSyscall_names()
144 // if (submode == null) {
145 // submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
149 // /* update process state */
150 // push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
151 // submode, trcEvent.getTimestamp(), traceSt);
153 // /* update cpu status */
154 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
155 // cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
156 // cpust.setLast_trap(trap); /* update trap status */
158 // // update Trap State
159 // LttngTrapState trap_state = traceSt.getTrap_states().get(
161 // trap_state.incrementRunning();
168 public Events
getEventHandleType() {
179 final IEventProcessing
getTrapExitHandler() {
180 AbsStateUpdate handler
= new AbsStateUpdate() {
182 private Events eventType
= Events
.LTT_EVENT_TRAP_EXIT
;
185 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
187 // Long cpu = trcEvent.getCpuId();
188 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
189 // Long trap = cpust.getLast_trap();
191 // pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt,
195 // /* update cpu status */
196 // cpu_pop_mode(cpust);
198 // /* update trap status */
199 // if (trap != -1L) {
200 // traceSt.getTrap_states().get(trap).decrementRunning();
207 public Events
getEventHandleType() {
218 final IEventProcessing
getIrqEntryHandler() {
219 AbsStateUpdate handler
= new AbsStateUpdate() {
221 private Events eventType
= Events
.LTT_EVENT_IRQ_ENTRY
;
224 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
226 // Long cpu = trcEvent.getCpuId();
228 // Long irq = getAFieldLong(trcEvent, traceSt,
229 // Fields.LTT_FIELD_IRQ_ID);
230 // if (irq == null) {
235 // submode = traceSt.getIrq_names().get(irq);
237 // if (submode == null) {
239 // ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN.getInName();
243 // * Do something with the info about being in user or system
247 // push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode,
249 // .getTimestamp(), traceSt);
251 // /* update cpu state */
252 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
253 // cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
254 // cpust.setLast_irq(irq); /* last irq */
256 // /* udpate irq state */
257 // irq_push_mode(traceSt.getIrq_states().get(irq),
258 // IRQMode.LTTV_IRQ_BUSY);
263 public Events
getEventHandleType() {
274 final IEventProcessing
getSoftIrqExitHandler() {
275 AbsStateUpdate handler
= new AbsStateUpdate() {
277 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_EXIT
;
280 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
282 // Long cpu = trcEvent.getCpuId();
283 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
284 // Long softirq = cpust.getLast_soft_irq();
285 // pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
286 // trcEvent.getTimestamp());
288 // /* update softirq status */
289 // if (softirq != -1) {
290 // LttngSoftIRQState softIrqstate = traceSt
291 // .getSoft_irq_states().get(softirq);
292 // softIrqstate.decrementRunning();
295 // /* update cpu status */
296 // cpu_pop_mode(cpust);
302 public Events
getEventHandleType() {
313 final IEventProcessing
getIrqExitHandler() {
314 AbsStateUpdate handler
= new AbsStateUpdate() {
316 private Events eventType
= Events
.LTT_EVENT_IRQ_EXIT
;
319 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
321 // Long cpu = trcEvent.getCpuId();
323 // /* update process state */
324 // pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt,
328 // /* update cpu status */
329 // LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
330 // cpu_pop_mode(cpust);
332 // /* update irq status */
333 // Long last_irq = cpust.getLast_irq();
334 // if (last_irq != -1L) {
335 // LttngIRQState irq_state = traceSt.getIrq_states().get(
337 // irq_pop_mode(irq_state);
345 public Events
getEventHandleType() {
356 final IEventProcessing
getSoftIrqRaiseHandler() {
357 AbsStateUpdate handler
= new AbsStateUpdate() {
359 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_RAISE
;
362 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
364 // // Long cpu = trcEvent.getCpuId();
366 // // get event field
367 // Long softirq = getAFieldLong(trcEvent, traceSt,
368 // Fields.LTT_FIELD_SOFT_IRQ_ID);
370 // if (softirq == null) {
374 // // String submode;
375 // // String[] softIrqNames = traceSt.getSoft_irq_names();
376 // // if (softirq < softIrqNames.length) {
377 // // submode = softIrqNames[softirq];
379 // // submode = "softirq " + softirq;
382 // /* update softirq status */
383 // /* a soft irq raises are not cumulative */
384 // LttngSoftIRQState irqState =
385 // traceSt.getSoft_irq_states().get(
387 // if (irqState != null) {
388 // irqState.setPending(1L);
391 // .debug("unexpected soft irq id value: " + softirq);
399 public Events
getEventHandleType() {
410 final IEventProcessing
getSoftIrqEntryHandler() {
411 AbsStateUpdate handler
= new AbsStateUpdate() {
413 private Events eventType
= Events
.LTT_EVENT_SOFT_IRQ_ENTRY
;
416 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
419 // Long cpu = trcEvent.getCpuId();
421 // // get event field
422 // Long softirq = getAFieldLong(trcEvent, traceSt,
423 // Fields.LTT_FIELD_SOFT_IRQ_ID);
425 // if (softirq == null) {
430 // Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
431 // String submode = softIrqNames.get(softirq);
432 // if (submode == null) {
433 // submode = "softirq " + softirq;
434 // softIrqNames.put(softirq, submode);
437 // /* update softirq status */
438 // LttngSoftIRQState irqState =
439 // traceSt.getSoft_irq_states().get(
441 // if (irqState != null) {
442 // irqState.decrementPending();
443 // irqState.incrementRunning();
446 // .debug("unexpected soft irq id value: " + softirq);
449 // /* update cpu state */
450 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
451 // cpu_state.setLast_soft_irq(softirq);
452 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
454 // /* update process execution mode state stack */
455 // push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
456 // trcEvent.getTimestamp(), traceSt);
463 public Events
getEventHandleType() {
471 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
475 final IEventProcessing
getEnumInterruptHandler() {
476 AbsStateUpdate handler
= new AbsStateUpdate() {
478 private Events eventType
= Events
.LTT_EVENT_LIST_INTERRUPT
;
481 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
482 // String action = getAFieldString(trcEvent, traceSt,
483 // Fields.LTT_FIELD_ACTION);
484 // Long irq = getAFieldLong(trcEvent, traceSt,
485 // Fields.LTT_FIELD_IRQ_ID);
487 // Map<Long, String> irq_names = traceSt.getIrq_names();
489 // irq_names.put(irq, action);
495 public Events
getEventHandleType() {
503 * Handle the event LTT_EVENT_REQUEST_ISSUE
507 final IEventProcessing
getBdevRequestIssueHandler() {
508 AbsStateUpdate handler
= new AbsStateUpdate() {
510 private Events eventType
= Events
.LTT_EVENT_REQUEST_ISSUE
;
513 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
516 // Long major = getAFieldLong(trcEvent, traceSt,
517 // Fields.LTT_FIELD_MAJOR);
518 // Long minor = getAFieldLong(trcEvent, traceSt,
519 // Fields.LTT_FIELD_MINOR);
520 // Long operation = getAFieldLong(trcEvent, traceSt,
521 // Fields.LTT_FIELD_OPERATION);
523 // // calculate bdevcode
524 // Long devcode = mkdev(major, minor);
526 // if (devcode == null) {
528 // .debug("incorrect calcualtion of bdevcode input( major: "
532 // + " operation: " + operation);
536 // Map<Long, LttngBdevState> bdev_states = traceSt
537 // .getBdev_states();
538 // // Get the instance
539 // LttngBdevState bdevState = bdev_states.get(devcode);
540 // if (bdevState == null) {
541 // bdevState = new LttngBdevState();
544 // // update the mode in the stack
545 // if (operation == 0L) {
546 // bdevState.getMode_stack().push(
547 // BdevMode.LTTV_BDEV_BUSY_READING);
549 // bdevState.getMode_stack().push(
550 // BdevMode.LTTV_BDEV_BUSY_WRITING);
553 // // make sure it is included in the set
554 // bdev_states.put(devcode, bdevState);
560 public Events
getEventHandleType() {
569 * Handling event: LTT_EVENT_REQUEST_COMPLETE
572 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
577 final IEventProcessing
getBdevRequestCompleteHandler() {
578 AbsStateUpdate handler
= new AbsStateUpdate() {
580 private Events eventType
= Events
.LTT_EVENT_REQUEST_COMPLETE
;
583 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
586 // Long major = getAFieldLong(trcEvent, traceSt,
587 // Fields.LTT_FIELD_MAJOR);
588 // Long minor = getAFieldLong(trcEvent, traceSt,
589 // Fields.LTT_FIELD_MINOR);
590 // Long operation = getAFieldLong(trcEvent, traceSt,
591 // Fields.LTT_FIELD_OPERATION);
593 // // calculate bdevcode
594 // Long devcode = mkdev(major, minor);
596 // if (devcode == null) {
598 // .debug("incorrect calcualtion of bdevcode input( major: "
602 // + " operation: " + operation);
606 // Map<Long, LttngBdevState> bdev_states = traceSt
607 // .getBdev_states();
608 // // Get the instance
609 // LttngBdevState bdevState = bdev_states.get(devcode);
610 // if (bdevState == null) {
611 // bdevState = new LttngBdevState();
614 // /* update block device */
615 // bdev_pop_mode(bdevState);
622 public Events
getEventHandleType() {
631 * Handles event: LTT_EVENT_FUNCTION_ENTRY
634 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
639 final IEventProcessing
getFunctionEntryHandler() {
640 AbsStateUpdate handler
= new AbsStateUpdate() {
642 private Events eventType
= Events
.LTT_EVENT_FUNCTION_ENTRY
;
645 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
646 // Long cpu = trcEvent.getCpuId();
647 // Long funcptr = getAFieldLong(trcEvent, traceSt,
648 // Fields.LTT_FIELD_THIS_FN);
650 // push_function(traceSt, funcptr, cpu);
656 public Events
getEventHandleType() {
667 final IEventProcessing
getFunctionExitHandler() {
668 AbsStateUpdate handler
= new AbsStateUpdate() {
670 private Events eventType
= Events
.LTT_EVENT_FUNCTION_EXIT
;
673 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
675 // Long funcptr = getAFieldLong(trcEvent, traceSt,
676 // Fields.LTT_FIELD_THIS_FN);
678 // pop_function(traceSt, trcEvent, funcptr);
684 public Events
getEventHandleType() {
693 * process event: LTT_EVENT_SYS_CALL_TABLE
696 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
701 final IEventProcessing
getDumpSyscallHandler() {
702 AbsStateUpdate handler
= new AbsStateUpdate() {
704 private Events eventType
= Events
.LTT_EVENT_SYS_CALL_TABLE
;
707 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
708 // // obtain the syscall id
709 // Long id = getAFieldLong(trcEvent, traceSt,
710 // Fields.LTT_FIELD_ID);
712 // // Long address = getAFieldLong(trcEvent, traceSt,
713 // // Fields.LTT_FIELD_ADDRESS);
715 // // Obtain the symbol
716 // String symbol = getAFieldString(trcEvent, traceSt,
717 // Fields.LTT_FIELD_SYMBOL);
719 // // fill the symbol to the sycall_names collection
720 // traceSt.getSyscall_names().put(id, symbol);
726 public Events
getEventHandleType() {
735 * Handles event: LTT_EVENT_KPROBE_TABLE
738 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
743 final IEventProcessing
getDumpKprobeHandler() {
744 AbsStateUpdate handler
= new AbsStateUpdate() {
746 private Events eventType
= Events
.LTT_EVENT_KPROBE_TABLE
;
749 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
751 // Long ip = getAFieldLong(trcEvent, traceSt,
752 // Fields.LTT_FIELD_IP);
753 // String symbol = getAFieldString(trcEvent, traceSt,
754 // Fields.LTT_FIELD_SYMBOL);
756 // traceSt.getKprobe_table().put(ip, symbol);
763 public Events
getEventHandleType() {
772 * Handles: LTT_EVENT_SOFTIRQ_VEC
775 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
780 final IEventProcessing
getDumpSoftIrqHandler() {
781 AbsStateUpdate handler
= new AbsStateUpdate() {
783 private Events eventType
= Events
.LTT_EVENT_SOFTIRQ_VEC
;
786 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
789 // Long id = getAFieldLong(trcEvent, traceSt,
790 // Fields.LTT_FIELD_ID);
792 // // Address not needed
793 // // Long address = ltt_event_get_long_unsigned(e,
794 // // lttv_trace_get_hook_field(th,
798 // String symbol = getAFieldString(trcEvent, traceSt,
799 // Fields.LTT_FIELD_SYMBOL);
801 // // Register the soft irq name
802 // traceSt.getSoft_irq_names().put(id, symbol);
808 public Events
getEventHandleType() {
817 * Handles: LTT_EVENT_SCHED_SCHEDULE
820 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
825 final IEventProcessing
getSchedChangeHandler() {
826 AbsStateUpdate handler
= new AbsStateUpdate() {
828 private Events eventType
= Events
.LTT_EVENT_SCHED_SCHEDULE
;
831 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
833 // Long cpu = trcEvent.getCpuId();
834 // TmfTimestamp eventTime = trcEvent.getTimestamp();
836 // LttngProcessState process = traceSt.getRunning_process().get(
839 // Long pid_out = getAFieldLong(trcEvent, traceSt,
840 // Fields.LTT_FIELD_PREV_PID);
841 // Long pid_in = getAFieldLong(trcEvent, traceSt,
842 // Fields.LTT_FIELD_NEXT_PID);
843 // Long state_out = getAFieldLong(trcEvent, traceSt,
844 // Fields.LTT_FIELD_PREV_STATE);
846 // if (process != null) {
849 // * We could not know but it was not the idle process
850 // * executing. This should only happen at the beginning,
851 // * before the first schedule event, and when the initial
852 // * information (current process for each CPU) is missing. It
853 // * is not obvious how we could, after the fact, compensate
854 // * the wrongly attributed statistics.
857 // // This test only makes sense once the state is known and if
860 // // missing events. We need to silently ignore schedchange
863 // // process_free, or it causes glitches. (FIXME)
864 // // if(unlikely(process->pid != pid_out)) {
865 // // g_assert(process->pid == 0);
867 // if (process.getPid() == 0
868 // && process.getState().getExec_mode() ==
869 // ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
870 // if (pid_out == 0) {
872 // * Scheduling out of pid 0 at beginning of the trace
873 // * : we know for sure it is in syscall mode at this
876 // int stackSize = process.getExecution_stack().size();
877 // if (stackSize != 1) {
879 // .debug("unpexpected process execution stack size, expected 1, received: ");
882 // process.getState().setExec_mode(
883 // ExecutionMode.LTTV_STATE_SYSCALL);
884 // process.getState().setProc_status(
885 // ProcessStatus.LTTV_STATE_WAIT);
886 // process.getState().setChage_Time(
887 // trcEvent.getTimestamp());
888 // process.getState().setEntry_Time(
889 // trcEvent.getTimestamp());
892 // if (process.getState().getProc_status() ==
893 // ProcessStatus.LTTV_STATE_EXIT) {
894 // process.getState().setProc_status(
895 // ProcessStatus.LTTV_STATE_ZOMBIE);
896 // process.getState().setChage_Time(
897 // trcEvent.getTimestamp());
899 // if (state_out == 0L) {
900 // process.getState().setProc_status(
901 // ProcessStatus.LTTV_STATE_WAIT_CPU);
903 // process.getState().setProc_status(
904 // ProcessStatus.LTTV_STATE_WAIT);
907 // process.getState().setChage_Time(
908 // trcEvent.getTimestamp());
911 // if (state_out == 32L || state_out == 64L) { /*
916 // /* see sched.h for states */
917 // if (!exit_process(traceSt, process)) {
918 // process.getState().setProc_status(
919 // ProcessStatus.LTTV_STATE_DEAD);
920 // process.getState().setChage_Time(
921 // trcEvent.getTimestamp());
926 // process = lttv_state_find_process_or_create(traceSt, cpu,
927 // pid_in, eventTime);
929 // traceSt.getRunning_process().put(cpu, process);
931 // process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
932 // process.getState().setChage_Time(eventTime);
933 // process.setCpu(cpu);
934 // // process->state->s = LTTV_STATE_RUN;
935 // // if(process->usertrace)
936 // // process->usertrace->cpu = cpu;
937 // // process->last_cpu_index =
938 // // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
940 // // process->state->change = s->parent.timestamp;
942 // LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
943 // /* update cpu status */
944 // if (pid_in == 0) {
946 // /* going to idle task */
947 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
950 // * scheduling a real task. we must be careful here: if we
951 // * just schedule()'ed to a process that is in a trap, we
952 // * must put the cpu in trap mode
954 // cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
955 // if (process.getState().getExec_mode() ==
956 // ExecutionMode.LTTV_STATE_TRAP) {
957 // cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
965 public Events
getEventHandleType() {
974 * Handles: LTT_EVENT_PROCESS_FORK
977 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
978 * LTT_FIELD_CHILD_TGID)
983 final IEventProcessing
getProcessForkHandler() {
984 AbsStateUpdate handler
= new AbsStateUpdate() {
986 private Events eventType
= Events
.LTT_EVENT_PROCESS_FORK
;
989 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
991 // Long cpu = trcEvent.getCpuId();
992 // LttngProcessState process = traceSt.getRunning_process().get(
994 // TmfTimestamp timeStamp = trcEvent.getTimestamp();
996 // // /* Parent PID */
997 // // Long parent_pid = getAFieldLong(trcEvent, traceSt,
998 // // Fields.LTT_FIELD_PARENT_PID);
1001 // /* In the Linux Kernel, there is one PID per thread. */
1002 // Long child_pid = getAFieldLong(trcEvent, traceSt,
1003 // Fields.LTT_FIELD_CHILD_PID);
1006 // /* tgid in the Linux kernel is the "real" POSIX PID. */
1007 // Long child_tgid = getAFieldLong(trcEvent, traceSt,
1008 // Fields.LTT_FIELD_CHILD_TGID);
1009 // if (child_tgid == null) {
1014 // * Mathieu : it seems like the process might have been
1016 // * in before the fork, and, in a rare case, might be the
1018 // * process. This might happen in a SMP case where we don't
1020 // * enough precision on the clocks.
1022 // * Test reenabled after precision fixes on time. (Mathieu)
1025 // // zombie_process = lttv_state_find_process(ts, ANY_CPU,
1028 // // if(unlikely(zombie_process != NULL)) {
1029 // // /* Reutilisation of PID. Only now we are sure that the old
1031 // // * has been released. FIXME : should know when release_task
1035 // // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1037 // // for(i=0; i< num_cpus; i++) {
1038 // // g_assert(zombie_process != ts->running_process[i]);
1041 // // exit_process(s, zombie_process);
1045 // if (process.getPid() == child_pid) {
1047 // .debug("Unexpected, process pid equal to child pid: "
1049 // + " Event Time: "
1050 // + trcEvent.getTimestamp());
1053 // // g_assert(process->pid != child_pid);
1054 // // FIXME : Add this test in the "known state" section
1055 // // g_assert(process->pid == parent_pid);
1056 // LttngProcessState child_process = lttv_state_find_process(
1057 // traceSt, ANY_CPU, child_pid);
1058 // if (child_process == null) {
1059 // child_process = create_process(traceSt, cpu, child_pid,
1060 // child_tgid, timeStamp);
1063 // * The process has already been created : due to time
1064 // * imprecision between multiple CPUs : it has been scheduled
1065 // * in before creation. Note that we shouldn't have this kind
1066 // * of imprecision.
1068 // * Simply put a correct parent.
1070 // StringBuilder sb = new StringBuilder("Process " + child_pid);
1071 // sb.append(" has been created at ["
1072 // + child_process.getCration_time() + "] ");
1073 // sb.append("and inserted at ["
1074 // + child_process.getInsertion_time() + "] ");
1075 // sb.append("before \nfork on cpu " + cpu + " Event time: ["
1076 // + trcEvent + "]\n.");
1078 // .append("Probably an unsynchronized TSD problem on the traced machine.");
1079 // TraceDebug.debug(sb.toString());
1081 // // g_assert(0); /* This is a problematic case : the process
1084 // // before the fork event */
1085 // child_process.setPpid(process.getPid());
1086 // child_process.setTgid(child_tgid);
1089 // if (!child_process.getName().equals(
1090 // ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
1091 // TraceDebug.debug("Unexpected child process status: "
1092 // + child_process.getName());
1095 // child_process.setName(process.getName());
1096 // child_process.setBrand(process.getBrand());
1103 public Events
getEventHandleType() {
1112 * Handles: LTT_EVENT_KTHREAD_CREATE
1115 * Fields: LTT_FIELD_PID
1120 final IEventProcessing
getProcessKernelThreadHandler() {
1121 AbsStateUpdate handler
= new AbsStateUpdate() {
1123 private Events eventType
= Events
.LTT_EVENT_KTHREAD_CREATE
;
1126 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1128 // * We stamp a newly created process as kernel_thread. The
1130 // * should not be running yet.
1133 // LttngExecutionState exState;
1135 // LttngProcessState process;
1138 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1139 // // s->parent.target_pid = pid;
1141 // process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1142 // pid, new TmfTimestamp());
1144 // if (!process.getState().getProc_status().equals(
1145 // ProcessStatus.LTTV_STATE_DEAD)) {
1146 // // Leave only the first element in the stack with execution
1149 // Stack<LttngExecutionState> processExStack = process
1150 // .getExecution_stack();
1151 // exState = processExStack.firstElement();
1152 // exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1153 // if (processExStack.size() > 1) {
1154 // processExStack.clear();
1155 // processExStack.add(exState);
1158 // // update the process state to the only one in the stack
1159 // process.setState(exState);
1162 // process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1169 public Events
getEventHandleType() {
1178 * Handles: LTT_EVENT_PROCESS_EXIT
1186 final IEventProcessing
getProcessExitHandler() {
1187 AbsStateUpdate handler
= new AbsStateUpdate() {
1189 private Events eventType
= Events
.LTT_EVENT_PROCESS_EXIT
;
1192 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1195 // LttngProcessState process;
1197 // pid = getAFieldLong(trcEvent, traceSt,
1198 // Fields.LTT_FIELD_PID);
1199 // // s->parent.target_pid = pid;
1201 // // FIXME : Add this test in the "known state" section
1202 // // g_assert(process->pid == pid);
1204 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1205 // if (process != null) {
1206 // process.getState().setProc_status(
1207 // ProcessStatus.LTTV_STATE_EXIT);
1214 public Events
getEventHandleType() {
1223 * Handles: LTT_EVENT_PROCESS_FREE
1226 * Fields: LTT_FIELD_PID
1231 final IEventProcessing
getProcessFreeHandler() {
1232 AbsStateUpdate handler
= new AbsStateUpdate() {
1234 private Events eventType
= Events
.LTT_EVENT_PROCESS_FREE
;
1237 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1239 // Long release_pid;
1240 // LttngProcessState process;
1242 // /* PID of the process to release */
1243 // release_pid = getAFieldLong(trcEvent, traceSt,
1244 // Fields.LTT_FIELD_PID);
1245 // // s->parent.target_pid = release_pid;
1247 // if (release_pid == 0) {
1248 // TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1249 // + trcEvent.getTimestamp());
1252 // process = lttv_state_find_process(traceSt, ANY_CPU,
1254 // if (process != null) {
1255 // exit_process(traceSt, process);
1260 // if(process != null) {
1262 * release_task is happening at kernel level : we can now safely
1263 * release the data structure of the process
1265 // This test is fun, though, as it may happen that
1266 // at time t : CPU 0 : process_free
1267 // at time t+150ns : CPU 1 : schedule out
1268 // Clearly due to time imprecision, we disable it. (Mathieu)
1269 // If this weird case happen, we have no choice but to put the
1270 // Currently running process on the cpu to 0.
1271 // I re-enable it following time precision fixes. (Mathieu)
1272 // Well, in the case where an process is freed by a process on
1275 // and still scheduled, it happens that this is the schedchange
1278 // drop the last reference count. Do not free it here!
1280 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1282 // for(i=0; i< num_cpus; i++) {
1283 // //g_assert(process != ts->running_process[i]);
1284 // if(process == ts->running_process[i]) {
1285 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1289 // if(i == num_cpus) /* process is not scheduled */
1290 // exit_process(s, process);
1298 public Events
getEventHandleType() {
1307 * Handles: LTT_EVENT_EXEC
1310 * FIELDS: LTT_FIELD_FILENAME
1315 final IEventProcessing
getProcessExecHandler() {
1316 AbsStateUpdate handler
= new AbsStateUpdate() {
1318 private Events eventType
= Events
.LTT_EVENT_EXEC
;
1321 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1323 // Long cpu = trcEvent.getCpuId();
1324 // LttngProcessState process = traceSt.getRunning_process().get(
1327 // // #if 0//how to use a sequence that must be transformed in a
1329 // // /* PID of the process to release */
1330 // // guint64 name_len = ltt_event_field_element_number(e,
1331 // // lttv_trace_get_hook_field(th, 0));
1332 // // //name = ltt_event_get_string(e,
1333 // // lttv_trace_get_hook_field(th, 0));
1334 // // LttField *child = ltt_event_field_element_select(e,
1335 // // lttv_trace_get_hook_field(th, 0), 0);
1336 // // gchar *name_begin =
1337 // // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e,
1339 // // gchar *null_term_name = g_new(gchar, name_len+1);
1340 // // memcpy(null_term_name, name_begin, name_len);
1341 // // null_term_name[name_len] = '\0';
1342 // // process->name = g_quark_from_string(null_term_name);
1345 // process.setName(getAFieldString(trcEvent, traceSt,
1346 // Fields.LTT_FIELD_FILENAME));
1347 // process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1353 public Events
getEventHandleType() {
1362 * LTT_EVENT_THREAD_BRAND
1365 * FIELDS: LTT_FIELD_NAME
1370 final IEventProcessing
GetThreadBrandHandler() {
1371 AbsStateUpdate handler
= new AbsStateUpdate() {
1373 private Events eventType
= Events
.LTT_EVENT_THREAD_BRAND
;
1376 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1379 // Long cpu = trcEvent.getCpuId();
1380 // LttngProcessState process = traceSt.getRunning_process().get(
1383 // name = getAFieldString(trcEvent, traceSt,
1384 // Fields.LTT_FIELD_NAME);
1385 // process.setBrand(name);
1391 public Events
getEventHandleType() {
1401 final IEventProcessing
getStateDumpEndHandler() {
1402 AbsStateUpdate handler
= new AbsStateUpdate() {
1404 private Events eventType
= Events
.LTT_EVENT_STATEDUMP_END
;
1407 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1409 // /* For all processes */
1411 // * if kernel thread, if stack[0] is unknown, set to syscall
1414 // /* else, if stack[0] is unknown, set to user mode, running */
1415 // List<LttngProcessState> processes = traceSt.getProcesses();
1416 // TmfTimestamp time = trcEvent.getTimestamp();
1418 // for (LttngProcessState process : processes) {
1419 // fix_process(process, time);
1427 public Events
getEventHandleType() {
1435 * Private method used to establish the first execution state in the stack
1436 * for a given process
1441 // private void fix_process(LttngProcessState process,
1442 // TmfTimestamp timestamp) {
1444 // LttngExecutionState es;
1445 // Stack<LttngExecutionState> procStack = process
1446 // .getExecution_stack();
1448 // if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1449 // es = procStack.firstElement();
1451 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1452 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1454 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1456 // es.setEntry_Time(timestamp);
1457 // es.setChage_Time(timestamp);
1458 // es.setCum_cpu_time(0L);
1459 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1460 // es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1464 // es = procStack.firstElement();
1465 // if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1466 // es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1468 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1470 // es.setEntry_Time(timestamp);
1471 // es.setChage_Time(timestamp);
1472 // es.setCum_cpu_time(0L);
1473 // if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1474 // es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1477 // if (procStack.size() == 1) {
1479 // * Still in bottom unknown mode, means never did a
1480 // * system call May be either in user mode, syscall
1481 // * mode, running or waiting.
1484 // * FIXME : we may be tagging syscall mode when being
1487 // // Get a new execution State
1488 // es = new LttngExecutionState();
1490 // // initialize values
1491 // es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1493 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1495 // es.setEntry_Time(timestamp);
1496 // es.setChage_Time(timestamp);
1497 // es.setCum_cpu_time(0L);
1498 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1500 // // Push the new state to the stack
1501 // procStack.push(es);
1512 * Handles: LTT_EVENT_PROCESS_STATE
1515 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1516 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1522 final IEventProcessing
getEnumProcessStateHandler() {
1523 AbsStateUpdate handler
= new AbsStateUpdate() {
1525 private Events eventType
= Events
.LTT_EVENT_PROCESS_STATE
;
1528 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
1534 // Long cpu = trcEvent.getCpuId();
1535 // LttngProcessState process = traceSt.getRunning_process().get(
1537 // LttngProcessState parent_process;
1539 // // String mode, submode, status;
1540 // LttngExecutionState es;
1543 // pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1546 // parent_pid = getAFieldLong(trcEvent, traceSt,
1547 // Fields.LTT_FIELD_PARENT_PID);
1549 // /* Command name */
1550 // command = getAFieldString(trcEvent, traceSt,
1551 // Fields.LTT_FIELD_NAME);
1553 // /* TODO: type field, Values need to be verified */
1555 // Long typeVal = getAFieldLong(trcEvent, traceSt,
1556 // Fields.LTT_FIELD_TYPE);
1557 // if (typeVal == 0L) {
1558 // type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
1560 // type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1563 // // FIXME: type is rarely used, enum must match possible
1567 // // mode = getAFieldString(trcEvent, traceSt,
1568 // // Fields.LTT_FIELD_MODE);
1571 // // submode = getAFieldString(trcEvent, traceSt,
1572 // // Fields.LTT_FIELD_SUBMODE);
1575 // // status = getAFieldString(trcEvent, traceSt,
1576 // // Fields.LTT_FIELD_STATUS);
1579 // tgid = getAFieldLong(trcEvent, traceSt,
1580 // Fields.LTT_FIELD_TGID);
1581 // if (tgid == null) {
1586 // for (Long acpu : traceSt.getCpu_states().keySet()) {
1587 // process = lttv_state_find_process(traceSt, acpu, pid);
1588 // if (process != null) {
1589 // process.setPpid(parent_pid);
1590 // process.setTgid(tgid);
1591 // process.setName(command);
1593 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1595 // StringBuilder sb = new StringBuilder(
1596 // "Unexpected, null process read from the TraceState list of processes, event time: "
1597 // + trcEvent.getTimestamp());
1598 // TraceDebug.debug(sb.toString());
1603 // * The process might exist if a process was forked while
1604 // * performing the state dump.
1606 // process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1607 // if (process == null) {
1608 // parent_process = lttv_state_find_process(traceSt,
1609 // ANY_CPU, parent_pid);
1610 // process = create_process(traceSt, cpu, pid, tgid,
1611 // command, trcEvent.getTimestamp());
1612 // if (parent_process != null) {
1613 // process.setPpid(parent_process.getPid());
1616 // /* Keep the stack bottom : a running user mode */
1618 // * Disabled because of inconsistencies in the current
1619 // * statedump states.
1621 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1624 // * FIXME Kernel thread : can be in syscall or
1625 // * interrupt or trap.
1628 // * Will cause expected trap when in fact being
1629 // * syscall (even after end of statedump event) Will
1630 // * cause expected interrupt when being syscall.
1631 // * (only before end of statedump event)
1634 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1637 // // es->t = LTTV_STATE_SYSCALL;
1638 // // es->s = status;
1639 // // es->n = submode;
1643 // * User space process : bottom : user mode either
1644 // * currently running or scheduled out. can be
1645 // * scheduled out because interrupted in (user mode
1646 // * or in syscall) or because of an explicit call to
1647 // * the scheduler in syscall. Note that the scheduler
1648 // * call comes after the irq_exit, so never in
1649 // * interrupt context.
1651 // // temp workaround : set size to 1 : only have user
1653 // // bottom of stack.
1654 // // will cause g_info message of expected syscall
1657 // // in user mode. Can also cause expected trap when
1660 // // mode in the event of a page fault reenabling
1662 // // in the handler.
1663 // // Expected syscall and trap can also happen after
1666 // // This will cause a
1667 // // "popping last state on stack, ignoring it."
1669 // // process->execution_stack =
1670 // // g_array_set_size(process->execution_stack, 1);
1671 // // es = process->state =
1672 // // &g_array_index(process->execution_stack,
1673 // // LttvExecutionState, 0);
1674 // // a new process must have only one state in the
1676 // // be the same as the current state
1677 // // es = process.getState();
1678 // // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1679 // // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1682 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1683 // // .getInName());
1686 // // es->t = LTTV_STATE_USER_MODE;
1687 // // es->s = status;
1688 // // es->n = submode;
1691 // // TODO: clean up comments above: Moved repeated code
1693 // // if / else blocks above,
1694 // // comments left temporarily for easier visualization
1696 // // comparision with c code
1697 // es = process.getState();
1698 // es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1699 // es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1701 // .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1704 // // /* UNKNOWN STATE */
1706 // // es = process->state =
1707 // // &g_array_index(process->execution_stack,
1708 // // LttvExecutionState, 1);
1709 // // es->t = LTTV_STATE_MODE_UNKNOWN;
1710 // // es->s = LTTV_STATE_UNNAMED;
1711 // // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1716 // * The process has already been created : Probably was
1717 // * forked while dumping the process state or was simply
1718 // * scheduled in prior to get the state dump event.
1720 // process.setPpid(parent_pid);
1721 // process.setTgid(tgid);
1722 // process.setName(command);
1723 // if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1726 // .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1728 // process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1732 // // &g_array_index(process->execution_stack,
1733 // // LttvExecutionState,
1736 // // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1737 // // if(type == LTTV_STATE_KERNEL_THREAD)
1738 // // es->t = LTTV_STATE_SYSCALL;
1740 // // es->t = LTTV_STATE_USER_MODE;
1744 // * Don't mess around with the stack, it will eventually
1745 // * become ok after the end of state dump.
1755 public Events
getEventHandleType() {