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
.evProcessor
.state
;
15 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
16 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
17 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
;
18 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ExecutionMode
;
19 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.IRQMode
;
20 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.ProcessStatus
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ILttngEventProcessor
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LTTngCPUState
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngBdevState
;
24 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngExecutionState
;
25 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngIRQState
;
26 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngProcessState
;
27 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
28 import org
.eclipse
.linuxtools
.tmf
.event
.TmfTimestamp
;
30 public abstract class AbsStateUpdate
extends AbsStateProcessing
implements
31 ILttngEventProcessor
{
33 // ========================================================================
35 // =======================================================================
36 protected static final Long ANY_CPU
= 0L;
38 // ========================================================================
39 // push and pop from stack
40 // =======================================================================
41 protected void push_state(Long cpu
, StateStrings
.ExecutionMode execMode
,
42 String submode
, TmfTimestamp eventTime
, LttngTraceState traceSt
) {
44 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
45 LttngExecutionState exe_state
= new LttngExecutionState();
46 exe_state
.setExec_mode(execMode
);
47 exe_state
.setExec_submode(submode
);
48 exe_state
.setEntry_Time(eventTime
.getValue());
49 exe_state
.setChange_Time(eventTime
.getValue());
50 exe_state
.setCum_cpu_time(0L);
51 exe_state
.setProc_status(process
.getState().getProc_status());
52 process
.pushToExecutionStack(exe_state
);
55 protected void pop_state(Long cpu
, StateStrings
.ExecutionMode execMode
,
56 LttngTraceState traceSt
, TmfTimestamp eventTime
) {
58 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
60 if (!process
.getState().getExec_mode().equals(execMode
)) {
61 // Different execution mode
62 TraceDebug
.debug("Different Execution Mode type \n\tTime:"
63 + eventTime
.toString() + "\n\tprocess state has: \n\t"
64 + process
.getState().getExec_mode().toString()
65 + "\n\twhen pop_int is:\n\t" + execMode
.toString());
69 //The process state is updated within the pop method
70 process
.popFromExecutionStack();
71 process
.getState().setChange_Time(eventTime
.getValue());
74 protected void irq_push_mode(LttngIRQState irqst
, IRQMode state
) {
75 irqst
.pushToIrqStack(state
);
78 protected void irq_set_base_mode(LttngIRQState irqst
, IRQMode state
) {
79 irqst
.clearAndSetBaseToIrqStack(state
);
82 protected void irq_pop_mode(LttngIRQState irqst
) {
83 irqst
.popFromIrqStack();
86 protected void cpu_push_mode(LTTngCPUState cpust
, StateStrings
.CpuMode state
) {
87 // The initialization (init) creates a LttngCPUState instance per
88 // available cpu in the system
89 cpust
.pushToCpuStack(state
);
92 protected void cpu_pop_mode(LTTngCPUState cpust
) {
93 cpust
.popFromCpuStack();
96 /* clears the stack and sets the state passed as argument */
97 protected void cpu_set_base_mode(LTTngCPUState cpust
,
98 StateStrings
.CpuMode state
) {
99 cpust
.clearAndSetBaseToCpuStack(state
);
102 protected void bdev_pop_mode(LttngBdevState bdevst
) {
103 bdevst
.popFromBdevStack();
107 * Push a new received function pointer to the user_stack
113 protected void push_function(LttngTraceState traceSt
, Long funcptr
, Long cpu
) {
114 // Get the related process
115 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
118 process
.pushToUserStack(funcptr
);
120 // update the pointer to the current function on the corresponding
122 process
.setCurrent_function(funcptr
);
125 protected void pop_function(LttngTraceState traceSt
, LttngEvent trcEvent
,
127 Long cpu
= trcEvent
.getCpuId();
128 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
129 Long curr_function
= process
.getCurrent_function();
131 if (curr_function
!= null && curr_function
!= funcptr
) {
132 TraceDebug
.debug("Different functions: " + funcptr
+ " current: "
133 + curr_function
+ " time stamp: "
134 + trcEvent
.getTimestamp().toString());
136 // g_info("Different functions (%lu.%09lu): ignore it\n",
137 // tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
138 // g_info("process state has %" PRIu64 " when pop_function is %"
141 // process->current_function, funcptr);
142 // g_info("{ %u, %u, %s, %s, %s }\n",
145 // g_quark_to_string(process->name),
146 // g_quark_to_string(process->brand),
147 // g_quark_to_string(process->state->s));
151 process
.popFromUserStack();
152 process
.setCurrent_function(process
.peekFromUserStack());
155 // ========================================================================
157 // =======================================================================
158 // Adaption from MKDEV macro
159 protected Long
mkdev(Long major
, Long minor
) {
161 if (major
!= null && minor
!= null) {
162 result
= (major
<< 20) | minor
;
168 * FIXME : this function should be called when we receive an event telling
169 * that release_task has been called in the kernel. In happens generally
170 * when the parent waits for its child termination, but may also happen in
171 * special cases in the child's exit : when the parent ignores its children
172 * SIGCCHLD or has the flag SA_NOCLDWAIT. It can also happen when the child
173 * is part of a killed thread group, but isn't the leader.
175 protected boolean exit_process(LttngTraceState ts
, LttngProcessState process
) {
177 * Wait for both schedule with exit dead and process free to happen.
178 * They can happen in any order.
180 process
.incrementFree_events();
181 if (process
.getFree_events() < 2) {
185 process
.clearExecutionStack();
186 process
.clearUserStack();
187 ts
.removeProcessState(process
);
200 protected LttngProcessState
create_process(LttngTraceState traceSt
,
201 Long cpu
, Long pid
, Long tgid
, final TmfTimestamp timestamp
) {
202 LttngProcessState process
= create_process(traceSt
, cpu
, pid
, tgid
,
203 ProcessStatus
.LTTV_STATE_UNNAMED
.getInName(), timestamp
);
216 protected LttngProcessState
create_process(LttngTraceState traceSt
,
217 Long cpu
, Long pid
, Long tgid
, String name
,
218 final TmfTimestamp timestamp
) {
219 LttngProcessState process
;
220 process
= new LttngProcessState(cpu
, pid
, tgid
, name
, timestamp
.getValue(), traceSt
.getTraceId());
221 traceSt
.addProcessState(process
);
230 * , Used when a new process is needed
233 protected LttngProcessState
lttv_state_find_process_or_create(
234 LttngTraceState ts
, Long cpu
, Long pid
, final TmfTimestamp timestamp
) {
236 LttngProcessState process
= lttv_state_find_process(ts
, cpu
, pid
);
237 /* Put ltt_time_zero creation time for non existing processes */
238 if (process
== null) {
239 process
= create_process(ts
, cpu
, pid
, 0L, timestamp
);
240 // leave only one entry in the execution stack
241 process
.popFromExecutionStack();
242 LttngExecutionState es
= process
.getState();
243 es
.setExec_mode(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
);
244 es
.setProc_status(ProcessStatus
.LTTV_STATE_UNNAMED
);