analysis.os: bug 488757: Let the KernelTidAspect block if not queryable
[deliverable/tracecompass.git] / analysis / org.eclipse.tracecompass.analysis.os.linux.core / src / org / eclipse / tracecompass / analysis / os / linux / core / kernel / KernelTidAspect.java
1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 * Geneviève Bastien - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.analysis.os.linux.core.kernel;
14
15 import org.eclipse.core.runtime.IProgressMonitor;
16 import org.eclipse.core.runtime.NullProgressMonitor;
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.eclipse.tracecompass.analysis.os.linux.core.event.aspect.LinuxTidAspect;
20 import org.eclipse.tracecompass.analysis.os.linux.core.tid.TidAnalysisModule;
21 import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
22 import org.eclipse.tracecompass.tmf.core.event.aspect.TmfCpuAspect;
23 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceUtils;
24
25 /**
26 * This aspect finds the ID of the thread running from this event using the
27 * {@link KernelAnalysisModule}.
28 *
29 * @author Geneviève Bastien
30 * @since 2.0
31 */
32 public final class KernelTidAspect extends LinuxTidAspect {
33
34 /** The singleton instance */
35 public static final KernelTidAspect INSTANCE = new KernelTidAspect();
36
37 private static final IProgressMonitor NULL_MONITOR = new NullProgressMonitor();
38
39 private KernelTidAspect() {
40 }
41
42 @Override
43 public @Nullable Integer resolve(ITmfEvent event) {
44 try {
45 return resolve(event, false, NULL_MONITOR);
46 } catch (InterruptedException e) {
47 /* Should not happen since there is nothing to interrupt */
48 return null;
49 }
50 }
51
52 @Override
53 public @Nullable Integer resolve(@NonNull ITmfEvent event, boolean block, final IProgressMonitor monitor) throws InterruptedException {
54 /* Find the CPU this event is run on */
55 Integer cpu = TmfTraceUtils.resolveIntEventAspectOfClassForEvent(event.getTrace(),
56 TmfCpuAspect.class, event);
57 if (cpu == null) {
58 return null;
59 }
60
61 /* Find the analysis module for the trace */
62 TidAnalysisModule analysis = TmfTraceUtils.getAnalysisModuleOfClass(event.getTrace(),
63 TidAnalysisModule.class, TidAnalysisModule.ID);
64 if (analysis == null) {
65 return null;
66 }
67 long ts = event.getTimestamp().toNanos();
68 while (block && !analysis.isQueryable(ts) && !monitor.isCanceled()) {
69 Thread.sleep(100);
70 }
71 return analysis.getThreadOnCpuAtTime(cpu, ts);
72 }
73
74 }
This page took 0.03254 seconds and 5 git commands to generate.