Temporary fix to make the architecture change transparent for now (bug id 302987)
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng / src / org / eclipse / linuxtools / lttng / state / evProcessor / state / StateUpdateHandlers.java
CommitLineData
5d10d135
ASL
1/*******************************************************************************
2 * Copyright (c) 2009 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 *******************************************************************************/
12package org.eclipse.linuxtools.lttng.state.evProcessor.state;
13
14import java.util.Map;
15
16import org.eclipse.linuxtools.lttng.TraceDebug;
17import org.eclipse.linuxtools.lttng.event.LttngEvent;
18import org.eclipse.linuxtools.lttng.state.StateStrings;
19import org.eclipse.linuxtools.lttng.state.StateStrings.BdevMode;
20import org.eclipse.linuxtools.lttng.state.StateStrings.CpuMode;
21import org.eclipse.linuxtools.lttng.state.StateStrings.Events;
22import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionMode;
23import org.eclipse.linuxtools.lttng.state.StateStrings.ExecutionSubMode;
24import org.eclipse.linuxtools.lttng.state.StateStrings.Fields;
25import org.eclipse.linuxtools.lttng.state.StateStrings.IRQMode;
26import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessStatus;
27import org.eclipse.linuxtools.lttng.state.StateStrings.ProcessType;
88144d4a 28import org.eclipse.linuxtools.lttng.state.evProcessor.IEventProcessing;
5d10d135
ASL
29import org.eclipse.linuxtools.lttng.state.model.LTTngCPUState;
30import org.eclipse.linuxtools.lttng.state.model.LttngBdevState;
31import org.eclipse.linuxtools.lttng.state.model.LttngExecutionState;
32import org.eclipse.linuxtools.lttng.state.model.LttngIRQState;
33import org.eclipse.linuxtools.lttng.state.model.LttngProcessState;
34import org.eclipse.linuxtools.lttng.state.model.LttngSoftIRQState;
35import org.eclipse.linuxtools.lttng.state.model.LttngTraceState;
36import org.eclipse.linuxtools.lttng.state.model.LttngTrapState;
37import org.eclipse.linuxtools.tmf.event.TmfTimestamp;
38
39/**
40 * Wraps the creation of individual handlers, each method creates and instance
41 * of the corresponding handler
42 *
43 * @author alvaro
44 *
45 */
46class StateUpdateHandlers {
47
88144d4a 48 final IEventProcessing getSyscallEntryHandler() {
5d10d135
ASL
49 AbsStateUpdate handler = new AbsStateUpdate() {
50
88144d4a
ASL
51 private Events eventType = Events.LTT_EVENT_SYSCALL_ENTRY;
52
5d10d135
ASL
53 // @Override
54 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
55
56 Long cpu = trcEvent.getCpuId();
57
58 // No syscall_entry update for initialization process
59 LttngProcessState process = traceSt.getRunning_process().get(
60 cpu);
61 if ((process != null) && (process.getPid() != null)
62 && (process.getPid().longValue() == 0L)) {
63 return true;
64 }
65
66 // Get the expected event field
67 Long syscall = getAFieldLong(trcEvent, traceSt,
68 Fields.LTT_FIELD_SYSCALL_ID);
69
70 String submode = null;
71 if (syscall == null) {
72 TraceDebug
73 .debug("Syscall Field not found, traceVent time: "
74 + trcEvent.getTimestamp());
75 } else {
76 submode = traceSt.getSyscall_names().get(syscall);
77 }
78
79 if (submode == null) {
80 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
81 .getInName();
82 }
83
84 push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
85 submode, trcEvent.getTimestamp(), traceSt);
86 return false;
87 }
88144d4a
ASL
88
89 // @Override
90 public Events getEventHandleType() {
91 return eventType;
92 }
5d10d135
ASL
93 };
94 return handler;
95 }
96
88144d4a 97 final IEventProcessing getsySyscallExitHandler() {
5d10d135
ASL
98 AbsStateUpdate handler = new AbsStateUpdate() {
99
88144d4a
ASL
100 private Events eventType = Events.LTT_EVENT_SYSCALL_EXIT;
101
5d10d135
ASL
102 // @Override
103 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
104
105 Long cpu = trcEvent.getCpuId();
106 LttngProcessState process = traceSt.getRunning_process().get(
107 cpu);
108
109 // No syscall_entry update for initialization process
110 if ((process != null) && (process.getPid() != null)
111 && (process.getPid().longValue() == 0L)) {
112 return true;
113 }
114
115 pop_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_SYSCALL,
116 traceSt, trcEvent.getTimestamp());
117 return false;
118
119 }
88144d4a
ASL
120
121 // @Override
122 public Events getEventHandleType() {
123 return eventType;
124 }
5d10d135
ASL
125 };
126 return handler;
127 }
128
129 /**
130 * Update stacks related to the parsing of an LttngEvent
131 *
132 * @return
133 */
88144d4a 134 final IEventProcessing getTrapEntryHandler() {
5d10d135
ASL
135 AbsStateUpdate handler = new AbsStateUpdate() {
136
88144d4a
ASL
137 private Events eventType = Events.LTT_EVENT_TRAP_ENTRY;
138
5d10d135
ASL
139 // @Override
140 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
141 Long cpu = trcEvent.getCpuId();
142
143 Long trap = getAFieldLong(trcEvent, traceSt,
144 Fields.LTT_FIELD_TRAP_ID);
145 if (trap == null) {
146 TraceDebug
147 .debug("Trap field could not be found, event time: "
148 + trcEvent.getTimestamp());
149 return true;
150 }
151
152 // ready the trap submode name
153 String submode = traceSt.getTrap_names().get(trap);
154
155 if (submode == null) {
156 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
157 .getInName();
158 }
159
160 /* update process state */
161 push_state(cpu, StateStrings.ExecutionMode.LTTV_STATE_TRAP,
162 submode, trcEvent.getTimestamp(), traceSt);
163
164 /* update cpu status */
165 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
166 cpu_push_mode(cpust, StateStrings.CpuMode.LTTV_CPU_TRAP);
167 cpust.pushToTrapStack(trap); /* update trap status */
88144d4a 168
5d10d135 169 // update Trap State
88144d4a
ASL
170 LttngTrapState trap_state = traceSt.getTrap_states().get(trap);
171 trap_state.incrementRunning();
172
5d10d135
ASL
173 return false;
174
175 }
88144d4a
ASL
176
177 // @Override
178 public Events getEventHandleType() {
179 return eventType;
180 }
5d10d135
ASL
181 };
182 return handler;
183 }
184
185 /**
186 *
187 * @return
188 */
88144d4a 189 final IEventProcessing getTrapExitHandler() {
5d10d135
ASL
190 AbsStateUpdate handler = new AbsStateUpdate() {
191
88144d4a
ASL
192 private Events eventType = Events.LTT_EVENT_TRAP_EXIT;
193
5d10d135
ASL
194 // @Override
195 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
196
197 Long cpu = trcEvent.getCpuId();
198 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
199 Long trap = cpust.popFromTrapStack();
200
201 /* update process state */
202 pop_state(cpu, ExecutionMode.LTTV_STATE_TRAP, traceSt, trcEvent
203 .getTimestamp());
204
205 /* update cpu status */
206 cpu_pop_mode(cpust);
207
208 if (trap != -1L) {
209 traceSt.getTrap_states().get(trap).decrementRunning();
210 }
211 // else {
212 // TraceDebug.debug("remove this line");
213 // }
214
215 return false;
216
217 }
88144d4a
ASL
218
219 // @Override
220 public Events getEventHandleType() {
221 return eventType;
222 }
5d10d135
ASL
223 };
224 return handler;
225 }
226
227 /**
228 *
229 * @return
230 */
88144d4a 231 final IEventProcessing getIrqEntryHandler() {
5d10d135
ASL
232 AbsStateUpdate handler = new AbsStateUpdate() {
233
88144d4a
ASL
234 private Events eventType = Events.LTT_EVENT_IRQ_ENTRY;
235
5d10d135
ASL
236 // @Override
237 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
238
239 Long cpu = trcEvent.getCpuId();
240
241 Long irq = getAFieldLong(trcEvent, traceSt,
242 Fields.LTT_FIELD_IRQ_ID);
88144d4a 243 if (irq == null) {
5d10d135
ASL
244 return true;
245 }
246
247 String submode;
248 submode = traceSt.getIrq_names().get(irq);
249
250 if (submode == null) {
251 submode = ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
252 .getInName();
253 }
254
255 /*
256 * Do something with the info about being in user or system mode
257 * when int?
258 */
259 push_state(cpu, ExecutionMode.LTTV_STATE_IRQ, submode, trcEvent
260 .getTimestamp(), traceSt);
261
262 /* update cpu state */
263 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
264 cpu_push_mode(cpust, CpuMode.LTTV_CPU_IRQ); /* mode stack */
265 cpust.pushToIrqStack(irq); /* last irq */
266
267 /* udpate irq state */
268 irq_push_mode(traceSt.getIrq_states().get(irq),
269 IRQMode.LTTV_IRQ_BUSY);
270 return false;
271
272 }
88144d4a
ASL
273
274 public Events getEventHandleType() {
275 return eventType;
276 }
5d10d135
ASL
277 };
278 return handler;
279 }
280
281 /**
282 *
283 * @return
284 */
88144d4a 285 final IEventProcessing getSoftIrqExitHandler() {
5d10d135
ASL
286 AbsStateUpdate handler = new AbsStateUpdate() {
287
88144d4a
ASL
288 private Events eventType = Events.LTT_EVENT_SOFT_IRQ_EXIT;
289
5d10d135
ASL
290 // @Override
291 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
292
293 Long cpu = trcEvent.getCpuId();
294 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
295 Long softirq = cpust.popFromSoftIrqStack();
296
297 // Update process status
298 pop_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, traceSt,
299 trcEvent.getTimestamp());
300
301 /* update softirq status */
302 if (softirq != -1) {
303 LttngSoftIRQState softIrqstate = traceSt
304 .getSoft_irq_states().get(softirq);
88144d4a 305 softIrqstate.decrementRunning();
5d10d135
ASL
306 }
307
308 /* update cpu status */
309 cpu_pop_mode(cpust);
310
311 return false;
312 }
88144d4a
ASL
313
314 // @Override
315 public Events getEventHandleType() {
316 return eventType;
317 }
5d10d135
ASL
318 };
319 return handler;
320 }
321
322 /**
323 *
324 * @return
325 */
88144d4a 326 final IEventProcessing getIrqExitHandler() {
5d10d135
ASL
327 AbsStateUpdate handler = new AbsStateUpdate() {
328
88144d4a
ASL
329 private Events eventType = Events.LTT_EVENT_IRQ_EXIT;
330
5d10d135
ASL
331 // @Override
332 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
333
334 Long cpu = trcEvent.getCpuId();
335
336 /* update process state */
337 pop_state(cpu, ExecutionMode.LTTV_STATE_IRQ, traceSt, trcEvent
338 .getTimestamp());
339
340 /* update cpu status */
341 LTTngCPUState cpust = traceSt.getCpu_states().get(cpu);
342 cpu_pop_mode(cpust);
343
344 /* update irq status */
345 Long last_irq = cpust.popFromIrqStack();
346 if (last_irq != -1L) {
347 LttngIRQState irq_state = traceSt.getIrq_states().get(
348 last_irq);
349 irq_pop_mode(irq_state);
350 }
351
352 return false;
353
354 }
88144d4a
ASL
355
356 // @Override
357 public Events getEventHandleType() {
358 return eventType;
359 }
5d10d135
ASL
360 };
361 return handler;
362 }
363
364 /**
365 *
366 * @return
367 */
88144d4a 368 final IEventProcessing getSoftIrqRaiseHandler() {
5d10d135
ASL
369 AbsStateUpdate handler = new AbsStateUpdate() {
370
371 private Events eventType = Events.LTT_EVENT_SOFT_IRQ_RAISE;
372
373 // @Override
374 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
375
376 // Long cpu = trcEvent.getCpuId();
377
378 // get event field
379 Long softirq = getAFieldLong(trcEvent, traceSt,
380 Fields.LTT_FIELD_SOFT_IRQ_ID);
381
382 if (softirq == null) {
383 TraceDebug.debug("Soft_irq_id not found in "
384 + eventType.getInName() + " time: "
385 + trcEvent.getTimestamp());
386 return true;
387 }
388
389 // String submode;
390 // String[] softIrqNames = traceSt.getSoft_irq_names();
391 // if (softirq < softIrqNames.length) {
392 // submode = softIrqNames[softirq];
393 // } else {
394 // submode = "softirq " + softirq;
395 // }
396
397 /* update softirq status */
398 /* a soft irq raises are not cumulative */
399 LttngSoftIRQState irqState = traceSt.getSoft_irq_states().get(
400 softirq);
401 if (irqState != null) {
402 irqState.setPending(1L);
403 } else {
404 TraceDebug
405 .debug("unexpected soft irq id value: " + softirq);
406 }
407
408 return false;
409
410 }
88144d4a
ASL
411
412 // @Override
413 public Events getEventHandleType() {
414 return eventType;
415 }
5d10d135
ASL
416 };
417 return handler;
418 }
419
420 /**
421 *
422 * @return
423 */
88144d4a 424 final IEventProcessing getSoftIrqEntryHandler() {
5d10d135
ASL
425 AbsStateUpdate handler = new AbsStateUpdate() {
426
88144d4a
ASL
427 private Events eventType = Events.LTT_EVENT_SOFT_IRQ_ENTRY;
428
5d10d135
ASL
429 // @Override
430 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
431
432 // obtrain cpu
433 Long cpu = trcEvent.getCpuId();
434
435 // get event field
436 Long softirq = getAFieldLong(trcEvent, traceSt,
437 Fields.LTT_FIELD_SOFT_IRQ_ID);
438
439 if (softirq == null) {
440 TraceDebug.debug("Soft IRQ ID not found, eventTime: "
441 + trcEvent.getTimestamp());
442 return true;
443 }
444
445 // obtain submode
446 Map<Long, String> softIrqNames = traceSt.getSoft_irq_names();
447 String submode = softIrqNames.get(softirq);
448 if (submode == null) {
449 submode = "softirq " + softirq;
450 softIrqNames.put(softirq, submode);
451 }
452
453 /* update softirq status */
454 LttngSoftIRQState irqState = traceSt.getSoft_irq_states().get(
455 softirq);
456 if (irqState != null) {
457 irqState.decrementPending();
458 irqState.incrementRunning();
459 } else {
460 TraceDebug
461 .debug("unexpected soft irq id value: " + softirq);
462 }
463
464 /* update cpu state */
465 LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
466 cpu_state.pushToSoftIrqStack(softirq);
467 cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_SOFT_IRQ);
468
469 /* update process execution mode state stack */
470 push_state(cpu, ExecutionMode.LTTV_STATE_SOFT_IRQ, submode,
471 trcEvent.getTimestamp(), traceSt);
472
473 return false;
474
475 }
88144d4a
ASL
476
477 // @Override
478 public Events getEventHandleType() {
479 return eventType;
480 }
5d10d135
ASL
481 };
482 return handler;
483 }
484
485 /**
486 * Method to handle the event: LTT_EVENT_LIST_INTERRRUPT
487 *
488 * @return
489 */
88144d4a 490 final IEventProcessing getEnumInterruptHandler() {
5d10d135
ASL
491 AbsStateUpdate handler = new AbsStateUpdate() {
492
493 private Events eventType = Events.LTT_EVENT_LIST_INTERRUPT;
494
495 // @Override
496 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
497 String action = getAFieldString(trcEvent, traceSt,
498 Fields.LTT_FIELD_ACTION);
499 Long irq = getAFieldLong(trcEvent, traceSt,
500 Fields.LTT_FIELD_IRQ_ID);
501
63eecb47 502 if (action == null) {
5d10d135
ASL
503 TraceDebug.debug("Field Action not found in event "
504 + eventType.getInName() + " time: "
505 + trcEvent.getTimestamp());
506 return true;
507 }
508
63eecb47 509 if (irq == null) {
5d10d135
ASL
510 TraceDebug.debug("Field irq_id not found in event "
511 + eventType.getInName() + " time: "
512 + trcEvent.getTimestamp());
513 return true;
514 }
515
516 Map<Long, String> irq_names = traceSt.getIrq_names();
517
518 irq_names.put(irq, action);
519 return false;
520
521 }
88144d4a
ASL
522
523 // @Override
524 public Events getEventHandleType() {
525 return eventType;
526 }
5d10d135
ASL
527 };
528 return handler;
529 }
530
531 /**
532 * Handle the event LTT_EVENT_REQUEST_ISSUE
533 *
534 * @return
535 */
88144d4a 536 final IEventProcessing getBdevRequestIssueHandler() {
5d10d135
ASL
537 AbsStateUpdate handler = new AbsStateUpdate() {
538
88144d4a
ASL
539 private Events eventType = Events.LTT_EVENT_REQUEST_ISSUE;
540
5d10d135
ASL
541 // @Override
542 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
543
544 // Get Fields
545 Long major = getAFieldLong(trcEvent, traceSt,
546 Fields.LTT_FIELD_MAJOR);
547 Long minor = getAFieldLong(trcEvent, traceSt,
548 Fields.LTT_FIELD_MINOR);
549 Long operation = getAFieldLong(trcEvent, traceSt,
550 Fields.LTT_FIELD_OPERATION);
551
552 // calculate bdevcode
553 Long devcode = mkdev(major, minor);
554
555 if (devcode == null) {
556 TraceDebug
557 .debug("incorrect calcualtion of bdevcode input( major: "
558 + major
559 + " minor: "
560 + minor
561 + " operation: " + operation);
562 return true;
563 }
564
565 Map<Long, LttngBdevState> bdev_states = traceSt
566 .getBdev_states();
567 // Get the instance
568 LttngBdevState bdevState = bdev_states.get(devcode);
569 if (bdevState == null) {
570 bdevState = new LttngBdevState();
571 }
572
573 // update the mode in the stack
574 if (operation == 0L) {
575 bdevState.pushToBdevStack(BdevMode.LTTV_BDEV_BUSY_READING);
576 } else {
577 bdevState.pushToBdevStack(BdevMode.LTTV_BDEV_BUSY_WRITING);
578 }
579
580 // make sure it is included in the set
581 bdev_states.put(devcode, bdevState);
582 return false;
583
584 }
88144d4a
ASL
585
586 // @Override
587 public Events getEventHandleType() {
588 return eventType;
589 }
5d10d135
ASL
590 };
591 return handler;
592 }
593
594 /**
595 * <p>
596 * Handling event: LTT_EVENT_REQUEST_COMPLETE
597 * </p>
598 * <p>
599 * FIELDS(LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION
600 * </p>
601 *
602 * @return
603 */
88144d4a 604 final IEventProcessing getBdevRequestCompleteHandler() {
5d10d135
ASL
605 AbsStateUpdate handler = new AbsStateUpdate() {
606
88144d4a
ASL
607 private Events eventType = Events.LTT_EVENT_REQUEST_COMPLETE;
608
5d10d135
ASL
609 // @Override
610 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
611
612 // Get Fields
613 Long major = getAFieldLong(trcEvent, traceSt,
614 Fields.LTT_FIELD_MAJOR);
615 Long minor = getAFieldLong(trcEvent, traceSt,
616 Fields.LTT_FIELD_MINOR);
617 Long operation = getAFieldLong(trcEvent, traceSt,
618 Fields.LTT_FIELD_OPERATION);
619
620 // calculate bdevcode
621 Long devcode = mkdev(major, minor);
622
623 if (devcode == null) {
624 TraceDebug
625 .debug("incorrect calcualtion of bdevcode input( major: "
626 + major
627 + " minor: "
628 + minor
629 + " operation: " + operation);
630 return true;
631 }
632
633 Map<Long, LttngBdevState> bdev_states = traceSt
634 .getBdev_states();
635 // Get the instance
636 LttngBdevState bdevState = bdev_states.get(devcode);
637 if (bdevState == null) {
638 bdevState = new LttngBdevState();
639 }
640
641 /* update block device */
642 bdev_pop_mode(bdevState);
643
644 return false;
645
646 }
88144d4a
ASL
647
648 // @Override
649 public Events getEventHandleType() {
650 return eventType;
651 }
5d10d135
ASL
652 };
653 return handler;
654 }
655
656 /**
657 * <p>
658 * Handles event: LTT_EVENT_FUNCTION_ENTRY
659 * </p>
660 * <p>
661 * FIELDS: LTT_FIELD_THIS_FN, LTT_FIELD_CALL_SITE
662 * </p>
663 *
664 * @return
665 */
88144d4a 666 final IEventProcessing getFunctionEntryHandler() {
5d10d135
ASL
667 AbsStateUpdate handler = new AbsStateUpdate() {
668
88144d4a
ASL
669 private Events eventType = Events.LTT_EVENT_FUNCTION_ENTRY;
670
5d10d135
ASL
671 // @Override
672 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
673 Long cpu = trcEvent.getCpuId();
674 Long funcptr = getAFieldLong(trcEvent, traceSt,
675 Fields.LTT_FIELD_THIS_FN);
676
677 push_function(traceSt, funcptr, cpu);
678 return false;
679
680 }
88144d4a
ASL
681
682 // @Override
683 public Events getEventHandleType() {
684 return eventType;
685 }
5d10d135
ASL
686 };
687 return handler;
688 }
689
690 /**
691 *
692 * @return
693 */
88144d4a 694 final IEventProcessing getFunctionExitHandler() {
5d10d135
ASL
695 AbsStateUpdate handler = new AbsStateUpdate() {
696
88144d4a
ASL
697 private Events eventType = Events.LTT_EVENT_FUNCTION_EXIT;
698
5d10d135
ASL
699 // @Override
700 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
701
702 Long funcptr = getAFieldLong(trcEvent, traceSt,
703 Fields.LTT_FIELD_THIS_FN);
704
705 pop_function(traceSt, trcEvent, funcptr);
706 return false;
707
708 }
88144d4a
ASL
709
710 // @Override
711 public Events getEventHandleType() {
712 return eventType;
713 }
5d10d135
ASL
714 };
715 return handler;
716 }
717
718 /**
719 * <p>
720 * process event: LTT_EVENT_SYS_CALL_TABLE
721 * </p>
722 * <p>
723 * fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
724 * </p>
725 *
726 * @return
727 */
88144d4a 728 final IEventProcessing getDumpSyscallHandler() {
5d10d135
ASL
729 AbsStateUpdate handler = new AbsStateUpdate() {
730
88144d4a
ASL
731 private Events eventType = Events.LTT_EVENT_SYS_CALL_TABLE;
732
5d10d135
ASL
733 // @Override
734 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
735 // obtain the syscall id
736 Long id = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_ID);
737
738 // Long address = getAFieldLong(trcEvent, traceSt,
739 // Fields.LTT_FIELD_ADDRESS);
740
741 // Obtain the symbol
742 String symbol = getAFieldString(trcEvent, traceSt,
743 Fields.LTT_FIELD_SYMBOL);
744
745 // fill the symbol to the sycall_names collection
746 traceSt.getSyscall_names().put(id, symbol);
747
748 return false;
749 }
88144d4a
ASL
750
751 // @Override
752 public Events getEventHandleType() {
753 return eventType;
754 }
5d10d135
ASL
755 };
756 return handler;
757 }
758
759 /**
760 * <p>
761 * Handles event: LTT_EVENT_KPROBE_TABLE
762 * </p>
763 * <p>
764 * Fields: LTT_FIELD_IP, LTT_FIELD_SYMBOL
765 * </p>
766 *
767 * @return
768 */
88144d4a 769 final IEventProcessing getDumpKprobeHandler() {
5d10d135
ASL
770 AbsStateUpdate handler = new AbsStateUpdate() {
771
88144d4a
ASL
772 private Events eventType = Events.LTT_EVENT_KPROBE_TABLE;
773
5d10d135
ASL
774 // @Override
775 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
776
777 Long ip = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_IP);
778 String symbol = getAFieldString(trcEvent, traceSt,
779 Fields.LTT_FIELD_SYMBOL);
780
781 traceSt.getKprobe_table().put(ip, symbol);
782
783 return false;
784
785 }
88144d4a
ASL
786
787 // @Override
788 public Events getEventHandleType() {
789 return eventType;
790 }
5d10d135
ASL
791 };
792 return handler;
793 }
794
795 /**
796 * <p>
797 * Handles: LTT_EVENT_SOFTIRQ_VEC
798 * </p>
799 * <p>
800 * Fields: LTT_FIELD_ID, LTT_FIELD_ADDRESS, LTT_FIELD_SYMBOL
801 * </p>
802 *
803 * @return
804 */
88144d4a 805 final IEventProcessing getDumpSoftIrqHandler() {
5d10d135
ASL
806 AbsStateUpdate handler = new AbsStateUpdate() {
807
88144d4a
ASL
808 private Events eventType = Events.LTT_EVENT_SOFTIRQ_VEC;
809
5d10d135
ASL
810 // @Override
811 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
812
813 // Get id
814 Long id = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_ID);
815
816 // Address not needed
817 // Long address = ltt_event_get_long_unsigned(e,
818 // lttv_trace_get_hook_field(th,
819 // 1));
820
821 // Get symbol
822 String symbol = getAFieldString(trcEvent, traceSt,
823 Fields.LTT_FIELD_SYMBOL);
824
825 // Register the soft irq name
826 traceSt.getSoft_irq_names().put(id, symbol);
827 return false;
828
829 }
88144d4a
ASL
830
831 // @Override
832 public Events getEventHandleType() {
833 return eventType;
834 }
5d10d135
ASL
835 };
836 return handler;
837 }
838
839 /**
840 * <p>
841 * Handles: LTT_EVENT_SCHED_SCHEDULE
842 * </p>
843 * <p>
844 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID, LTT_FIELD_PREV_STATE
845 * </p>
846 *
847 * @return
848 */
88144d4a 849 final IEventProcessing getSchedChangeHandler() {
5d10d135
ASL
850 AbsStateUpdate handler = new AbsStateUpdate() {
851
88144d4a
ASL
852 private Events eventType = Events.LTT_EVENT_SCHED_SCHEDULE;
853
5d10d135
ASL
854 // @Override
855 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
856
857 Long cpu = trcEvent.getCpuId();
858 TmfTimestamp eventTime = trcEvent.getTimestamp();
859
860 LttngProcessState process = traceSt.getRunning_process().get(
861 cpu);
862
863 Long pid_out = getAFieldLong(trcEvent, traceSt,
864 Fields.LTT_FIELD_PREV_PID);
865 Long pid_in = getAFieldLong(trcEvent, traceSt,
866 Fields.LTT_FIELD_NEXT_PID);
867 Long state_out = getAFieldLong(trcEvent, traceSt,
868 Fields.LTT_FIELD_PREV_STATE);
869
870 if (process != null) {
871
872 /*
873 * We could not know but it was not the idle process
874 * executing. This should only happen at the beginning,
875 * before the first schedule event, and when the initial
876 * information (current process for each CPU) is missing. It
877 * is not obvious how we could, after the fact, compensate
878 * the wrongly attributed statistics.
879 */
880
881 // This test only makes sense once the state is known and if
882 // there
883 // is no
884 // missing events. We need to silently ignore schedchange
885 // coming
886 // after a
887 // process_free, or it causes glitches. (FIXME)
888 // if(unlikely(process->pid != pid_out)) {
889 // g_assert(process->pid == 0);
890 // }
891 if ((process.getPid().longValue() == 0L)
892 && (process.getState().getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN)) {
893 if ((pid_out != null) && (pid_out.longValue() == 0L)) {
894 /*
895 * Scheduling out of pid 0 at beginning of the trace
896 * : we know for sure it is in syscall mode at this
897 * point.
898 */
899
900 process.getState().setExec_mode(
901 ExecutionMode.LTTV_STATE_SYSCALL);
902 process.getState().setProc_status(
903 ProcessStatus.LTTV_STATE_WAIT);
904 process.getState().setChange_Time(
28b94d61 905 trcEvent.getTimestamp().getValue());
5d10d135 906 process.getState().setEntry_Time(
28b94d61 907 trcEvent.getTimestamp().getValue());
5d10d135
ASL
908 }
909 } else {
910 if (process.getState().getProc_status() == ProcessStatus.LTTV_STATE_EXIT) {
911 process.getState().setProc_status(
912 ProcessStatus.LTTV_STATE_ZOMBIE);
913 process.getState().setChange_Time(
28b94d61 914 trcEvent.getTimestamp().getValue());
5d10d135
ASL
915 } else {
916 if ((state_out != null)
917 && (state_out.longValue() == 0L)) {
918 process.getState().setProc_status(
919 ProcessStatus.LTTV_STATE_WAIT_CPU);
920 } else {
921 process.getState().setProc_status(
922 ProcessStatus.LTTV_STATE_WAIT);
923 }
924
925 process.getState().setChange_Time(
28b94d61 926 trcEvent.getTimestamp().getValue());
5d10d135
ASL
927 }
928
929 if ((state_out != null)
930 && (state_out == 32L || state_out == 64L)) { /*
931 * EXIT_DEAD
932 * ||
933 * TASK_DEAD
934 */
935 /* see sched.h for states */
936 if (!exit_process(traceSt, process)) {
937 process.getState().setProc_status(
938 ProcessStatus.LTTV_STATE_DEAD);
939 process.getState().setChange_Time(
28b94d61 940 trcEvent.getTimestamp().getValue());
5d10d135
ASL
941 }
942 }
943 }
944 }
945 process = lttv_state_find_process_or_create(traceSt, cpu,
946 pid_in, eventTime);
947
948 traceSt.getRunning_process().put(cpu, process);
949
950 process.getState().setProc_status(ProcessStatus.LTTV_STATE_RUN);
28b94d61 951 process.getState().setChange_Time(eventTime.getValue());
5d10d135
ASL
952 process.setCpu(cpu);
953 // process->state->s = LTTV_STATE_RUN;
954 // if(process->usertrace)
955 // process->usertrace->cpu = cpu;
956 // process->last_cpu_index =
957 // ltt_tracefile_num(((LttvTracefileContext*)s)->tf);
958
959 // process->state->change = s->parent.timestamp;
960
961 LTTngCPUState cpu_state = traceSt.getCpu_states().get(cpu);
962 /* update cpu status */
963 if ((pid_in != null) && (pid_in.longValue() == 0L)) {
964
965 /* going to idle task */
966 cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_IDLE);
967 } else {
968 /*
969 * scheduling a real task. we must be careful here: if we
970 * just schedule()'ed to a process that is in a trap, we
971 * must put the cpu in trap mode
972 */
973 cpu_set_base_mode(cpu_state, CpuMode.LTTV_CPU_BUSY);
974 if (process.getState().getExec_mode() == ExecutionMode.LTTV_STATE_TRAP) {
975 cpu_push_mode(cpu_state, CpuMode.LTTV_CPU_TRAP);
976 }
977 }
978 return false;
979
980 }
88144d4a
ASL
981
982 // @Override
983 public Events getEventHandleType() {
984 return eventType;
985 }
5d10d135
ASL
986 };
987 return handler;
988 }
989
990 /**
991 * <p>
992 * Handles: LTT_EVENT_PROCESS_FORK
993 * </p>
994 * <p>
995 * Fields: FIELD_ARRAY(LTT_FIELD_PARENT_PID, LTT_FIELD_CHILD_PID,
996 * LTT_FIELD_CHILD_TGID)
997 * </p>
998 *
999 * @return
1000 */
88144d4a 1001 final IEventProcessing getProcessForkHandler() {
5d10d135
ASL
1002 AbsStateUpdate handler = new AbsStateUpdate() {
1003
88144d4a
ASL
1004 private Events eventType = Events.LTT_EVENT_PROCESS_FORK;
1005
5d10d135
ASL
1006 // @Override
1007 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1008
1009 Long cpu = trcEvent.getCpuId();
1010 LttngProcessState process = traceSt.getRunning_process().get(
1011 cpu);
1012 TmfTimestamp timeStamp = trcEvent.getTimestamp();
1013
1014 // /* Parent PID */
1015 // Long parent_pid = getAFieldLong(trcEvent, traceSt,
1016 // Fields.LTT_FIELD_PARENT_PID);
1017
1018 /* Child PID */
1019 /* In the Linux Kernel, there is one PID per thread. */
1020 Long child_pid = getAFieldLong(trcEvent, traceSt,
1021 Fields.LTT_FIELD_CHILD_PID);
1022
1023 /* Child TGID */
1024 /* tgid in the Linux kernel is the "real" POSIX PID. */
1025 Long child_tgid = getAFieldLong(trcEvent, traceSt,
1026 Fields.LTT_FIELD_CHILD_TGID);
1027 if (child_tgid == null) {
1028 child_tgid = 0L;
1029 }
1030
1031 /*
1032 * Mathieu : it seems like the process might have been scheduled
1033 * in before the fork, and, in a rare case, might be the current
1034 * process. This might happen in a SMP case where we don't have
1035 * enough precision on the clocks.
1036 *
1037 * Test reenabled after precision fixes on time. (Mathieu)
1038 */
1039 // #if 0
1040 // zombie_process = lttv_state_find_process(ts, ANY_CPU,
1041 // child_pid);
1042 //
1043 // if(unlikely(zombie_process != NULL)) {
1044 // /* Reutilisation of PID. Only now we are sure that the old
1045 // PID
1046 // * has been released. FIXME : should know when release_task
1047 // happens
1048 // instead.
1049 // */
1050 // guint num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1051 // guint i;
1052 // for(i=0; i< num_cpus; i++) {
1053 // g_assert(zombie_process != ts->running_process[i]);
1054 // }
1055 //
1056 // exit_process(s, zombie_process);
1057 // }
1058 // #endif //0
1059
1060 if (process.getPid().equals(child_pid)) {
1061 TraceDebug
1062 .debug("Unexpected, process pid equal to child pid: "
1063 + child_pid
1064 + " Event Time: "
1065 + trcEvent.getTimestamp());
1066 }
1067
1068 // g_assert(process->pid != child_pid);
1069 // FIXME : Add this test in the "known state" section
1070 // g_assert(process->pid == parent_pid);
1071 LttngProcessState child_process = lttv_state_find_process(
1072 traceSt, ANY_CPU, child_pid);
1073 if (child_process == null) {
1074 child_process = create_process(traceSt, cpu, child_pid,
1075 child_tgid, timeStamp);
28b94d61 1076 child_process.setPpid(process.getPid(), timeStamp.getValue());
5d10d135
ASL
1077 } else {
1078 /*
1079 * The process has already been created : due to time
1080 * imprecision between multiple CPUs : it has been scheduled
1081 * in before creation. Note that we shouldn't have this kind
1082 * of imprecision.
1083 *
1084 * Simply put a correct parent.
1085 */
1086 StringBuilder sb = new StringBuilder("Process " + child_pid);
1087 sb.append(" has been created at ["
1088 + child_process.getCreation_time() + "] ");
1089 sb.append("and inserted at ["
1090 + child_process.getInsertion_time() + "] ");
1091 sb.append("before \nfork on cpu " + cpu + " Event time: ["
1092 + trcEvent + "]\n.");
1093 sb
1094 .append("Probably an unsynchronized TSD problem on the traced machine.");
1095 TraceDebug.debug(sb.toString());
1096
1097 // g_assert(0); /* This is a problematic case : the process
1098 // has
1099 // beencreated
1100 // before the fork event */
1101 child_process.setPpid(process.getPid());
1102 child_process.setTgid(child_tgid);
1103 }
1104
1105 if (!child_process.getName().equals(
1106 ProcessStatus.LTTV_STATE_UNNAMED.getInName())) {
1107 TraceDebug.debug("Unexpected child process status: "
1108 + child_process.getName());
1109 }
1110
1111 child_process.setName(process.getName());
1112 child_process.setBrand(process.getBrand());
1113
1114 return false;
1115
1116 }
88144d4a
ASL
1117
1118 // @Override
1119 public Events getEventHandleType() {
1120 return eventType;
1121 }
5d10d135
ASL
1122 };
1123 return handler;
1124 }
1125
1126 /**
1127 * <p>
1128 * Handles: LTT_EVENT_KTHREAD_CREATE
1129 * </p>
1130 * <p>
1131 * Fields: LTT_FIELD_PID
1132 * </p>
1133 *
1134 * @return
1135 */
88144d4a 1136 final IEventProcessing getProcessKernelThreadHandler() {
5d10d135
ASL
1137 AbsStateUpdate handler = new AbsStateUpdate() {
1138
88144d4a
ASL
1139 private Events eventType = Events.LTT_EVENT_KTHREAD_CREATE;
1140
5d10d135
ASL
1141 // @Override
1142 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1143 /*
1144 * We stamp a newly created process as kernel_thread. The thread
1145 * should not be running yet.
1146 */
1147
1148 LttngExecutionState exState;
1149 Long pid;
1150 LttngProcessState process;
1151
1152 /* PID */
1153 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1154 // s->parent.target_pid = pid;
1155
1156 process = lttv_state_find_process_or_create(traceSt, ANY_CPU,
1157 pid, new TmfTimestamp());
1158
1159 if (!process.getState().getProc_status().equals(
1160 ProcessStatus.LTTV_STATE_DEAD)) {
1161 // Leave only the first element in the stack with execution
1162 // mode to
1163 // syscall
1164 exState = process.getFirstElementFromExecutionStack();
1165 exState.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1166 process.clearExecutionStack();
1167 process.pushToExecutionStack(exState);
1168 }
1169
1170 process.setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1171
1172 return false;
1173
1174 }
88144d4a
ASL
1175
1176 // @Override
1177 public Events getEventHandleType() {
1178 return eventType;
1179 }
5d10d135
ASL
1180 };
1181 return handler;
1182 }
1183
1184 /**
1185 * <p>
1186 * Handles: LTT_EVENT_PROCESS_EXIT
1187 * </p>
1188 * <p>
1189 * LTT_FIELD_PID
1190 * </p>
1191 *
1192 * @return
1193 */
88144d4a 1194 final IEventProcessing getProcessExitHandler() {
5d10d135
ASL
1195 AbsStateUpdate handler = new AbsStateUpdate() {
1196
88144d4a
ASL
1197 private Events eventType = Events.LTT_EVENT_PROCESS_EXIT;
1198
5d10d135
ASL
1199 // @Override
1200 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1201
1202 Long pid;
1203 LttngProcessState process;
1204
1205 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1206 // s->parent.target_pid = pid;
1207
1208 // FIXME : Add this test in the "known state" section
1209 // g_assert(process->pid == pid);
1210
1211 process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1212 if (process != null) {
1213 process.getState().setProc_status(
1214 ProcessStatus.LTTV_STATE_EXIT);
1215 }
1216 return false;
1217
1218 }
88144d4a
ASL
1219
1220 // @Override
1221 public Events getEventHandleType() {
1222 return eventType;
1223 }
5d10d135
ASL
1224 };
1225 return handler;
1226 }
1227
1228 /**
1229 * <p>
1230 * Handles: LTT_EVENT_PROCESS_FREE
1231 * </p>
1232 * <p>
1233 * Fields: LTT_FIELD_PID
1234 * </p>
1235 *
1236 * @return
1237 */
88144d4a 1238 final IEventProcessing getProcessFreeHandler() {
5d10d135
ASL
1239 AbsStateUpdate handler = new AbsStateUpdate() {
1240
88144d4a
ASL
1241 private Events eventType = Events.LTT_EVENT_PROCESS_FREE;
1242
5d10d135
ASL
1243 // @Override
1244 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1245
1246 Long release_pid;
1247 LttngProcessState process;
1248
1249 /* PID of the process to release */
1250 release_pid = getAFieldLong(trcEvent, traceSt,
1251 Fields.LTT_FIELD_PID);
1252 // s->parent.target_pid = release_pid;
1253
1254 if ((release_pid != null) && (release_pid.longValue() == 0L)) {
1255 TraceDebug.debug("Unexpected release_pid: 0, Event time: "
1256 + trcEvent.getTimestamp());
1257 }
1258
1259 process = lttv_state_find_process(traceSt, ANY_CPU, release_pid);
1260 if (process != null) {
1261 exit_process(traceSt, process);
1262 }
1263
1264 return false;
1265 // DISABLED
1266 // if(process != null) {
1267 /*
1268 * release_task is happening at kernel level : we can now safely
1269 * release the data structure of the process
1270 */
1271 // This test is fun, though, as it may happen that
1272 // at time t : CPU 0 : process_free
1273 // at time t+150ns : CPU 1 : schedule out
1274 // Clearly due to time imprecision, we disable it. (Mathieu)
1275 // If this weird case happen, we have no choice but to put the
1276 // Currently running process on the cpu to 0.
1277 // I re-enable it following time precision fixes. (Mathieu)
1278 // Well, in the case where an process is freed by a process on
1279 // another
1280 // CPU
1281 // and still scheduled, it happens that this is the schedchange
1282 // that
1283 // will
1284 // drop the last reference count. Do not free it here!
1285
1286 // int num_cpus = ltt_trace_get_num_cpu(ts->parent.t);
1287 // guint i;
1288 // for(i=0; i< num_cpus; i++) {
1289 // //g_assert(process != ts->running_process[i]);
1290 // if(process == ts->running_process[i]) {
1291 // //ts->running_process[i] = lttv_state_find_process(ts, i, 0);
1292 // break;
1293 // }
1294 // }
1295 // if(i == num_cpus) /* process is not scheduled */
1296 // exit_process(s, process);
1297 // }
1298 //
1299 // return false;
1300
1301 }
88144d4a
ASL
1302
1303 // @Override
1304 public Events getEventHandleType() {
1305 return eventType;
1306 }
5d10d135
ASL
1307 };
1308 return handler;
1309 }
1310
1311 /**
1312 * <p>
1313 * Handles: LTT_EVENT_EXEC
1314 * </p>
1315 * <p>
1316 * FIELDS: LTT_FIELD_FILENAME
1317 * </p>
1318 *
1319 * @return
1320 */
88144d4a 1321 final IEventProcessing getProcessExecHandler() {
5d10d135
ASL
1322 AbsStateUpdate handler = new AbsStateUpdate() {
1323
88144d4a
ASL
1324 private Events eventType = Events.LTT_EVENT_EXEC;
1325
5d10d135
ASL
1326 // @Override
1327 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1328
1329 Long cpu = trcEvent.getCpuId();
1330 LttngProcessState process = traceSt.getRunning_process().get(
1331 cpu);
1332
1333 // #if 0//how to use a sequence that must be transformed in a
1334 // string
1335 // /* PID of the process to release */
1336 // guint64 name_len = ltt_event_field_element_number(e,
1337 // lttv_trace_get_hook_field(th, 0));
1338 // //name = ltt_event_get_string(e,
1339 // lttv_trace_get_hook_field(th, 0));
1340 // LttField *child = ltt_event_field_element_select(e,
1341 // lttv_trace_get_hook_field(th, 0), 0);
1342 // gchar *name_begin =
1343 // (gchar*)(ltt_event_data(e)+ltt_event_field_offset(e, child));
1344 // gchar *null_term_name = g_new(gchar, name_len+1);
1345 // memcpy(null_term_name, name_begin, name_len);
1346 // null_term_name[name_len] = '\0';
1347 // process->name = g_quark_from_string(null_term_name);
1348 // #endif //0
1349
1350 process.setName(getAFieldString(trcEvent, traceSt,
1351 Fields.LTT_FIELD_FILENAME));
1352 process.setBrand(StateStrings.LTTV_STATE_UNBRANDED);
1353 return false;
1354
1355 }
88144d4a
ASL
1356
1357 // @Override
1358 public Events getEventHandleType() {
1359 return eventType;
1360 }
5d10d135
ASL
1361 };
1362 return handler;
1363 }
1364
1365 /**
1366 * <p>
1367 * LTT_EVENT_THREAD_BRAND
1368 * </p>
1369 * <p>
1370 * FIELDS: LTT_FIELD_NAME
1371 * </p>
1372 *
1373 * @return
1374 */
88144d4a 1375 final IEventProcessing GetThreadBrandHandler() {
5d10d135
ASL
1376 AbsStateUpdate handler = new AbsStateUpdate() {
1377
88144d4a
ASL
1378 private Events eventType = Events.LTT_EVENT_THREAD_BRAND;
1379
5d10d135
ASL
1380 // @Override
1381 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1382
1383 String name;
1384 Long cpu = trcEvent.getCpuId();
1385 LttngProcessState process = traceSt.getRunning_process().get(
1386 cpu);
1387
1388 name = getAFieldString(trcEvent, traceSt, Fields.LTT_FIELD_NAME);
1389 process.setBrand(name);
1390 return false;
1391
1392 }
88144d4a
ASL
1393
1394 // @Override
1395 public Events getEventHandleType() {
1396 return eventType;
1397 }
5d10d135
ASL
1398 };
1399 return handler;
1400 }
1401
1402 /**
1403 * @return
1404 */
88144d4a 1405 final IEventProcessing getStateDumpEndHandler() {
5d10d135
ASL
1406 AbsStateUpdate handler = new AbsStateUpdate() {
1407
88144d4a
ASL
1408 private Events eventType = Events.LTT_EVENT_STATEDUMP_END;
1409
5d10d135
ASL
1410 // @Override
1411 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1412
1413 /* For all processes */
1414 /*
1415 * if kernel thread, if stack[0] is unknown, set to syscall
1416 * mode, wait
1417 */
1418 /* else, if stack[0] is unknown, set to user mode, running */
2211df66 1419 LttngProcessState[] processes = traceSt.getProcesses();
5d10d135 1420 TmfTimestamp time = trcEvent.getTimestamp();
2211df66
FC
1421
1422 for (int pos = 0; pos < processes.length; pos++) {
1423 fix_process(processes[pos], time);
5d10d135 1424 }
2211df66 1425
5d10d135
ASL
1426 return false;
1427
1428 }
1429
88144d4a
ASL
1430 // @Override
1431 public Events getEventHandleType() {
1432 return eventType;
1433 }
1434
5d10d135
ASL
1435 /**
1436 * Private method used to establish the first execution state in the
1437 * stack for a given process
1438 *
1439 * @param process
1440 * @param timestamp
1441 */
1442 private void fix_process(LttngProcessState process,
1443 TmfTimestamp timestamp) {
1444
1445 LttngExecutionState es;
1446
1447 if (process.getType() == ProcessType.LTTV_STATE_KERNEL_THREAD) {
1448 es = process.getFirstElementFromExecutionStack();
1449
1450 if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1451 es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1452 es
1453 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1454 .getInName());
28b94d61
FC
1455 es.setEntry_Time(timestamp.getValue());
1456 es.setChange_Time(timestamp.getValue());
5d10d135
ASL
1457 es.setCum_cpu_time(0L);
1458 if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1459 es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
1460 }
1461 }
1462 } else {
1463 es = process.getFirstElementFromExecutionStack();
1464 if (es.getExec_mode() == ExecutionMode.LTTV_STATE_MODE_UNKNOWN) {
1465 es.setExec_mode(ExecutionMode.LTTV_STATE_USER_MODE);
1466 es
1467 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1468 .getInName());
28b94d61
FC
1469 es.setEntry_Time(timestamp.getValue());
1470 es.setChange_Time(timestamp.getValue());
5d10d135
ASL
1471 es.setCum_cpu_time(0L);
1472 if (es.getProc_status() == ProcessStatus.LTTV_STATE_UNNAMED) {
1473 es.setProc_status(ProcessStatus.LTTV_STATE_RUN);
1474 }
1475
1476 // If the first element is also the one on top... mean
1477 // we have ONE element on the stack
1478 if (process.getFirstElementFromExecutionStack() == process
1479 .peekFromExecutionStack()) {
1480 /*
1481 * Still in bottom unknown mode, means never did a
1482 * system call May be either in user mode, syscall
1483 * mode, running or waiting.
1484 */
1485 /*
1486 * FIXME : we may be tagging syscall mode when being
1487 * user mode
1488 */
1489 // Get a new execution State
1490 es = new LttngExecutionState();
1491
1492 // initialize values
1493 es.setExec_mode(ExecutionMode.LTTV_STATE_SYSCALL);
1494 es
1495 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_NONE
1496 .getInName());
28b94d61
FC
1497 es.setEntry_Time(timestamp.getValue());
1498 es.setChange_Time(timestamp.getValue());
5d10d135 1499 es.setCum_cpu_time(0L);
63eecb47 1500 es.setProc_status(ProcessStatus.LTTV_STATE_WAIT);
5d10d135
ASL
1501
1502 // Push the new state to the stack
1503 process.pushToExecutionStack(es);
1504 }
1505 }
1506 }
1507 }
1508 };
1509 return handler;
1510 }
1511
1512 /**
1513 * <p>
1514 * Handles: LTT_EVENT_PROCESS_STATE
1515 * </p>
1516 * <p>
1517 * FIELDS: LTT_FIELD_PID, LTT_FIELD_PARENT_PID, LTT_FIELD_NAME,
1518 * LTT_FIELD_TYPE, LTT_FIELD_MODE, LTT_FIELD_SUBMODE, LTT_FIELD_STATUS,
1519 * LTT_FIELD_TGID
1520 * </p>
1521 *
1522 * @return
1523 */
88144d4a 1524 final IEventProcessing getEnumProcessStateHandler() {
5d10d135
ASL
1525 AbsStateUpdate handler = new AbsStateUpdate() {
1526
88144d4a
ASL
1527 private Events eventType = Events.LTT_EVENT_PROCESS_STATE;
1528
5d10d135
ASL
1529 // @Override
1530 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
1531
1532 Long parent_pid;
1533 Long pid;
1534 Long tgid;
1535 String command;
1536 Long cpu = trcEvent.getCpuId();
28b94d61 1537
5d10d135
ASL
1538 LttngProcessState process = traceSt.getRunning_process().get(
1539 cpu);
1540 LttngProcessState parent_process;
1541 String type;
1542 // String mode, submode, status;
1543 LttngExecutionState es;
28b94d61 1544
5d10d135
ASL
1545 /* PID */
1546 pid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_PID);
1547
1548 /* Parent PID */
1549 parent_pid = getAFieldLong(trcEvent, traceSt,
1550 Fields.LTT_FIELD_PARENT_PID);
1551
1552 /* Command name */
1553 command = getAFieldString(trcEvent, traceSt,
1554 Fields.LTT_FIELD_NAME);
1555
1556 Long typeVal = getAFieldLong(trcEvent, traceSt,
1557 Fields.LTT_FIELD_TYPE);
63eecb47
FC
1558
1559 type = ProcessType.LTTV_STATE_KERNEL_THREAD.getInName();
5d10d135
ASL
1560 if ((typeVal != null) && (typeVal.longValue() == 0L)) {
1561 type = ProcessType.LTTV_STATE_USER_THREAD.getInName();
1562 }
1563
1564 // /* mode */
1565 // mode = getAFieldString(trcEvent, traceSt,
1566 // Fields.LTT_FIELD_MODE);
1567 //
1568 // /* submode */
1569 // submode = getAFieldString(trcEvent, traceSt,
1570 // Fields.LTT_FIELD_SUBMODE);
1571 //
1572 // /* status */
1573 // status = getAFieldString(trcEvent, traceSt,
1574 // Fields.LTT_FIELD_STATUS);
1575
1576 /* TGID */
1577 tgid = getAFieldLong(trcEvent, traceSt, Fields.LTT_FIELD_TGID);
1578 if (tgid == null) {
1579 tgid = 0L;
1580 }
1581
1582 if ((pid != null) && (pid.longValue() == 0L)) {
1583 for (Long acpu : traceSt.getCpu_states().keySet()) {
1584 process = lttv_state_find_process(traceSt, acpu, pid);
1585 if (process != null) {
1586 process.setPpid(parent_pid);
1587 process.setTgid(tgid);
1588 process.setName(command);
1589 process
1590 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1591 } else {
1592 StringBuilder sb = new StringBuilder(
1593 "Unexpected, null process read from the TraceState list of processes, event time: "
1594 + trcEvent.getTimestamp());
1595 TraceDebug.debug(sb.toString());
1596 }
1597 }
1598 } else {
1599 /*
1600 * The process might exist if a process was forked while
1601 * performing the state dump.
1602 */
1603 process = lttv_state_find_process(traceSt, ANY_CPU, pid);
1604 if (process == null) {
1605 parent_process = lttv_state_find_process(traceSt,
1606 ANY_CPU, parent_pid);
41dc35d0 1607 TmfTimestamp eventTime = trcEvent.getTimestamp();
5d10d135 1608 process = create_process(traceSt, cpu, pid, tgid,
41dc35d0 1609 command, eventTime);
5d10d135 1610 if (parent_process != null) {
28b94d61 1611 process.setPpid(parent_process.getPid(), eventTime.getValue());
5d10d135
ASL
1612 }
1613
1614 /* Keep the stack bottom : a running user mode */
1615 /*
1616 * Disabled because of inconsistencies in the current
1617 * statedump states.
1618 */
1619 if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1620 .getInName())) {
1621 /*
1622 * FIXME Kernel thread : can be in syscall or
1623 * interrupt or trap.
1624 */
1625 /*
1626 * Will cause expected trap when in fact being
1627 * syscall (even after end of statedump event) Will
1628 * cause expected interrupt when being syscall.
1629 * (only before end of statedump event)
1630 */
63eecb47 1631 // process type is USER_THREAD by default.
5d10d135
ASL
1632 process
1633 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1634
1635 }
63eecb47
FC
1636
1637 //Only one entry needed in the execution stack
1638 process.popFromExecutionStack();
5d10d135
ASL
1639 es = process.getState();
1640 es.setExec_mode(ExecutionMode.LTTV_STATE_MODE_UNKNOWN);
1641 es.setProc_status(ProcessStatus.LTTV_STATE_UNNAMED);
1642 es
1643 .setExec_submode(ExecutionSubMode.LTTV_STATE_SUBMODE_UNKNOWN
1644 .getInName());
1645 // #if 0
1646 // /* UNKNOWN STATE */
1647 // {
1648 // es = process->state =
1649 // &g_array_index(process->execution_stack,
1650 // LttvExecutionState, 1);
1651 // es->t = LTTV_STATE_MODE_UNKNOWN;
1652 // es->s = LTTV_STATE_UNNAMED;
1653 // es->n = LTTV_STATE_SUBMODE_UNKNOWN;
1654 // }
1655 // #endif //0
1656 } else {
1657 /*
1658 * The process has already been created : Probably was
1659 * forked while dumping the process state or was simply
1660 * scheduled in prior to get the state dump event.
1661 */
1662 process.setPpid(parent_pid);
1663 process.setTgid(tgid);
1664 process.setName(command);
1665 if (type.equals(ProcessType.LTTV_STATE_KERNEL_THREAD
1666 .getInName())) {
1667 process
1668 .setType(ProcessType.LTTV_STATE_KERNEL_THREAD);
1669 } else {
1670 process.setType(ProcessType.LTTV_STATE_USER_THREAD);
1671 }
1672
1673 // es =
1674 // &g_array_index(process->execution_stack,
1675 // LttvExecutionState,
1676 // 0);
1677 // #if 0
1678 // if(es->t == LTTV_STATE_MODE_UNKNOWN) {
1679 // if(type == LTTV_STATE_KERNEL_THREAD)
1680 // es->t = LTTV_STATE_SYSCALL;
1681 // else
1682 // es->t = LTTV_STATE_USER_MODE;
1683 // }
1684 // #endif //0
1685 /*
1686 * Don't mess around with the stack, it will eventually
1687 * become ok after the end of state dump.
1688 */
1689 }
1690 }
1691
1692 return false;
1693
1694 }
88144d4a
ASL
1695
1696 // @Override
1697 public Events getEventHandleType() {
1698 return eventType;
1699 }
5d10d135
ASL
1700 };
1701 return handler;
1702 }
1703
1704}
This page took 0.099651 seconds and 5 git commands to generate.