1 /*******************************************************************************
2 * Copyright (c) 2009 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng
.ui
.views
.resources
.evProcessor
;
15 import java
.util
.HashMap
;
18 import org
.eclipse
.linuxtools
.lttng
.event
.LttngEvent
;
19 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
;
20 import org
.eclipse
.linuxtools
.lttng
.event
.LttngSyntheticEvent
.SequenceInd
;
21 import org
.eclipse
.linuxtools
.lttng
.state
.StateStrings
;
22 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.AbsEventToHandlerResolver
;
23 import org
.eclipse
.linuxtools
.lttng
.state
.evProcessor
.ILttngEventProcessor
;
24 import org
.eclipse
.linuxtools
.lttng
.state
.model
.LttngTraceState
;
27 * Builds a Map from string event name to a processing handler object, the
28 * processors implement the same interface to facilitate transparent methods
31 * The map key String is the entry point of the raw events. Using a hash speeds
32 * up the resolution of the appropriate processor
37 public class ResourcesEventToHandlerFactory
extends AbsEventToHandlerResolver
{
38 // ========================================================================
40 // =======================================================================
41 private final Map
<String
, ILttngEventProcessor
> eventNametoBeforeProcessor
= new HashMap
<String
, ILttngEventProcessor
>();
42 private final Map
<String
, ILttngEventProcessor
> eventNametoAfterProcessor
= new HashMap
<String
, ILttngEventProcessor
>();
43 private ResourcesFinishUpdateHandler finishProcessor
= null;
44 private static ResourcesEventToHandlerFactory instance
= null;
45 private ResourcesBeforeUpdateHandlers instantiateBeforeHandler
= new ResourcesBeforeUpdateHandlers();
46 private ResourcesAfterUpdateHandlers instantiateAfterHandler
= new ResourcesAfterUpdateHandlers();
48 private ResourcesEventToHandlerFactory() {
50 // Create one instance of each individual event handler and add the
51 // instance to the map
53 // *** BEFORE HOOKS ***
54 eventNametoBeforeProcessor
.put(
55 StateStrings
.Events
.LTT_EVENT_SCHED_SCHEDULE
.getInName(),
56 instantiateBeforeHandler
.getBeforeSchedChangeHandler());
58 eventNametoBeforeProcessor
.put(StateStrings
.Events
.LTT_EVENT_TRAP_ENTRY
59 .getInName(), instantiateBeforeHandler
60 .getBeforeExecutionModeTrap());
61 eventNametoBeforeProcessor
.put(StateStrings
.Events
.LTT_EVENT_TRAP_EXIT
62 .getInName(), instantiateBeforeHandler
63 .getBeforeExecutionModeTrap());
64 eventNametoBeforeProcessor
.put(
65 StateStrings
.Events
.LTT_EVENT_PAGE_FAULT_ENTRY
.getInName(),
66 instantiateBeforeHandler
.getBeforeExecutionModeTrap());
67 eventNametoBeforeProcessor
.put(
68 StateStrings
.Events
.LTT_EVENT_PAGE_FAULT_EXIT
.getInName(),
69 instantiateBeforeHandler
.getBeforeExecutionModeTrap());
70 eventNametoBeforeProcessor
.put(
71 StateStrings
.Events
.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
72 .getInName(), instantiateBeforeHandler
73 .getBeforeExecutionModeTrap());
74 eventNametoBeforeProcessor
75 .put(StateStrings
.Events
.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
76 .getInName(), instantiateBeforeHandler
77 .getBeforeExecutionModeTrap());
79 eventNametoBeforeProcessor
.put(StateStrings
.Events
.LTT_EVENT_IRQ_ENTRY
80 .getInName(), instantiateBeforeHandler
81 .getBeforeExecutionModeIrq());
82 eventNametoBeforeProcessor
.put(StateStrings
.Events
.LTT_EVENT_IRQ_EXIT
83 .getInName(), instantiateBeforeHandler
84 .getBeforeExecutionModeIrq());
86 eventNametoBeforeProcessor
.put(
87 StateStrings
.Events
.LTT_EVENT_SOFT_IRQ_RAISE
.getInName(),
88 instantiateBeforeHandler
.getBeforeExecutionModeSoftIrq());
89 eventNametoBeforeProcessor
.put(
90 StateStrings
.Events
.LTT_EVENT_SOFT_IRQ_ENTRY
.getInName(),
91 instantiateBeforeHandler
.getBeforeExecutionModeSoftIrq());
92 eventNametoBeforeProcessor
.put(
93 StateStrings
.Events
.LTT_EVENT_SOFT_IRQ_EXIT
.getInName(),
94 instantiateBeforeHandler
.getBeforeExecutionModeSoftIrq());
96 eventNametoBeforeProcessor
.put(
97 StateStrings
.Events
.LTT_EVENT_REQUEST_ISSUE
.getInName(),
98 instantiateBeforeHandler
.getBeforeBdevEvent());
99 eventNametoBeforeProcessor
.put(
100 StateStrings
.Events
.LTT_EVENT_REQUEST_COMPLETE
.getInName(),
101 instantiateBeforeHandler
.getBeforeBdevEvent());
103 // *** AFTER HOOKS ***
104 eventNametoAfterProcessor
.put(
105 StateStrings
.Events
.LTT_EVENT_SCHED_SCHEDULE
.getInName(),
106 instantiateAfterHandler
.getAfterSchedChangeHandler());
108 finishProcessor
= new ResourcesFinishUpdateHandler();
114 public static AbsEventToHandlerResolver
getInstance() {
115 if (instance
== null) {
116 instance
= new ResourcesEventToHandlerFactory();
122 public ILttngEventProcessor
getAfterProcessor(String eventType
) {
123 return eventNametoAfterProcessor
.get(eventType
);
127 public ILttngEventProcessor
getBeforeProcessor(String eventType
) {
128 return eventNametoBeforeProcessor
.get(eventType
);
132 public ILttngEventProcessor
getfinishProcessor() {
133 return finishProcessor
;
137 public boolean process(LttngEvent trcEvent
, LttngTraceState traceSt
) {
138 if (trcEvent
instanceof LttngSyntheticEvent
) {
140 LttngSyntheticEvent synEvent
= (LttngSyntheticEvent
) trcEvent
;
141 String eventType
= synEvent
.getMarkerName();
142 ILttngEventProcessor processor
= null;
143 if (synEvent
.getSynType() == SequenceInd
.BEFORE
) {
144 processor
= getBeforeProcessor(eventType
);
147 if (synEvent
.getSynType() == SequenceInd
.AFTER
) {
148 processor
= getAfterProcessor(eventType
);
151 if (synEvent
.getSynType() == SequenceInd
.ENDREQ
) {
152 processor
= getfinishProcessor();
155 if (processor
!= null) {
156 processor
.process(trcEvent
, traceSt
);
163 public ILttngEventProcessor
getStateUpdaterProcessor(String eventType
) {