1 package org
.eclipse
.linuxtools
.lttng
.tests
.state
.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 public abstract class AbsStateUpdate
implements ILttngEventProcessor
{
14 // ========================================================================
16 // =======================================================================
17 protected static LttngExecutionState exState
= null;
18 protected static Long pid
= null;
20 // ========================================================================
21 // push and pop from stack
22 // =======================================================================
24 // protected static final Long ANY_CPU = 0L;
27 // protected void push_state(Long cpu, StateStrings.ExecutionMode execMode,
28 // String submode, TmfTimestamp eventTime, LttngTraceState traceSt) {
30 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
31 // LttngExecutionState exe_state = new LttngExecutionState();
32 // exe_state.setExec_mode(execMode);
33 // exe_state.setExec_submode(submode);
34 // exe_state.setEntry_Time(eventTime);
35 // exe_state.setChage_Time(eventTime);
36 // exe_state.setCum_cpu_time(0L);
37 // exe_state.setProc_status(process.getState().getProc_status());
38 // process.setState(exe_state);
40 // Stack<LttngExecutionState> exe_state_stack = process
41 // .getExecution_stack();
42 // exe_state_stack.push(exe_state);
45 // protected void pop_state(Long cpu, StateStrings.ExecutionMode execMode,
46 // LttngTraceState traceSt, TmfTimestamp eventTime) {
48 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
50 // if (!process.getState().getExec_mode().equals(execMode)) {
51 // // Different execution mode
52 // TraceDebug.debug("Different Execution Mode type \n\tTime:"
53 // + eventTime.toString() + "\n\tprocess state has: \n\t"
54 // + process.getState().getExec_mode().toString()
55 // + "\n\twhen pop_int is:\n\t" + execMode.toString());
59 // Stack<LttngExecutionState> exe_state_stack = process
60 // .getExecution_stack();
62 // if (exe_state_stack.size() <= 1) {
64 // .debug("Removing last item from execution stack is not allowed");
67 // exe_state_stack.pop();
68 // process.setState(exe_state_stack.peek());
69 // process.getState().setChage_Time(eventTime);
72 // protected void irq_push_mode(LttngIRQState irqst, IRQMode state) {
73 // irqst.getMode_stack().push(state);
76 // protected void irq_set_base_mode(LttngIRQState irqst, IRQMode state) {
77 // Stack<IRQMode> irqModeStack = irqst.getMode_stack();
78 // irqModeStack.clear();
79 // irqModeStack.push(state);
82 // protected void irq_pop_mode(LttngIRQState irqst) {
83 // Stack<IRQMode> irq_stack = irqst.getMode_stack();
84 // if (irq_stack.size() <= 1)
85 // irq_set_base_mode(irqst, IRQMode.LTTV_IRQ_UNKNOWN);
90 // protected void cpu_push_mode(LTTngCPUState cpust, StateStrings.CpuMode state) {
91 // // The initialization (init) creates a LttngCPUState instance per
92 // // available cpu in the system
93 // Stack<CpuMode> cpuStack = cpust.getMode_stack();
94 // cpuStack.push(state);
97 // protected void cpu_pop_mode(LTTngCPUState cpust) {
98 // if (cpust.getMode_stack().size() <= 1)
99 // cpu_set_base_mode(cpust, StateStrings.CpuMode.LTTV_CPU_UNKNOWN);
101 // cpust.getMode_stack().pop();
104 // /* clears the stack and sets the state passed as argument */
105 // protected void cpu_set_base_mode(LTTngCPUState cpust,
106 // StateStrings.CpuMode state) {
107 // Stack<CpuMode> cpuStack = cpust.getMode_stack();
109 // cpuStack.push(state);
112 // protected void bdev_pop_mode(LttngBdevState bdevst) {
113 // Stack<BdevMode> bdevModeStack = bdevst.getMode_stack();
114 // if (bdevModeStack.size() <= 1) {
115 // bdev_set_base_mode(bdevModeStack, BdevMode.LTTV_BDEV_UNKNOWN);
117 // bdevModeStack.pop();
122 // protected void bdev_set_base_mode(Stack<BdevMode> bdevModeStack,
124 // bdevModeStack.clear();
125 // bdevModeStack.push(state);
129 // * Push a new received function pointer to the user_stack
135 // protected void push_function(LttngTraceState traceSt, Long funcptr, Long cpu) {
136 // // Get the related process
137 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
139 // // get the user_stack
140 // Stack<Long> user_stack = process.getUser_stack();
143 // user_stack.push(funcptr);
145 // // update the pointer to the current function on the corresponding
147 // process.setCurrent_function(funcptr);
150 // protected void pop_function(LttngTraceState traceSt, LttngEvent trcEvent,
152 // Long cpu = trcEvent.getCpuId();
153 // // LttvTraceState *ts = (LttvTraceState*)tfs->parent.t_context;
154 // // LttvProcessState *process = ts->running_process[cpu];
155 // LttngProcessState process = traceSt.getRunning_process().get(cpu);
156 // Long curr_function = process.getCurrent_function();
157 // if (curr_function != null && curr_function != funcptr) {
158 // TraceDebug.debug("Different functions: " + funcptr + " current: "
159 // + curr_function + " time stamp: "
160 // + trcEvent.getTimestamp().toString());
162 // // g_info("Different functions (%lu.%09lu): ignore it\n",
163 // // tfs->parent.timestamp.tv_sec, tfs->parent.timestamp.tv_nsec);
164 // // g_info("process state has %" PRIu64 " when pop_function is %"
167 // // process->current_function, funcptr);
168 // // g_info("{ %u, %u, %s, %s, %s }\n",
171 // // g_quark_to_string(process->name),
172 // // g_quark_to_string(process->brand),
173 // // g_quark_to_string(process->state->s));
177 // Stack<Long> user_stack = process.getUser_stack();
178 // if (user_stack.size() == 0) {
180 // .debug("Trying to pop last function in stack. Ignored. Time Stamp: "
181 // + trcEvent.getTimestamp());
185 // process.setCurrent_function(user_stack.peek());
188 // // ========================================================================
189 // // General methods
190 // // =======================================================================
192 // * protected method used when only one Field is expected with Type "Long" if
193 // * the number of fields is greater, the first field is returned and a
194 // * tracing message is sent Null is returned if the value could not be
199 // * @param expectedNumFields
202 // protected Long getDField(LttngEvent trcEvent, LttngTraceState traceSt,
203 // Fields expectedField) {
204 // Long fieldVal = null;
205 // TmfEventField[] fields = trcEvent.getContent().getFields();
206 // String[] fieldLabels = trcEvent.getContent().getFormat().getLabels();
208 // // Only one field expected
209 // if (fields.length != 1 || fieldLabels.length != 1) {
210 // StringBuilder sb = new StringBuilder(
211 // "Unexpected number of fields received: " + fields.length
212 // + " for Event: " + trcEvent.getMarkerName() + "\n\t\tFields: ");
214 // for (TmfEventField field : fields) {
215 // sb.append(((LttngEventField)field).getName() + " ");
218 // TraceDebug.debug(sb.toString());
219 // if (fields.length == 0) {
224 // LttngEventField field = (LttngEventField) fields[0];
225 // String fieldname = field.getName();
226 // String expectedFieldName = expectedField.getInName();
227 // if (fieldname.equals(expectedFieldName)) {
228 // Object fieldObj = field.getValue();
229 // if (fieldObj instanceof Long) {
230 // // Expected value found
231 // fieldVal = (Long) field.getValue();
233 // if (TraceDebug.isDEBUG()) {
235 // .debug("Unexpected field Type. Expected: Long, Received: "
236 // + fieldObj.getClass().getSimpleName());
241 // TraceDebug.debug("Unexpected field received: " + fieldname
242 // + " Expected: " + expectedFieldName);
250 * protected method used when a Field is requested among several available
251 * fields and the expected type is Long
255 * @param expectedNumFields
258 protected Long
getAFieldLong(LttngEvent trcEvent
, LttngTraceState traceSt
,
259 Fields expectedField
) {
260 Long fieldVal
= null;
261 TmfEventField
[] fields
= trcEvent
.getContent().getFields();
263 // At least one field expected
264 if (fields
.length
== 0) {
265 TraceDebug
.debug("Unexpected number of fields received: "
270 LttngEventField field
;
272 String expectedFieldName
= expectedField
.getInName();
273 for (int i
= 0; i
< fields
.length
; i
++) {
274 field
= (LttngEventField
) fields
[i
];
275 fieldname
= field
.getId();
276 if (fieldname
.equals(expectedFieldName
)) {
277 Object fieldObj
= field
.getValue();
278 if (fieldObj
instanceof Long
) {
279 // Expected value found
280 fieldVal
= (Long
) field
.getValue();
281 // if (expectedField == Fields.LTT_FIELD_TYPE) {
282 // TraceDebug.debug("Field Type value is: " + fieldVal);
286 if (TraceDebug
.isDEBUG()) {
288 .debug("Unexpected field Type. Expected: Long, Received: "
289 + fieldObj
.getClass().getSimpleName());
296 if (fieldVal
== null) {
297 if (TraceDebug
.isDEBUG()) {
298 sendNoFieldFoundMsg(fields
, expectedFieldName
);
305 * protected method used when a Field is requested among several available
306 * fields and the expected type is String
310 * @param expectedNumFields
313 protected String
getAFieldString(LttngEvent trcEvent
,
314 LttngTraceState traceSt
, Fields expectedField
) {
315 String fieldVal
= null;
316 TmfEventField
[] fields
= trcEvent
.getContent().getFields();
318 // Only one field expected
319 if (fields
.length
== 0) {
320 TraceDebug
.debug("Unexpected number of fields received: "
325 LttngEventField field
;
327 String expectedFieldName
= expectedField
.getInName();
328 for (int i
= 0; i
< fields
.length
; i
++) {
329 field
= (LttngEventField
) fields
[i
];
330 fieldname
= field
.getId();
331 if (fieldname
.equals(expectedFieldName
)) {
332 Object fieldObj
= field
.getValue();
333 if (fieldObj
instanceof String
) {
334 // Expected value found
335 fieldVal
= (String
) field
.getValue();
338 if (TraceDebug
.isDEBUG()) {
340 .debug("Unexpected field Type. Expected: String, Received: "
341 + fieldObj
.getClass().getSimpleName());
348 if (fieldVal
== null) {
349 if (TraceDebug
.isDEBUG()) {
350 sendNoFieldFoundMsg(fields
, expectedFieldName
);
356 protected void sendNoFieldFoundMsg(TmfEventField
[] fields
,
357 String expectedFieldName
) {
358 LttngEventField field
;
359 StringBuilder sb
= new StringBuilder("Field not found, requested: "
360 + expectedFieldName
);
361 sb
.append(" number of fields: " + fields
.length
+ "Fields: ");
362 for (int i
= 0; i
< fields
.length
; i
++) {
363 field
= (LttngEventField
) fields
[i
];
364 sb
.append(field
.getId() + " ");
367 TraceDebug
.debug(sb
.toString(), 5);
370 // // Adaption from MKDEV macro
371 // protected Long mkdev(Long major, Long minor) {
372 // Long result = null;
373 // if (major != null && minor != null) {
374 // result = (major << 20) | minor;
380 // * FIXME : this function should be called when we receive an event telling
381 // * that release_task has been called in the kernel. In happens generally
382 // * when the parent waits for its child terminaison, but may also happen in
383 // * special cases in the child's exit : when the parent ignores its children
384 // * SIGCCHLD or has the flag SA_NOCLDWAIT. It can also happen when the child
385 // * is part of a killed thread group, but isn't the leader.
387 // protected boolean exit_process(LttngTraceState ts, LttngProcessState process) {
389 // * Wait for both schedule with exit dead and process free to happen.
390 // * They can happen in any order.
392 // process.incrementFree_events();
393 // if (process.getFree_events() < 2) {
397 // process.getExecution_stack().clear();
398 // process.getUser_stack().clear();
399 // ts.getProcesses().remove(process);
404 // // LttvProcessState *
405 // // lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent,
406 // // guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp)
408 // // LttvProcessState *process = g_new(LttvProcessState, 1);
410 // // LttvExecutionState *es;
412 // // char buffer[128];
414 // // process->pid = pid;
415 // // process->tgid = tgid;
416 // // process->cpu = cpu;
417 // // process->name = name;
418 // // process->brand = LTTV_STATE_UNBRANDED;
419 // // //process->last_cpu = tfs->cpu_name;
420 // // //process->last_cpu_index =
421 // // ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
422 // // process->type = LTTV_STATE_USER_THREAD;
423 // // process->usertrace = ltt_state_usertrace_find(tcs, pid, timestamp);
424 // // process->current_function = 0; //function 0x0 by default.
426 // // g_info("Process %u, core %p", process->pid, process);
427 // // g_hash_table_insert(tcs->processes, process, process);
430 // // process->ppid = parent->pid;
431 // // process->creation_time = *timestamp;
434 // // /* No parent. This process exists but we are missing all information
436 // // its creation. The birth time is set to zero but we remember the time of
440 // // process->ppid = 0;
441 // // process->creation_time = ltt_time_zero;
444 // // process->insertion_time = *timestamp;
445 // // sprintf(buffer,"%d-%lu.%lu",pid, process->creation_time.tv_sec,
446 // // process->creation_time.tv_nsec);
447 // // process->pid_time = g_quark_from_string(buffer);
448 // // process->cpu = cpu;
449 // // process->free_events = 0;
450 // // //process->last_cpu = tfs->cpu_name;
451 // // //process->last_cpu_index =
452 // // ltt_tracefile_num(((LttvTracefileContext*)tfs)->tf);
453 // // process->execution_stack = g_array_sized_new(FALSE, FALSE,
454 // // sizeof(LttvExecutionState), PREALLOCATED_EXECUTION_STACK);
455 // // process->execution_stack = g_array_set_size(process->execution_stack, 2);
456 // // es = process->state = &g_array_index(process->execution_stack,
457 // // LttvExecutionState, 0);
458 // // es->t = LTTV_STATE_USER_MODE;
459 // // es->n = LTTV_STATE_SUBMODE_NONE;
460 // // es->entry = *timestamp;
461 // // //g_assert(timestamp->tv_sec != 0);
462 // // es->change = *timestamp;
463 // // es->cum_cpu_time = ltt_time_zero;
464 // // es->s = LTTV_STATE_RUN;
466 // // es = process->state = &g_array_index(process->execution_stack,
467 // // LttvExecutionState, 1);
468 // // es->t = LTTV_STATE_SYSCALL;
469 // // es->n = LTTV_STATE_SUBMODE_NONE;
470 // // es->entry = *timestamp;
471 // // //g_assert(timestamp->tv_sec != 0);
472 // // es->change = *timestamp;
473 // // es->cum_cpu_time = ltt_time_zero;
474 // // es->s = LTTV_STATE_WAIT_FORK;
476 // // /* Allocate an empty function call stack. If it's empty, use 0x0. */
477 // // process->user_stack = g_array_sized_new(FALSE, FALSE,
478 // // sizeof(guint64), 0);
480 // // return process;
484 // * Find the process matching the given pid and cpu
486 // * If cpu is 0, the cpu value is not matched and the selection is based on
494 // protected LttngProcessState lttv_state_find_process(LttngTraceState ts,
495 // Long cpu, Long pid) {
496 // // Define the return value
497 // LttngProcessState process = null;
499 // // Obtain the list of available processes
500 // List<LttngProcessState> processList = ts.getProcesses();
502 // // find the process matching pid and cpu,
503 // // TODO: This may need to be improved since the pid may be re-used and
504 // // the creation time may need to be considered
505 // for (LttngProcessState dprocess : processList) {
506 // if (dprocess.getPid() == pid) {
507 // if (dprocess.getCpu() == cpu || cpu == 0) {
520 // * @param timestamp
521 // * , Used when a new process is needed
524 // protected LttngProcessState lttv_state_find_process_or_create(
525 // LttngTraceState ts, Long cpu, Long pid, final TmfTimestamp timestamp) {
527 // LttngProcessState process = lttv_state_find_process(ts, cpu, pid);
528 // /* Put ltt_time_zero creation time for unexisting processes */
529 // if (process == null) {
530 // process = create_process(ts, cpu, pid, 0L, timestamp);
540 // * @param timestamp
543 // protected LttngProcessState create_process(LttngTraceState traceSt,
544 // Long cpu, Long pid, Long tgid, final TmfTimestamp timestamp) {
545 // LttngProcessState process = create_process(traceSt, cpu, pid, tgid,
546 // ProcessStatus.LTTV_STATE_UNNAMED.getInName(), timestamp);
556 // * @param timestamp
559 // protected LttngProcessState create_process(LttngTraceState traceSt,
560 // Long cpu, Long pid, Long tgid, String name,
561 // final TmfTimestamp timestamp) {
562 // LttngProcessState process;
563 // process = new LttngProcessState(cpu, pid, tgid, name, timestamp);
564 // traceSt.getProcesses().add(process);