Rename xxx.lttng to xxx.lttng.core
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.tests / src / org / eclipse / linuxtools / lttng / tests / state / handlers / AbsStateUpdate.java
CommitLineData
03c71d1e
ASL
1package org.eclipse.linuxtools.lttng.tests.state.handlers;
2
3import org.eclipse.linuxtools.lttng.TraceDebug;
4import org.eclipse.linuxtools.lttng.event.LttngEvent;
5import org.eclipse.linuxtools.lttng.event.LttngEventField;
6import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
8827c197 7import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor;
03c71d1e
ASL
8import org.eclipse.linuxtools.lttng.state.model.LttngExecutionState;
9import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
10import org.eclipse.linuxtools.tmf.event.TmfEventField;
11
3b38ea61 12@SuppressWarnings("nls")
8827c197 13public abstract class AbsStateUpdate implements ILttngEventProcessor {
03c71d1e
ASL
14
15 // ========================================================================
16 // Data
17 // =======================================================================
18 protected static LttngExecutionState exState = null;
19 protected static Long pid = null;
20
21 // ========================================================================
22 // push and pop from stack
23 // =======================================================================
24
25// protected static final Long ANY_CPU = 0L;
26
27
28// protected void push_state(Long cpu, StateStrings.ExecutionMode execMode,
29// String submode, TmfTimestamp eventTime, LttngTraceState traceSt) {
30//
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);
40//
41// Stack<LttngExecutionState> exe_state_stack = process
42// .getExecution_stack();
43// exe_state_stack.push(exe_state);
44// }
45//
46// protected void pop_state(Long cpu, StateStrings.ExecutionMode execMode,
47// LttngTraceState traceSt, TmfTimestamp eventTime) {
48//
49// LttngProcessState process = traceSt.getRunning_process().get(cpu);
50//
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());
57// return;
58// }
59//
60// Stack<LttngExecutionState> exe_state_stack = process
61// .getExecution_stack();
62//
63// if (exe_state_stack.size() <= 1) {
64// TraceDebug
65// .debug("Removing last item from execution stack is not allowed");
66// }
67//
68// exe_state_stack.pop();
69// process.setState(exe_state_stack.peek());
70// process.getState().setChage_Time(eventTime);
71// }
72//
73// protected void irq_push_mode(LttngIRQState irqst, IRQMode state) {
74// irqst.getMode_stack().push(state);
75// }
76//
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);
81// }
82//
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);
87// else
88// irq_stack.pop();
89// }
90//
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);
96// }
97//
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);
101// else
102// cpust.getMode_stack().pop();
103// }
104//
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();
109// cpuStack.clear();
110// cpuStack.push(state);
111// }
112//
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);
117// } else {
118// bdevModeStack.pop();
119// }
120//
121// }
122//
123// protected void bdev_set_base_mode(Stack<BdevMode> bdevModeStack,
124// BdevMode state) {
125// bdevModeStack.clear();
126// bdevModeStack.push(state);
127// }
128//
129// /**
130// * Push a new received function pointer to the user_stack
131// *
132// * @param traceSt
133// * @param funcptr
134// * @param cpu
135// */
136// protected void push_function(LttngTraceState traceSt, Long funcptr, Long cpu) {
137// // Get the related process
138// LttngProcessState process = traceSt.getRunning_process().get(cpu);
139//
140// // get the user_stack
141// Stack<Long> user_stack = process.getUser_stack();
142//
143// // update stack
144// user_stack.push(funcptr);
145//
146// // update the pointer to the current function on the corresponding
147// // process
148// process.setCurrent_function(funcptr);
149// }
150//
151// protected void pop_function(LttngTraceState traceSt, LttngEvent trcEvent,
152// Long funcptr) {
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());
162//
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 %"
166// // PRIu64
167// // "\n",
168// // process->current_function, funcptr);
169// // g_info("{ %u, %u, %s, %s, %s }\n",
170// // process->pid,
171// // process->ppid,
172// // g_quark_to_string(process->name),
173// // g_quark_to_string(process->brand),
174// // g_quark_to_string(process->state->s));
175// return;
176// }
177//
178// Stack<Long> user_stack = process.getUser_stack();
179// if (user_stack.size() == 0) {
180// TraceDebug
181// .debug("Trying to pop last function in stack. Ignored. Time Stamp: "
182// + trcEvent.getTimestamp());
183// return;
184// }
185// user_stack.pop();
186// process.setCurrent_function(user_stack.peek());
187// }
188//
189// // ========================================================================
190// // General methods
191// // =======================================================================
192// /**
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
196// * extracted.
197// *
198// * @param trcEvent
199// * @param traceSt
200// * @param expectedNumFields
201// * @return
202// */
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();
208//
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: ");
214//
215// for (TmfEventField field : fields) {
216// sb.append(((LttngEventField)field).getName() + " ");
217// }
218//
219// TraceDebug.debug(sb.toString());
220// if (fields.length == 0) {
221// return null;
222// }
223// }
224//
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();
233// } else {
234// if (TraceDebug.isDEBUG()) {
235// TraceDebug
236// .debug("Unexpected field Type. Expected: Long, Received: "
237// + fieldObj.getClass().getSimpleName());
238// }
239// return null;
240// }
241// } else {
242// TraceDebug.debug("Unexpected field received: " + fieldname
243// + " Expected: " + expectedFieldName);
244// return null;
245// }
246//
247// return fieldVal;
248// }
249//
250 /**
251 * protected method used when a Field is requested among several available
252 * fields and the expected type is Long
253 *
254 * @param trcEvent
255 * @param traceSt
256 * @param expectedNumFields
257 * @return
258 */
259 protected Long getAFieldLong(LttngEvent trcEvent, LttngTraceState traceSt,
260 Fields expectedField) {
261 Long fieldVal = null;
262 TmfEventField[] fields = trcEvent.getContent().getFields();
263
264 // At least one field expected
265 if (fields.length == 0) {
266 TraceDebug.debug("Unexpected number of fields received: "
267 + fields.length);
268 return null;
269 }
270
271 LttngEventField field;
272 String fieldname;
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);
284 // }
285 break;
286 } else {
287 if (TraceDebug.isDEBUG()) {
288 TraceDebug
289 .debug("Unexpected field Type. Expected: Long, Received: "
290 + fieldObj.getClass().getSimpleName());
291 }
292 return null;
293 }
294 }
295 }
296
297 if (fieldVal == null) {
298 if (TraceDebug.isDEBUG()) {
299 sendNoFieldFoundMsg(fields, expectedFieldName);
300 }
301 }
302 return fieldVal;
303 }
304
305 /**
306 * protected method used when a Field is requested among several available
307 * fields and the expected type is String
308 *
309 * @param trcEvent
310 * @param traceSt
311 * @param expectedNumFields
312 * @return
313 */
314 protected String getAFieldString(LttngEvent trcEvent,
315 LttngTraceState traceSt, Fields expectedField) {
316 String fieldVal = null;
317 TmfEventField[] fields = trcEvent.getContent().getFields();
318
319 // Only one field expected
320 if (fields.length == 0) {
321 TraceDebug.debug("Unexpected number of fields received: "
322 + fields.length);
323 return null;
324 }
325
326 LttngEventField field;
327 String fieldname;
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();
337 break;
338 } else {
339 if (TraceDebug.isDEBUG()) {
340 TraceDebug
341 .debug("Unexpected field Type. Expected: String, Received: "
342 + fieldObj.getClass().getSimpleName());
343 }
344 return null;
345 }
346 }
347 }
348
349 if (fieldVal == null) {
350 if (TraceDebug.isDEBUG()) {
351 sendNoFieldFoundMsg(fields, expectedFieldName);
352 }
353 }
354 return fieldVal;
355 }
356
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() + " ");
366 }
367
368 TraceDebug.debug(sb.toString(), 5);
369 }
370
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;
376// }
377// return result;
378// }
379//
380// /*
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.
387// */
388// protected boolean exit_process(LttngTraceState ts, LttngProcessState process) {
389// /*
390// * Wait for both schedule with exit dead and process free to happen.
391// * They can happen in any order.
392// */
393// process.incrementFree_events();
394// if (process.getFree_events() < 2) {
395// return false;
396// }
397//
398// process.getExecution_stack().clear();
399// process.getUser_stack().clear();
400// ts.getProcesses().remove(process);
401//
402// return true;
403// }
404//
405// // LttvProcessState *
406// // lttv_state_create_process(LttvTraceState *tcs, LttvProcessState *parent,
407// // guint cpu, guint pid, guint tgid, GQuark name, const LttTime *timestamp)
408// // {
409// // LttvProcessState *process = g_new(LttvProcessState, 1);
410// //
411// // LttvExecutionState *es;
412// //
413// // char buffer[128];
414// //
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.
426// //
427// // g_info("Process %u, core %p", process->pid, process);
428// // g_hash_table_insert(tcs->processes, process, process);
429// //
430// // if(parent) {
431// // process->ppid = parent->pid;
432// // process->creation_time = *timestamp;
433// // }
434// //
435// // /* No parent. This process exists but we are missing all information
436// // about
437// // its creation. The birth time is set to zero but we remember the time of
438// // insertion */
439// //
440// // else {
441// // process->ppid = 0;
442// // process->creation_time = ltt_time_zero;
443// // }
444// //
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;
466// //
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;
476// //
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);
480// //
481// // return process;
482// // }
483//
484// /**
485// * Find the process matching the given pid and cpu
486// *
487// * If cpu is 0, the cpu value is not matched and the selection is based on
488// * pid value only
489// *
490// * @param ts
491// * @param cpu
492// * @param pid
493// * @return
494// */
495// protected LttngProcessState lttv_state_find_process(LttngTraceState ts,
496// Long cpu, Long pid) {
497// // Define the return value
498// LttngProcessState process = null;
499//
500// // Obtain the list of available processes
501// List<LttngProcessState> processList = ts.getProcesses();
502//
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) {
509// return process;
510// }
511// }
512// }
513//
514// return process;
515// }
516//
517// /**
518// * @param ts
519// * @param cpu
520// * @param pid
521// * @param timestamp
522// * , Used when a new process is needed
523// * @return
524// */
525// protected LttngProcessState lttv_state_find_process_or_create(
526// LttngTraceState ts, Long cpu, Long pid, final TmfTimestamp timestamp) {
527//
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);
532// }
533// return process;
534// }
535//
536// /**
537// * @param traceSt
538// * @param cpu
539// * @param pid
540// * @param tgid
541// * @param timestamp
542// * @return
543// */
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);
548// return process;
549// }
550//
551// /**
552// * @param traceSt
553// * @param cpu
554// * @param pid
555// * @param tgid
556// * @param name
557// * @param timestamp
558// * @return
559// */
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);
566// return process;
567// }
568
569}
This page took 0.078859 seconds and 5 git commands to generate.