Commit | Line | Data |
---|---|---|
6e512b93 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 | *******************************************************************************/ | |
12 | package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor; | |
13 | ||
14 | import java.util.HashMap; | |
15 | import java.util.Map; | |
16 | ||
17 | import org.eclipse.linuxtools.lttng.event.LttngEvent; | |
18 | import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent; | |
19 | import org.eclipse.linuxtools.lttng.event.LttngSyntheticEvent.SequenceInd; | |
20 | import org.eclipse.linuxtools.lttng.state.StateStrings; | |
21 | import org.eclipse.linuxtools.lttng.state.evProcessor.AbsEventToHandlerResolver; | |
22 | import org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor; | |
23 | import org.eclipse.linuxtools.lttng.state.model.LttngTraceState; | |
24 | ||
25 | /** | |
26 | * Builds a Map from string event name to a processing handler object, the | |
27 | * processors implement the same interface to facilitate transparent methods | |
28 | * call, | |
29 | * | |
30 | * The map key String is the entry point of the raw events. Using a hash speeds | |
31 | * up the resolution of the appropriate processor | |
32 | * | |
33 | * @author alvaro | |
34 | * | |
35 | */ | |
36 | public class ResourcesEventToHandlerFactory extends AbsEventToHandlerResolver { | |
37 | // ======================================================================== | |
38 | // Data | |
39 | // ======================================================================= | |
40 | private final Map<String, ILttngEventProcessor> eventNametoBeforeProcessor = new HashMap<String, ILttngEventProcessor>(); | |
41 | private final Map<String, ILttngEventProcessor> eventNametoAfterProcessor = new HashMap<String, ILttngEventProcessor>(); | |
42 | private ResourcesFinishUpdateHandler finishProcessor = null; | |
43 | private static ResourcesEventToHandlerFactory instance = null; | |
44 | private ResourcesBeforeUpdateHandlers instantiateBeforeHandler = new ResourcesBeforeUpdateHandlers(); | |
45 | private ResourcesAfterUpdateHandlers instantiateAfterHandler = new ResourcesAfterUpdateHandlers(); | |
46 | ||
47 | private ResourcesEventToHandlerFactory() { | |
48 | super(); | |
49 | // Create one instance of each individual event handler and add the | |
50 | // instance to the map | |
51 | ||
52 | // *** BEFORE HOOKS *** | |
53 | eventNametoBeforeProcessor.put( | |
54 | StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(), | |
55 | instantiateBeforeHandler.getBeforeSchedChangeHandler()); | |
56 | ||
57 | eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_ENTRY | |
58 | .getInName(), instantiateBeforeHandler | |
59 | .getBeforeExecutionModeTrap()); | |
60 | eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_EXIT | |
61 | .getInName(), instantiateBeforeHandler | |
62 | .getBeforeExecutionModeTrap()); | |
63 | eventNametoBeforeProcessor.put( | |
64 | StateStrings.Events.LTT_EVENT_PAGE_FAULT_ENTRY.getInName(), | |
65 | instantiateBeforeHandler.getBeforeExecutionModeTrap()); | |
66 | eventNametoBeforeProcessor.put( | |
67 | StateStrings.Events.LTT_EVENT_PAGE_FAULT_EXIT.getInName(), | |
68 | instantiateBeforeHandler.getBeforeExecutionModeTrap()); | |
69 | eventNametoBeforeProcessor.put( | |
70 | StateStrings.Events.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY | |
71 | .getInName(), instantiateBeforeHandler | |
72 | .getBeforeExecutionModeTrap()); | |
73 | eventNametoBeforeProcessor | |
74 | .put(StateStrings.Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT | |
75 | .getInName(), instantiateBeforeHandler | |
76 | .getBeforeExecutionModeTrap()); | |
77 | ||
78 | eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_ENTRY | |
79 | .getInName(), instantiateBeforeHandler | |
80 | .getBeforeExecutionModeIrq()); | |
81 | eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_EXIT | |
82 | .getInName(), instantiateBeforeHandler | |
83 | .getBeforeExecutionModeIrq()); | |
84 | ||
85 | eventNametoBeforeProcessor.put( | |
86 | StateStrings.Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName(), | |
87 | instantiateBeforeHandler.getBeforeExecutionModeSoftIrq()); | |
88 | eventNametoBeforeProcessor.put( | |
89 | StateStrings.Events.LTT_EVENT_SOFT_IRQ_ENTRY.getInName(), | |
90 | instantiateBeforeHandler.getBeforeExecutionModeSoftIrq()); | |
91 | eventNametoBeforeProcessor.put( | |
92 | StateStrings.Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName(), | |
93 | instantiateBeforeHandler.getBeforeExecutionModeSoftIrq()); | |
94 | ||
95 | eventNametoBeforeProcessor.put( | |
96 | StateStrings.Events.LTT_EVENT_REQUEST_ISSUE.getInName(), | |
97 | instantiateBeforeHandler.getBeforeBdevEvent()); | |
98 | eventNametoBeforeProcessor.put( | |
99 | StateStrings.Events.LTT_EVENT_REQUEST_COMPLETE.getInName(), | |
100 | instantiateBeforeHandler.getBeforeBdevEvent()); | |
101 | ||
102 | // *** AFTER HOOKS *** | |
103 | eventNametoAfterProcessor.put( | |
104 | StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(), | |
105 | instantiateAfterHandler.getAfterSchedChangeHandler()); | |
106 | ||
107 | finishProcessor = new ResourcesFinishUpdateHandler(); | |
108 | } | |
109 | ||
110 | /** | |
111 | * | |
112 | */ | |
113 | public static AbsEventToHandlerResolver getInstance() { | |
114 | if (instance == null) { | |
115 | instance = new ResourcesEventToHandlerFactory(); | |
116 | } | |
117 | return instance; | |
118 | } | |
119 | ||
120 | @Override | |
121 | public ILttngEventProcessor getAfterProcessor(String eventType) { | |
122 | return eventNametoAfterProcessor.get(eventType); | |
123 | } | |
124 | ||
125 | @Override | |
126 | public ILttngEventProcessor getBeforeProcessor(String eventType) { | |
127 | return eventNametoBeforeProcessor.get(eventType); | |
128 | } | |
129 | ||
130 | @Override | |
131 | public ILttngEventProcessor getfinishProcessor() { | |
132 | return finishProcessor; | |
133 | } | |
134 | ||
9aae0442 | 135 | @Override |
6e512b93 ASL |
136 | public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) { |
137 | if (trcEvent instanceof LttngSyntheticEvent) { | |
138 | ||
139 | LttngSyntheticEvent synEvent = (LttngSyntheticEvent) trcEvent; | |
140 | String eventType = synEvent.getMarkerName(); | |
141 | ILttngEventProcessor processor = null; | |
142 | if (synEvent.getSynType() == SequenceInd.BEFORE) { | |
143 | processor = getBeforeProcessor(eventType); | |
144 | } | |
145 | ||
146 | if (synEvent.getSynType() == SequenceInd.AFTER) { | |
147 | processor = getAfterProcessor(eventType); | |
148 | } | |
149 | ||
150 | if (synEvent.getSynType() == SequenceInd.ENDREQ) { | |
151 | processor = getfinishProcessor(); | |
152 | } | |
153 | ||
154 | if (processor != null) { | |
155 | processor.process(trcEvent, traceSt); | |
156 | } | |
157 | } | |
158 | return false; | |
159 | } | |
160 | ||
161 | @Override | |
162 | public ILttngEventProcessor getStateUpdaterProcessor(String eventType) { | |
163 | return null; | |
164 | } | |
165 | } |