Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 1aa1db80da9b9e26a3c5d743e12cef65a6a0b07f (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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
/*******************************************************************************
 * 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 org.eclipse.linuxtools.lttng.core.event.LttngEvent;
import org.eclipse.linuxtools.lttng.core.state.StateStrings.Channels;
import org.eclipse.linuxtools.lttng.core.state.StateStrings.Events;
import org.eclipse.linuxtools.lttng.core.state.StateStrings.Fields;
import org.eclipse.linuxtools.lttng.core.state.evProcessor.ILttngEventProcessor;
import org.eclipse.linuxtools.lttng.core.state.model.LttngTraceState;
import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource;
import org.eclipse.linuxtools.lttng.ui.model.trange.TimeRangeEventResource.ResourceTypes;
import org.eclipse.linuxtools.tmf.core.event.TmfTimeRange;

/**
 * Creates instances of specific before state update handlers, per corresponding
 * event.
 * 
 * @author alvaro
 * 
 */
public class ResourcesBeforeUpdateHandlers {

	/**
	 * <p>
	 * Handles: LTT_EVENT_SCHED_SCHEDULE
	 * </p>
	 * Replace C function named "before_schedchange_hook" in eventhooks.c
	 * <p>
	 * Fields: LTT_FIELD_PREV_PID, LTT_FIELD_NEXT_PID(?), LTT_FIELD_PREV_STATE
	 * (?)
	 * </p>
	 * 
	 * @return
	 */
	final ILttngEventProcessor getBeforeSchedChangeHandler() {
		AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {

			// @Override
			@Override
			public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
				// Create a time range for the cpu.
				globalProcessBeforeExecmode(trcEvent, traceSt);

				return false;
			}
		};

		return handler;
	}

	/**
	 * <p>
	 * Handles: LTT_EVENT_IRQ_ENTRY, LTT_EVENT_IRQ_EXIT
	 * </p>
	 * Replace C function named "before_execmode_hook_irq" in eventhooks.c
	 * 
	 * @return
	 */
	final ILttngEventProcessor getBeforeExecutionModeIrq() {
		AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {

			// @Override
			@Override
			public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {

				Long irqId = null;

				// According to Ltt, we should not draw anything if the channel
				// is the kernel one
				if (trcEvent.getChannelName().equals(
						Channels.LTT_CHANNEL_KERNEL.name())) {
					return false;
				} else {

					if (trcEvent.getMarkerName().equals(
							Events.LTT_EVENT_IRQ_ENTRY.getInName())) {
						irqId = getAFieldLong(trcEvent, traceSt,
								Fields.LTT_FIELD_IRQ_ID);
					} else if (trcEvent.getMarkerName().equals(
							Events.LTT_EVENT_IRQ_EXIT.getInName())) {
						long cpu = trcEvent.getCpuId();
						irqId = traceSt.getCpu_states().get(cpu)
								.peekFromIrqStack();
						if (irqId.equals(-1L)) {
							// nothing to update
							return false;
						}
					}


					// softIrqId is the resource id here
					TimeRangeEventResource localResource = resourcelist_obtain_irq(
							traceSt, irqId);

					// If the resource is missing in the list, add it
					if (localResource == null) {
						TmfTimeRange timeRange = traceSt.getContext()
								.getTraceTimeWindow();
						localResource = addLocalResource(timeRange
								.getStartTime().getValue(), timeRange
								.getEndTime().getValue(), traceSt.getTraceId(),
								ResourceTypes.IRQ, irqId, trcEvent
										.getTimestamp().getValue());
					}

					// get the start time
					long stime = localResource.getNext_good_time();

					// Get the resource state mode
					String irqStateMode = localResource.getStateMode(traceSt);

					// Call the makeDraw function
					makeDraw(traceSt, stime,
							trcEvent.getTimestamp().getValue(), localResource,
							params, irqStateMode);

					// Call the globalProcessBeforeExecmode() after, as
					// it is needed by all
					// getBeforeExecmode*SOMETHING*()
					globalProcessBeforeExecmode(trcEvent, traceSt);
				}
				return false;
			}
		};

		return handler;
	}

	/**
	 * <p>
	 * Handles: LTT_EVENT_SOFT_IRQ_RAISE, LTT_EVENT_SOFT_IRQ_ENTRY,
	 * LTT_EVENT_SOFT_IRQ_EXIT,
	 * </p>
	 * Replace C function named "before_execmode_hook_soft_irq" in eventhooks.c
	 * <p>
	 * Fields: LTT_FIELD_SOFT_IRQ_ID
	 * </p>
	 * 
	 * @return
	 */
	final ILttngEventProcessor getBeforeExecutionModeSoftIrq() {
		AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {

			// @Override
			@Override
			public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {

				Long softIrqId = null;

				// According to Ltt, we should not draw anything if the channel
				// is the kernel one
				if (trcEvent.getChannelName().equals(
						Channels.LTT_CHANNEL_KERNEL.name())) {
					return false;
				} else {

					if ((trcEvent.getMarkerName()
							.equals(Events.LTT_EVENT_SOFT_IRQ_RAISE.getInName()))
							|| (trcEvent.getMarkerName()
									.equals(Events.LTT_EVENT_SOFT_IRQ_ENTRY
											.getInName()))) {
						softIrqId = getAFieldLong(trcEvent, traceSt,
								Fields.LTT_FIELD_SOFT_IRQ_ID);
					} else if (trcEvent.getMarkerName().equals(
							Events.LTT_EVENT_SOFT_IRQ_EXIT.getInName())) {
						long cpu = trcEvent.getCpuId();
						softIrqId = traceSt.getCpu_states().get(cpu)
								.peekFromSoftIrqStack();
						if (softIrqId < 0) {
							// nothing to update
							return false;
						}
					}

					// Add the resource to the resource list
					// softIrqId is the resource id here
					TimeRangeEventResource localResource = resourcelist_obtain_soft_irq(
							traceSt, softIrqId);

					// If the resource is missing in the list, add it
					if (localResource == null) {
						TmfTimeRange timeRange = traceSt.getContext()
								.getTraceTimeWindow();
						localResource = addLocalResource(timeRange
								.getStartTime().getValue(), timeRange
								.getEndTime().getValue(), traceSt.getTraceId(),
								ResourceTypes.SOFT_IRQ, softIrqId, trcEvent
										.getTimestamp().getValue());
					}

					// get the start time
					long stime = localResource.getNext_good_time();

					// Get the resource state mode
					String softIrqStateMode = localResource
							.getStateMode(traceSt);

					// Call the makeDraw function
					makeDraw(traceSt, stime,
							trcEvent.getTimestamp().getValue(), localResource,
							params, softIrqStateMode);

					// Call the globalProcessBeforeExecmode() after, as
					// it is needed by all
					// getBeforeExecmode*SOMETHING*()
					globalProcessBeforeExecmode(trcEvent, traceSt);

				}

				return false;
			}
		};

		return handler;
	}

	/**
	 * <p>
	 * Handles: LTT_EVENT_TRAP_ENTRY, LTT_EVENT_TRAP_EXIT,
	 * LTT_EVENT_PAGE_FAULT_ENTRY, LTT_EVENT_PAGE_FAULT_EXIT,
	 * LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY, LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
	 * </p>
	 * Replace C function named "before_execmode_hook_trap" in eventhooks.c
	 * <p>
	 * Fields: LTT_FIELD_TRAP_ID
	 * </p>
	 * 
	 * @return
	 */
	final ILttngEventProcessor getBeforeExecutionModeTrap() {
		AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {

			// @Override
			@Override
			public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {

				Long trapId = null;

				// According to Ltt, we should not draw anything if the channel
				// is the kernel one
				if (trcEvent.getChannelName().equals(
						Channels.LTT_CHANNEL_KERNEL.name())) {
					return false;
				} else {

					if ((trcEvent.getMarkerName()
							.equals(Events.LTT_EVENT_TRAP_ENTRY.getInName()))
							|| (trcEvent.getMarkerName()
									.equals(Events.LTT_EVENT_PAGE_FAULT_ENTRY
											.getInName()))
							|| (trcEvent.getMarkerName()
									.equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_ENTRY
											.getInName()))) {
						trapId = getAFieldLong(trcEvent, traceSt,
								Fields.LTT_FIELD_TRAP_ID);
					} else if ((trcEvent.getMarkerName()
							.equals(Events.LTT_EVENT_TRAP_EXIT.getInName()))
							|| (trcEvent.getMarkerName()
									.equals(Events.LTT_EVENT_PAGE_FAULT_EXIT
											.getInName()))
							|| (trcEvent.getMarkerName()
									.equals(Events.LTT_EVENT_PAGE_FAULT_NOSEM_EXIT
											.getInName()))) {
						long cpu = trcEvent.getCpuId();
						trapId = traceSt.getCpu_states().get(cpu)
								.peekFromTrapStack();

						if (trapId.equals(-1L)) {
							// Nothing to update
							return false;
						}
					} else {
						return false;
					}

					// Add the resource to the resource list
					// trapId is the resource id here
					TimeRangeEventResource localResource = resourcelist_obtain_trap(
							traceSt, trapId);

					// If the resource is missing in the list, add it
					if (localResource == null) {
						TmfTimeRange timeRange = traceSt.getContext()
								.getTraceTimeWindow();
						localResource = addLocalResource(timeRange
								.getStartTime().getValue(), timeRange
								.getEndTime().getValue(), traceSt.getTraceId(),
								ResourceTypes.TRAP, trapId, trcEvent
										.getTimestamp().getValue());
					}

					// Determine the trap state.
					String trapStateMode = localResource.getStateMode(traceSt);

					long stime = localResource.getNext_good_time();
					makeDraw(traceSt, stime,
							trcEvent.getTimestamp().getValue(), localResource,
							params, trapStateMode);

					// Call the globalProcessBeforeExecmode() after, as
					// it is needed by all
					// getBeforeExecmode*SOMETHING*()
					globalProcessBeforeExecmode(trcEvent, traceSt);

				}

				return false;
			}
		};

		return handler;
	}

	/**
	 * <p>
	 * Handles: LTT_EVENT_REQUEST_ISSUE, LTT_EVENT_REQUEST_COMPLETE
	 * </p>
	 * Replace C function named "before_bdev_event_hook" in eventhooks.c
	 * <p>
	 * Fields: LTT_FIELD_MAJOR, LTT_FIELD_MINOR, LTT_FIELD_OPERATION (?)
	 * </p>
	 * 
	 * @return
	 */
	final ILttngEventProcessor getBeforeBdevEvent() {
		AbsResourcesTRangeUpdate handler = new AbsResourcesTRangeUpdate() {

			// @Override
			@Override
			public boolean process(LttngEvent trcEvent, LttngTraceState traceSt) {
				Long major = getAFieldLong(trcEvent, traceSt,
						Fields.LTT_FIELD_MAJOR);
				Long minor = getAFieldLong(trcEvent, traceSt,
						Fields.LTT_FIELD_MINOR);
				// This is useless even in LTTv!
				// Long oper = getAFieldLong(trcEvent, traceSt,
				// Fields.LTT_FIELD_OPERATION);

				Long bdevId = getMkdevId(major, minor);

				// According to Lttv, bdevId (obtain from MKDEV macro) is
				// the id here
				TimeRangeEventResource localResource = resourcelist_obtain_bdev(
						traceSt, bdevId);

				if (localResource == null) {
					TmfTimeRange timeRange = traceSt.getContext()
							.getTraceTimeWindow();
					localResource = addLocalResource(timeRange.getStartTime()
							.getValue(), timeRange.getEndTime().getValue(),
							traceSt.getTraceId(), ResourceTypes.BDEV, bdevId,
							trcEvent.getTimestamp().getValue());
				}

				// get the start time
				long stime = localResource.getNext_good_time();
				// Get the resource state mode
				String bdevStateMode = localResource.getStateMode(traceSt);
				// Call the makeDraw function
				makeDraw(traceSt, stime, trcEvent.getTimestamp().getValue(),
						localResource, params, bdevStateMode);

				return false;
			}
		};

		return handler;
	}
}

Back to the top