1 package org
.eclipse
.linuxtools
.lttng
.tests
.state
.tests
.handlers
;
3 import org
.eclipse
.linuxtools
.lttng
.TraceDebug
;
4 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
5 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEventField
;
6 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
.Fields
;
7 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ILttngEventProcessor
;
8 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngExecutionState
;
9 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
10 import org
.eclipse
.linuxtools
.tmf
.event
.TmfEventField
;
12 @SuppressWarnings("nls")
13 public abstract class AbsStateUpdate
implements ILttngEventProcessor
{
15 // ========================================================================
17 // =======================================================================
18 protected static LttngExecutionState exState
= null;
19 protected static Long pid
= null;
21 // ========================================================================
22 // push and pop from stack
23 // =======================================================================
25 // protected static final Long ANY_CPU = 0L;
28 // protected void push_state(Long cpu, StateStrings.ExecutionMode execMode,
29 // String submode, TmfTimestamp eventTime, LttngTraceState traceSt) {
31 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
32 // LttngExecutionState exe_state = new LttngExecutionState();
33 // exe_state.setExec_mode(execMode);
34 // exe_state.setExec_submode(submode);
35 // exe_state.setEntry_Time(eventTime);
36 // exe_state.setChage_Time(eventTime);
37 // exe_state.setCum_cpu_time(0L);
38 // exe_state.setProc_status(process.getState().getProc_status());
39 // process.setState(exe_state);
41 // Stack<LttngExecutionState> exe_state_stack = process
42 // .getExecution_stack();
43 // exe_state_stack.push(exe_state);
46 // protected void pop_state(Long cpu, StateStrings.ExecutionMode execMode,
47 // LttngTraceState traceSt, TmfTimestamp eventTime) {
49 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
51 // if (!process.getState().getExec_mode().equals(execMode)) {
52 // // Different execution mode
53 // TraceDebug.debug("Different Execution Mode type \n\tTime:"
54 // + eventTime.toString() + "\n\tprocess state has: \n\t"
55 // + process.getState().getExec_mode().toString()
56 // + "\n\twhen pop_int is:\n\t" + execMode.toString());
60 // Stack<LttngExecutionState> exe_state_stack = process
61 // .getExecution_stack();
63 // if (exe_state_stack.size() <= 1) {
65 // .debug("Removing last item from execution stack is not allowed");
68 // exe_state_stack.pop();
69 // process.setState(exe_state_stack.peek());
70 // process.getState().setChage_Time(eventTime);
73 // protected void irq_push_mode(LttngIRQState irqst, IRQMode state) {
74 // irqst.getMode_stack().push(state);
77 // protected void irq_set_base_mode(LttngIRQState irqst, IRQMode state) {
78 // Stack<IRQMode> irqModeStack = irqst.getMode_stack();
79 // irqModeStack.clear();
80 // irqModeStack.push(state);
83 // protected void irq_pop_mode(LttngIRQState irqst) {
84 // Stack<IRQMode> irq_stack = irqst.getMode_stack();
85 // if (irq_stack.size() <= 1)
86 // irq_set_base_mode(irqst, IRQMode.LTTV_IRQ_UNKNOWN);
91 // protected void cpu_push_mode(LTTngCPUState cpust, StateStrings.CpuMode state) {
92 // // The initialization (init) creates a LttngCPUState instance per
93 // // available cpu in the system
94 // Stack<CpuMode> cpuStack = cpust.getMode_stack();
95 // cpuStack.push(state);
98 // protected void cpu_pop_mode(LTTngCPUState cpust) {
99 // if (cpust.getMode_stack().size() <= 1)
100 // cpu_set_base_mode(cpust, StateStrings.CpuMode.LTTV_CPU_UNKNOWN);
102 // cpust.getMode_stack().pop();
105 // /* clears the stack and sets the state passed as argument */
106 // protected void cpu_set_base_mode(LTTngCPUState cpust,
107 // StateStrings.CpuMode state) {
108 // Stack<CpuMode> cpuStack = cpust.getMode_stack();
110 // cpuStack.push(state);
113 // protected void bdev_pop_mode(LttngBdevState bdevst) {
114 // Stack<BdevMode> bdevModeStack = bdevst.getMode_stack();
115 // if (bdevModeStack.size() <= 1) {
116 // bdev_set_base_mode(bdevModeStack, BdevMode.LTTV_BDEV_UNKNOWN);
118 // bdevModeStack.pop();
123 // protected void bdev_set_base_mode(Stack<BdevMode> bdevModeStack,
125 // bdevModeStack.clear();
126 // bdevModeStack.push(state);
130 // * Push a new received function pointer to the user_stack
136 // protected void push_function(LttngTraceState traceSt, Long funcptr, Long cpu) {
137 // // Get the related process
138 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
140 // // get the user_stack
141 // Stack<Long> user_stack = process.getUser_stack();
144 // user_stack.push(funcptr);
146 // // update the pointer to the current function on the corresponding
148 // process.setCurrent_function(funcptr);
151 // protected void pop_function(LttngTraceState traceSt, LttngEvent trcEvent,
153 // Long cpu = trcEvent.getCpuId();
154 // // LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
155 // // LttvProcessState *process = ts->running_process[cpu];
156 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
157 // Long curr_function = process.getCurrent_function();
158 // if (curr_function != null && curr_function != funcptr) {
159 // TraceDebug.debug("Different functions: " + funcptr + " current: "
160 // + curr_function + " time stamp: "
161 // + trcEvent.getTimestamp().toString());
163 // // g_info("Different functions (%lu.%09lu): ignore it\n",
164 // // tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
165 // // g_info("process state has %" PRIu64 " when pop_function is %"
168 // // process->current_function, funcptr);
169 // // g_info("{ %u, %u, %s, %s, %s }\n",
172 // // g_quark_to_string(process->name),
173 // // g_quark_to_string(process->brand),
174 // // g_quark_to_string(process->state->s));
178 // Stack<Long> user_stack = process.getUser_stack();
179 // if (user_stack.size() == 0) {
181 // .debug("Trying to pop last function in stack. Ignored. Time Stamp: "
182 // + trcEvent.getTimestamp());
186 // process.setCurrent_function(user_stack.peek());
189 // // ========================================================================
190 // // General methods
191 // // =======================================================================
193 // * protected method used when only one Field is expected with Type "Long" if
194 // * the number of fields is greater, the first field is returned and a
195 // * tracing message is sent Null is returned if the value could not be
200 // * @param expectedNumFields
203 // protected Long getDField(LttngEvent trcEvent, LttngTraceState traceSt,
204 // Fields expectedField) {
205 // Long fieldVal = null;
206 // TmfEventField[] fields = trcEvent.getContent().getFields();
207 // String[] fieldLabels = trcEvent.getContent().getFormat().getLabels();
209 // // Only one field expected
210 // if (fields.length != 1 || fieldLabels.length != 1) {
211 // StringBuilder sb = new StringBuilder(
212 // "Unexpected number of fields received: " + fields.length
213 // + " for Event: " + trcEvent.getMarkerName() + "\n\t\tFields: ");
215 // for (TmfEventField field : fields) {
216 // sb.append(((LttngEventField)field).getName() + " ");
219 // TraceDebug.debug(sb.toString());
220 // if (fields.length == 0) {
225 // LttngEventField field = (LttngEventField) fields[0];
226 // String fieldname = field.getName();
227 // String expectedFieldName = expectedField.getInName();
228 // if (fieldname.equals(expectedFieldName)) {
229 // Object fieldObj = field.getValue();
230 // if (fieldObj instanceof Long) {
231 // // Expected value found
232 // fieldVal = (Long) field.getValue();
234 // if (TraceDebug.isDEBUG()) {
236 // .debug("Unexpected field Type. Expected: Long, Received: "
237 // + fieldObj.getClass().getSimpleName());
242 // TraceDebug.debug("Unexpected field received: " + fieldname
243 // + " Expected: " + expectedFieldName);
251 * protected method used when a Field is requested among several available
252 * fields and the expected type is Long
256 * @param expectedNumFields
259 protected Long
getAFieldLong(LttngEvent trcEvent
, LttngTraceState traceSt
,
260 Fields expectedField
) {
261 Long fieldVal
= null;
262 TmfEventField
[] fields
= trcEvent
.getContent().getFields();
264 // At least one field expected
265 if (fields
.length
== 0) {
266 TraceDebug
.debug("Unexpected number of fields received: "
271 LttngEventField field
;
273 String expectedFieldName
= expectedField
.getInName();
274 for (int i
= 0; i
< fields
.length
; i
++) {
275 field
= (LttngEventField
) fields
[i
];
276 fieldname
= field
.getId();
277 if (fieldname
.equals(expectedFieldName
)) {
278 Object fieldObj
= field
.getValue();
279 if (fieldObj
instanceof Long
) {
280 // Expected value found
281 fieldVal
= (Long
) field
.getValue();
282 // if (expectedField == Fields.LTT_FIELD_TYPE) {
283 // TraceDebug.debug("Field Type value is: " + fieldVal);
287 if (TraceDebug
.isDEBUG()) {
289 .debug("Unexpected field Type. Expected: Long, Received: "
290 + fieldObj
.getClass().getSimpleName());
297 if (fieldVal
== null) {
298 if (TraceDebug
.isDEBUG()) {
299 sendNoFieldFoundMsg(fields
, expectedFieldName
);
306 * protected method used when a Field is requested among several available
307 * fields and the expected type is String
311 * @param expectedNumFields
314 protected String
getAFieldString(LttngEvent trcEvent
,
315 LttngTraceState traceSt
, Fields expectedField
) {
316 String fieldVal
= null;
317 TmfEventField
[] fields
= trcEvent
.getContent().getFields();
319 // Only one field expected
320 if (fields
.length
== 0) {
321 TraceDebug
.debug("Unexpected number of fields received: "
326 LttngEventField field
;
328 String expectedFieldName
= expectedField
.getInName();
329 for (int i
= 0; i
< fields
.length
; i
++) {
330 field
= (LttngEventField
) fields
[i
];
331 fieldname
= field
.getId();
332 if (fieldname
.equals(expectedFieldName
)) {
333 Object fieldObj
= field
.getValue();
334 if (fieldObj
instanceof String
) {
335 // Expected value found
336 fieldVal
= (String
) field
.getValue();
339 if (TraceDebug
.isDEBUG()) {
341 .debug("Unexpected field Type. Expected: String, Received: "
342 + fieldObj
.getClass().getSimpleName());
349 if (fieldVal
== null) {
350 if (TraceDebug
.isDEBUG()) {
351 sendNoFieldFoundMsg(fields
, expectedFieldName
);
357 protected void sendNoFieldFoundMsg(TmfEventField
[] fields
,
358 String expectedFieldName
) {
359 LttngEventField field
;
360 StringBuilder sb
= new StringBuilder("Field not found, requested: "
361 + expectedFieldName
);
362 sb
.append(" number of fields: " + fields
.length
+ "Fields: ");
363 for (int i
= 0; i
< fields
.length
; i
++) {
364 field
= (LttngEventField
) fields
[i
];
365 sb
.append(field
.getId() + " ");
368 TraceDebug
.debug(sb
.toString(), 5);
371 // // Adaption from MKDEV macro
372 // protected Long mkdev(Long major, Long minor) {
373 // Long result = null;
374 // if (major != null && minor != null) {
375 // result = (major << 20) | minor;
381 // * FIXME : this function should be called when we receive an event telling
382 // * that release_task has been called in the kernel. In happens generally
383 // * when the parent waits for its child terminaison, but may also happen in
384 // * special cases in the child's exit : when the parent ignores its children
385 // * SIGCCHLD or has the flag SA_NOCLDWAIT. It can also happen when the child
386 // * is part of a killed thread group, but isn't the leader.
388 // protected boolean exit_process(LttngTraceState ts, LttngProcessState process) {
390 // * Wait for both schedule with exit dead and process free to happen.
391 // * They can happen in any order.
393 // process.incrementFree_events();
394 // if (process.getFree_events() < 2) {
398 // process.getExecution_stack().clear();
399 // process.getUser_stack().clear();
400 // ts.getProcesses().remove(process);
405 // // LttvProcessState *
406 // // lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent,
407 // // guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp)
409 // // LttvProcessState *process = g_new(LttvProcessState, 1);
411 // // LttvExecutionState *es;
413 // // char buffer[128];
415 // // process->pid = pid;
416 // // process->tgid = tgid;
417 // // process->cpu = cpu;
418 // // process->name = name;
419 // // process->brand = LTTV_STATE_UNBRANDED;
420 // // //process->last_cpu = tfs->cpu_name;
421 // // //process->last_cpu_index =
422 // // ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
423 // // process->type = LTTV_STATE_USER_THREAD;
424 // // process->usertrace = ltt_state_usertrace_find(tcs, pid, timestamp);
425 // // process->current_function = 0; //function 0x0 by default.
427 // // g_info("Process %u, core %p", process->pid, process);
428 // // g_hash_table_insert(tcs->processes, process, process);
431 // // process->ppid = parent->pid;
432 // // process->creation_time = *timestamp;
435 // // /* No parent. This process exists but we are missing all information
437 // // its creation. The birth time is set to zero but we remember the time of
441 // // process->ppid = 0;
442 // // process->creation_time = ltt_time_zero;
445 // // process->insertion_time = *timestamp;
446 // // sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec,
447 // // process->creation_time.tv_nsec);
448 // // process->pid_time = g_quark_from_string(buffer);
449 // // process->cpu = cpu;
450 // // process->free_events = 0;
451 // // //process->last_cpu = tfs->cpu_name;
452 // // //process->last_cpu_index =
453 // // ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
454 // // process->execution_stack = g_array_sized_new(FALSE, FALSE,
455 // // sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK);
456 // // process->execution_stack = g_array_set_size(process->execution_stack, 2);
457 // // es = process->state = &g_array_index(process->execution_stack,
458 // // LttvExecutionState, 0);
459 // // es->t = LTTV_STATE_USER_MODE;
460 // // es->n = LTTV_STATE_SUBMODE_NONE;
461 // // es->entry = *timestamp;
462 // // //g_assert(timestamp->tv_sec != 0);
463 // // es->change = *timestamp;
464 // // es->cum_cpu_time = ltt_time_zero;
465 // // es->s = LTTV_STATE_RUN;
467 // // es = process->state = &g_array_index(process->execution_stack,
468 // // LttvExecutionState, 1);
469 // // es->t = LTTV_STATE_SYSCALL;
470 // // es->n = LTTV_STATE_SUBMODE_NONE;
471 // // es->entry = *timestamp;
472 // // //g_assert(timestamp->tv_sec != 0);
473 // // es->change = *timestamp;
474 // // es->cum_cpu_time = ltt_time_zero;
475 // // es->s = LTTV_STATE_WAIT_FORK;
477 // // /* Allocate an empty function call stack. If it's empty, use 0x0. */
478 // // process->user_stack = g_array_sized_new(FALSE, FALSE,
479 // // sizeof(guint64), 0);
481 // // return process;
485 // * Find the process matching the given pid and cpu
487 // * If cpu is 0, the cpu value is not matched and the selection is based on
495 // protected LttngProcessState lttv_state_find_process(LttngTraceState ts,
496 // Long cpu, Long pid) {
497 // // Define the return value
498 // LttngProcessState process = null;
500 // // Obtain the list of available processes
501 // List<LttngProcessState> processList = ts.getProcesses();
503 // // find the process matching pid and cpu,
504 // // TODO: This may need to be improved since the pid may be re-used and
505 // // the creation time may need to be considered
506 // for (LttngProcessState dprocess : processList) {
507 // if (dprocess.getPid() == pid) {
508 // if (dprocess.getCpu() == cpu || cpu == 0) {
521 // * @param timestamp
522 // * , Used when a new process is needed
525 // protected LttngProcessState lttv_state_find_process_or_create(
526 // LttngTraceState ts, Long cpu, Long pid, final TmfTimestamp timestamp) {
528 // LttngProcessState process = lttv_state_find_process(ts, cpu, pid);
529 // /* Put ltt_time_zero creation time for unexisting processes */
530 // if (process == null) {
531 // process = create_process(ts, cpu, pid, 0L, timestamp);
541 // * @param timestamp
544 // protected LttngProcessState create_process(LttngTraceState traceSt,
545 // Long cpu, Long pid, Long tgid, final TmfTimestamp timestamp) {
546 // LttngProcessState process = create_process(traceSt, cpu, pid, tgid,
547 // ProcessStatus.LTTV_STATE_UNNAMED.getInName(), timestamp);
557 // * @param timestamp
560 // protected LttngProcessState create_process(LttngTraceState traceSt,
561 // Long cpu, Long pid, Long tgid, String name,
562 // final TmfTimestamp timestamp) {
563 // LttngProcessState process;
564 // process = new LttngProcessState(cpu, pid, tgid, name, timestamp);
565 // traceSt.getProcesses().add(process);