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 // if (process != null)
52 exe_state
.setProc_status(process
.getState().getProc_status());
53 process
.pushToExecutionStack(exe_state
);
56 protected void pop_state(Long cpu
, StateStrings
.ExecutionMode execMode
,
57 LttngTraceState traceSt
, TmfTimestamp eventTime
) {
59 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
61 if (!process
.getState().getExec_mode().equals(execMode
)) {
62 // Different execution mode
63 TraceDebug
.debug("Different Execution Mode type \n\tTime:" //$NON-NLS-1$
64 + eventTime
.toString() + "\n\tprocess state has: \n\t" //$NON-NLS-1$
65 + process
.getState().getExec_mode().toString()
66 + "\n\twhen pop_int is:\n\t" + execMode
.toString()); //$NON-NLS-1$
70 //The process state is updated within the pop method
71 process
.popFromExecutionStack();
72 process
.getState().setChange_Time(eventTime
.getValue());
75 protected void irq_push_mode(LttngIRQState irqst
, IRQMode state
) {
76 irqst
.pushToIrqStack(state
);
79 protected void irq_set_base_mode(LttngIRQState irqst
, IRQMode state
) {
80 irqst
.clearAndSetBaseToIrqStack(state
);
83 protected void irq_pop_mode(LttngIRQState irqst
) {
84 irqst
.popFromIrqStack();
87 protected void cpu_push_mode(LTTngCPUState cpust
, StateStrings
.CpuMode state
) {
88 // The initialization (init) creates a LttngCPUState instance per
89 // available cpu in the system
90 cpust
.pushToCpuStack(state
);
93 protected void cpu_pop_mode(LTTngCPUState cpust
) {
94 cpust
.popFromCpuStack();
97 /* clears the stack and sets the state passed as argument */
98 protected void cpu_set_base_mode(LTTngCPUState cpust
,
99 StateStrings
.CpuMode state
) {
100 cpust
.clearAndSetBaseToCpuStack(state
);
103 protected void bdev_pop_mode(LttngBdevState bdevst
) {
104 bdevst
.popFromBdevStack();
108 * Push a new received function pointer to the user_stack
114 protected void push_function(LttngTraceState traceSt
, Long funcptr
, Long cpu
) {
115 // Get the related process
116 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
119 process
.pushToUserStack(funcptr
);
121 // update the pointer to the current function on the corresponding
123 process
.setCurrent_function(funcptr
);
126 protected void pop_function(LttngTraceState traceSt
, LttngEvent trcEvent
,
128 Long cpu
= trcEvent
.getCpuId();
129 LttngProcessState process
= traceSt
.getRunning_process().get(cpu
);
130 Long curr_function
= process
.getCurrent_function();
132 if (curr_function
!= null && !curr_function
.equals(funcptr
)) {
133 TraceDebug
.debug("Different functions: " + funcptr
+ " current: " //$NON-NLS-1$ //$NON-NLS-2$
134 + curr_function
+ " time stamp: " //$NON-NLS-1$
135 + trcEvent
.getTimestamp().toString());
137 // g_info("Different functions (%lu.%09lu): ignore it\n",
138 // tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
139 // g_info("process state has %" PRIu64 " when pop_function is %"
142 // process->current_function, funcptr);
143 // g_info("{ %u, %u, %s, %s, %s }\n",
146 // g_quark_to_string(process->name),
147 // g_quark_to_string(process->brand),
148 // g_quark_to_string(process->state->s));
152 process
.popFromUserStack();
153 process
.setCurrent_function(process
.peekFromUserStack());
156 // ========================================================================
158 // =======================================================================
159 // Adaption from MKDEV macro
160 protected Long
mkdev(Long major
, Long minor
) {
162 if (major
!= null && minor
!= null) {
163 result
= (major
<< 20) | minor
;
169 * FIXME : this function should be called when we receive an event telling
170 * that release_task has been called in the kernel. In happens generally
171 * when the parent waits for its child termination, but may also happen in
172 * special cases in the child's exit : when the parent ignores its children
173 * SIGCCHLD or has the flag SA_NOCLDWAIT. It can also happen when the child
174 * is part of a killed thread group, but isn't the leader.
176 protected boolean exit_process(LttngTraceState ts
, LttngProcessState process
) {
178 * Wait for both schedule with exit dead and process free to happen.
179 * They can happen in any order.
181 process
.incrementFree_events();
182 if (process
.getFree_events() < 2) {
186 process
.clearExecutionStack();
187 process
.clearUserStack();
188 ts
.removeProcessState(process
);
201 protected LttngProcessState
create_process(LttngTraceState traceSt
,
202 Long cpu
, Long pid
, Long tgid
, final TmfTimestamp timestamp
) {
203 LttngProcessState process
= create_process(traceSt
, cpu
, pid
, tgid
,
204 ProcessStatus
.LTTV_STATE_UNNAMED
.getInName(), timestamp
);
217 protected LttngProcessState
create_process(LttngTraceState traceSt
,
218 Long cpu
, Long pid
, Long tgid
, String name
,
219 final TmfTimestamp timestamp
) {
220 LttngProcessState process
;
221 process
= new LttngProcessState(cpu
, pid
, tgid
, name
, timestamp
.getValue(), traceSt
.getTraceId());
222 traceSt
.addProcessState(process
);
231 * , Used when a new process is needed
234 protected LttngProcessState
lttv_state_find_process_or_create(
235 LttngTraceState ts
, Long cpu
, Long pid
, final TmfTimestamp timestamp
) {
237 LttngProcessState process
= lttv_state_find_process(ts
, cpu
, pid
);
238 /* Put ltt_time_zero creation time for non existing processes */
239 if (process
== null) {
240 process
= create_process(ts
, cpu
, pid
, 0L, timestamp
);
241 // leave only one entry in the execution stack
242 process
.popFromExecutionStack();
243 LttngExecutionState es
= process
.getState();
244 es
.setExec_mode(ExecutionMode
.LTTV_STATE_MODE_UNKNOWN
);
245 es
.setProc_status(ProcessStatus
.LTTV_STATE_UNNAMED
);