tmf: Use tabs in statistics view for each traces
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng.core / src / org / eclipse / linuxtools / internal / lttng / core / state / evProcessor / AbsEventToHandlerResolver.java
1 /*******************************************************************************
2 * Copyright (c) 2009, 2010 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@ail.com) - Initial API and implementation
11 * Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
12 *******************************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng.core.state.evProcessor;
15
16 import java.util.Set;
17
18 import org.eclipse.linuxtools.internal.lttng.core.TraceDebug;
19 import org.eclipse.linuxtools.internal.lttng.core.event.LttngEvent;
20 import org.eclipse.linuxtools.internal.lttng.core.event.LttngSyntheticEvent;
21 import org.eclipse.linuxtools.internal.lttng.core.state.model.LttngTraceState;
22 import org.eclipse.linuxtools.tmf.core.event.ITmfEvent;
23
24 /**
25 * @author alvaro
26 *
27 */
28 public abstract class AbsEventToHandlerResolver implements
29 IEventToHandlerResolver, ITransEventProcessor {
30
31 Long fbeforeEventCount = 0L;
32 Long fstateUpdateCount = 0L;
33 Long filteredOutEventsCount = 0L;
34
35 /* (non-Javadoc)
36 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getBeforeProcessor(java.lang.String)
37 */
38 @Override
39 public abstract ILttngEventProcessor getBeforeProcessor(String eventType);
40
41 /* (non-Javadoc)
42 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getAfterProcessor(java.lang.String)
43 */
44 @Override
45 public abstract ILttngEventProcessor getAfterProcessor(String eventType);
46
47 /* (non-Javadoc)
48 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getfinishProcessor()
49 */
50 @Override
51 public abstract ILttngEventProcessor getfinishProcessor();
52
53 /* (non-Javadoc)
54 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IEventToHandlerResolver#getStateUpdaterProcessor(java.lang.String)
55 */
56 @Override
57 public abstract ILttngEventProcessor getStateUpdaterProcessor(
58 String eventType);
59
60 /* (non-Javadoc)
61 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ILttngEventProcessor#process(org.eclipse.linuxtools.lttng.event.LttngEvent, org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
62 */
63 @Override
64 public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
65 if (trcEvent instanceof LttngSyntheticEvent) {
66
67 // prepare to dispatch synthetic events to its corresponding handler
68 LttngSyntheticEvent synEvent = (LttngSyntheticEvent) trcEvent;
69 ILttngEventProcessor processor = null;
70 String eventType = synEvent.getMarkerName();
71
72 switch (synEvent.getSynType()) {
73 case STARTREQ: {
74 // Status indicators do not contain a valid marker name
75 reset();
76 return false;
77 }
78
79 case BEFORE: {
80 processor = getBeforeProcessor(eventType);
81 // increment event count only for one sequence indicator,
82 // Note: BEFORE is selected to be used as an indicator to
83 // prevent duplicated updates in the state system
84 incrementBeforeEventCount();
85 break;
86 }
87
88 case UPDATE: {
89 processor = getStateUpdaterProcessor(eventType);
90 incrementStateUpdateCount();
91 break;
92 }
93
94 case AFTER: {
95 processor = getAfterProcessor(eventType);
96 break;
97 }
98
99 case ENDREQ: {
100 processor = getfinishProcessor();
101 TraceDebug.debug("EndRequest satus received:"); //$NON-NLS-1$
102 break;
103 }
104
105 default:
106 // Nothing to do
107 break;
108
109 }
110
111 // For BEFORE/UPDATE/AFTER
112 // TODO: Implement filter of events not associated to this trace
113 // Make sure the event received is associated to this trace
114 // handling context, Implementing a trace compare for each event
115 // is not acceptable due to performance, and a reference check
116 // may not be feasible since there are trace clones used either
117 // to build the state system check points or UI requests.
118
119 // if (traceSt != null && trcEvent.getParentTrace() !=
120 // traceSt.getContext().getTraceIdRef()) {
121 // // increment the number of events filtered out
122 // filteredOutEventsCount++;
123 // return false;
124 // }
125
126 if (processor != null) {
127 processor.process(trcEvent, traceSt);
128 }
129 }
130
131 return true;
132 }
133
134 /*
135 * (non-Javadoc)
136 *
137 * @see
138 * org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#process
139 * (org.eclipse.linuxtools.tmf.event.TmfEvent,
140 * org.eclipse.linuxtools.lttng.state.model.LttngTraceState)
141 */
142 @Override
143 public void process(ITmfEvent tmfEvent, LttngTraceState traceSt) {
144 if (tmfEvent == null) {
145 return;
146 }
147
148 if (!(tmfEvent instanceof LttngSyntheticEvent)) {
149 TraceDebug
150 .debug("The event received is not an instance of LttngSyntheticEvent and can not be processed"); //$NON-NLS-1$
151 return;
152 }
153
154 LttngSyntheticEvent trcEvent = (LttngSyntheticEvent) tmfEvent;
155
156 process(trcEvent, traceSt);
157 }
158
159 /*
160 * (non-Javadoc)
161 *
162 * @see org.eclipse.linuxtools.lttng.state.evProcessor.IBaseEventProcessor#
163 * getEventsNotHandled()
164 */
165 public Set<String> getEventsNotHandled() {
166 return null;
167 }
168
169 /*
170 * (non-Javadoc)
171 *
172 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
173 * getEventCount()
174 */
175 @Override
176 public Long getBeforeEventCount() {
177 return fbeforeEventCount;
178 }
179
180 /*
181 * (non-Javadoc)
182 *
183 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
184 * getStateUpdateCount()
185 */
186 @Override
187 public Long getStateUpdateCount() {
188 return fstateUpdateCount;
189 }
190
191 /*
192 * (non-Javadoc)
193 *
194 * @see org.eclipse.linuxtools.lttng.state.evProcessor.ITransEventProcessor#
195 * getFilteredOutEventCount()
196 */
197 @Override
198 public Long getFilteredOutEventCount() {
199 return filteredOutEventsCount;
200 }
201
202 /**
203 * <p>
204 * Initialise counter values, e.g before new requests
205 * </p>
206 */
207 protected void reset() {
208 fbeforeEventCount = 0L;
209 fstateUpdateCount = 0L;
210 filteredOutEventsCount = 0L;
211 }
212
213 /**
214 * Multi-threading not expected
215 */
216 protected void incrementBeforeEventCount() {
217 fbeforeEventCount++;
218 }
219
220 /**
221 * Multi-threading not expected
222 */
223 protected void incrementStateUpdateCount() {
224 fstateUpdateCount++;
225 }
226 }
This page took 0.037936 seconds and 5 git commands to generate.