Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2a068d81425641fcc38fb448149be5c17ca3dfff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*******************************************************************************
 * Copyright (c) 2009 Ericsson
 * 
 * All rights reserved. This program and the accompanying materials are
 * made available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *   Alvaro Sanchez-Leon (alvsan09@gmail.com) - Initial API and implementation
 * 	 Michel Dagenais (michel.dagenais@polymtl.ca) - Reference C implementation, used with permission
 *******************************************************************************/
package org.eclipse.linuxtools.lttng.ui.views.resources.evProcessor;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.linuxtools.lttng.core.event.LttngEvent;
import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent;
import org.eclipse.linuxtools.lttng.core.event.LttngSyntheticEvent.SequenceInd;
import org.eclipse.linuxtools.lttng.core.state.StateStrings;
import org.eclipse.linuxtools.lttng.core.state.evProcessor.AbsEventToHandlerResolver;
import org.eclipse.linuxtools.lttng.core.state.evProcessor.ILttngEventProcessor;
import org.eclipse.linuxtools.lttng.core.state.model.LttngTraceState;

/**
 * Builds a Map from string event name to a processing handler object, the
 * processors implement the same interface to facilitate transparent methods
 * call,
 * 
 * The map key String is the entry point of the raw events. Using a hash speeds
 * up the resolution of the appropriate processor
 * 
 * @author alvaro
 * 
 */
public class ResourcesEventToHandlerFactory extends AbsEventToHandlerResolver {
	// ========================================================================
	// Data
	// =======================================================================
	private final Map<String, ILttngEventProcessor> eventNametoBeforeProcessor = new HashMap<String, ILttngEventProcessor>();
	private final Map<String, ILttngEventProcessor> eventNametoAfterProcessor = new HashMap<String, ILttngEventProcessor>();
	private ResourcesFinishUpdateHandler finishProcessor = null;
	private static ResourcesEventToHandlerFactory instance = null;
	private ResourcesBeforeUpdateHandlers instantiateBeforeHandler = new ResourcesBeforeUpdateHandlers();
	private ResourcesAfterUpdateHandlers instantiateAfterHandler = new ResourcesAfterUpdateHandlers();

	private ResourcesEventToHandlerFactory() {
		super();
		// Create one instance of each individual event handler and add the
		// instance to the map

		// *** BEFORE HOOKS ***
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(),
				instantiateBeforeHandler.getBeforeSchedChangeHandler());

		eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_ENTRY
				.getInName(), instantiateBeforeHandler
				.getBeforeExecutionModeTrap());
		eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_TRAP_EXIT
				.getInName(), instantiateBeforeHandler
				.getBeforeExecutionModeTrap());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_PAGE_FAULT_ENTRY.getInName(),
				instantiateBeforeHandler.getBeforeExecutionModeTrap());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_PAGE_FAULT_EXIT.getInName(),
				instantiateBeforeHandler.getBeforeExecutionModeTrap());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
						.getInName(), instantiateBeforeHandler
						.getBeforeExecutionModeTrap());
		eventNametoBeforeProcessor
				.put(StateStrings.Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
						.getInName(), instantiateBeforeHandler
						.getBeforeExecutionModeTrap());

		eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_ENTRY
				.getInName(), instantiateBeforeHandler
				.getBeforeExecutionModeIrq());
		eventNametoBeforeProcessor.put(StateStrings.Events.LTT_EVENT_IRQ_EXIT
				.getInName(), instantiateBeforeHandler
				.getBeforeExecutionModeIrq());

		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName(),
				instantiateBeforeHandler.getBeforeExecutionModeSoftIrq());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_SOFT_IRQ_ENTRY.getInName(),
				instantiateBeforeHandler.getBeforeExecutionModeSoftIrq());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName(),
				instantiateBeforeHandler.getBeforeExecutionModeSoftIrq());

		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_REQUEST_ISSUE.getInName(),
				instantiateBeforeHandler.getBeforeBdevEvent());
		eventNametoBeforeProcessor.put(
				StateStrings.Events.LTT_EVENT_REQUEST_COMPLETE.getInName(),
				instantiateBeforeHandler.getBeforeBdevEvent());

		// *** AFTER HOOKS ***
		eventNametoAfterProcessor.put(
				StateStrings.Events.LTT_EVENT_SCHED_SCHEDULE.getInName(),
				instantiateAfterHandler.getAfterSchedChangeHandler());

		finishProcessor = new ResourcesFinishUpdateHandler();
	}

	/**
     * 
     */
	public static AbsEventToHandlerResolver getInstance() {
		if (instance == null) {
			instance = new ResourcesEventToHandlerFactory();
		}
		return instance;
	}

	@Override
	public ILttngEventProcessor getAfterProcessor(String eventType) {
		return eventNametoAfterProcessor.get(eventType);
	}

	@Override
	public ILttngEventProcessor getBeforeProcessor(String eventType) {
		return eventNametoBeforeProcessor.get(eventType);
	}

	@Override
	public ILttngEventProcessor getfinishProcessor() {
		return finishProcessor;
	}

	@Override
	public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
		if (trcEvent instanceof LttngSyntheticEvent) {

			LttngSyntheticEvent synEvent = (LttngSyntheticEvent) trcEvent;
			String eventType = synEvent.getMarkerName();
			ILttngEventProcessor processor = null;
			if (synEvent.getSynType() == SequenceInd.BEFORE) {
				processor = getBeforeProcessor(eventType);
			}

			if (synEvent.getSynType() == SequenceInd.AFTER) {
				processor = getAfterProcessor(eventType);
			}

			if (synEvent.getSynType() == SequenceInd.ENDREQ) {
				processor = getfinishProcessor();
			}

			if (processor != null) {
				processor.process(trcEvent, traceSt);
			}
		}
		return false;
	}

	@Override
	public ILttngEventProcessor getStateUpdaterProcessor(String eventType) {
		return null;
	}
}

Back to the top