analysis: support sched_waking event
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.core / src / org / eclipse / tracecompass / internal / lttng2 / kernel / core / analysis / graph / building / LttngKernelExecGraphProvider.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
10 package org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.building;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.Set;
15
16 import org.eclipse.tracecompass.analysis.graph.core.base.IGraphWorker;
17 import org.eclipse.tracecompass.analysis.graph.core.base.TmfEdge;
18 import org.eclipse.tracecompass.analysis.graph.core.base.TmfGraph;
19 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex;
20 import org.eclipse.tracecompass.analysis.graph.core.base.TmfVertex.EdgeDirection;
21 import org.eclipse.tracecompass.analysis.graph.core.building.AbstractTmfGraphProvider;
22 import org.eclipse.tracecompass.analysis.os.linux.core.trace.IKernelAnalysisEventLayout;
23 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.handlers.EventContextHandler;
24 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.handlers.TraceEventHandlerExecutionGraph;
25 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.handlers.TraceEventHandlerSched;
26 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.handlers.TraceEventHandlerStatedump;
27 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model.LttngSystemModel;
28 import org.eclipse.tracecompass.internal.lttng2.kernel.core.analysis.graph.model.LttngWorker;
29 import org.eclipse.tracecompass.internal.lttng2.kernel.core.trace.layout.LttngEventLayout;
30 import org.eclipse.tracecompass.lttng2.kernel.core.trace.LttngKernelTrace;
31 import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32
33 /**
34 * The graph provider builds an execution graph from a kernel trace. The
35 * execution graph is a 2d-mesh model of the system, where vertices represent
36 * events, horizontal edges represent states of tasks, and where vertical edges
37 * represent relations between tasks (currently local wake-up and pairs of
38 * network packets).
39 *
40 * Event handling is split into smaller sub-handlers. One event request is done,
41 * and each event is passed to the handlers in the order in the list, such as
42 * this pseudo code:
43 *
44 * <pre>
45 * for each event:
46 * for each handler:
47 * handler.handleEvent(event)
48 * </pre>
49 *
50 * @author Geneviève Bastien
51 * @author Francis Giraldeau
52 */
53 public class LttngKernelExecGraphProvider extends AbstractTmfGraphProvider {
54
55 private final LttngSystemModel fSystem;
56
57 /**
58 * Represents an interrupt context
59 */
60 public enum Context {
61 /** Not in an interrupt */
62 NONE,
63 /** The interrupt is a soft IRQ */
64 SOFTIRQ,
65 /** The interrupt is an IRQ */
66 IRQ,
67 /** The interrupt is a timer */
68 HRTIMER,
69 /** The inter-processor interrupt */
70 IPI,
71 }
72
73 /**
74 * A list of status a thread can be in
75 */
76 public enum ProcessStatus {
77 /** Unknown process status */
78 UNKNOWN(0),
79 /** Waiting for a fork */
80 WAIT_FORK(1),
81 /** Waiting for the CPU */
82 WAIT_CPU(2),
83 /** The thread has exited, but is not dead yet */
84 EXIT(3),
85 /** The thread is a zombie thread */
86 ZOMBIE(4),
87 /** The thread is blocked */
88 WAIT_BLOCKED(5),
89 /** The thread is running */
90 RUN(6),
91 /** The thread is dead */
92 DEAD(7);
93 private final int fValue;
94
95 private ProcessStatus(int value) {
96 fValue = value;
97 }
98
99 private int value() {
100 return fValue;
101 }
102
103 /**
104 * Get the ProcessStatus associated with a long value
105 *
106 * @param val
107 * The long value corresponding to a status
108 * @return The {@link ProcessStatus} enum value
109 */
110 static public ProcessStatus getStatus(long val) {
111 for (ProcessStatus e : ProcessStatus.values()) {
112 if (e.value() == val) {
113 return e;
114 }
115 }
116 return UNKNOWN;
117 }
118 }
119
120 /**
121 * Constructor
122 *
123 * @param trace
124 * The trace on which to build graph
125 */
126 public LttngKernelExecGraphProvider(ITmfTrace trace) {
127 super(trace, "LTTng Kernel"); //$NON-NLS-1$
128 fSystem = new LttngSystemModel();
129
130 registerHandler(new TraceEventHandlerStatedump(this));
131 registerHandler(new TraceEventHandlerSched(this));
132 registerHandler(new EventContextHandler(this));
133 registerHandler(new TraceEventHandlerExecutionGraph(this));
134 }
135
136 /**
137 * Simplify graph after construction
138 */
139 @Override
140 public void done() {
141 TmfGraph graph = getAssignedGraph();
142 if (graph == null) {
143 throw new NullPointerException();
144 }
145 Set<IGraphWorker> keys = graph.getWorkers();
146 List<LttngWorker> kernelWorker = new ArrayList<>();
147 /* build the set of worker to eliminate */
148 for (Object k : keys) {
149 if (k instanceof LttngWorker) {
150 LttngWorker w = (LttngWorker) k;
151 if (w.getHostThread().getTid() == -1) {
152 kernelWorker.add(w);
153 }
154 }
155 }
156 for (LttngWorker k : kernelWorker) {
157 List<TmfVertex> nodes = graph.getNodesOf(k);
158 for (TmfVertex node : nodes) {
159 /*
160 * send -> recv, it removes the vertex between the real source
161 * and destination
162 */
163 TmfEdge nextH = node.getEdge(EdgeDirection.OUTGOING_HORIZONTAL_EDGE);
164 TmfEdge inV = node.getEdge(EdgeDirection.INCOMING_VERTICAL_EDGE);
165 if (inV != null && nextH != null) {
166
167 TmfVertex next = nextH.getVertexTo();
168 TmfEdge nextV = next.getEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE);
169 if (nextV != null) {
170 TmfVertex src = inV.getVertexFrom();
171 TmfVertex dst = nextV.getVertexTo();
172
173 /* unlink */
174 node.removeEdge(EdgeDirection.INCOMING_VERTICAL_EDGE);
175 next.removeEdge(EdgeDirection.OUTGOING_VERTICAL_EDGE);
176
177 /* simplified link */
178 src.linkVertical(dst).setType(inV.getType());
179 }
180 }
181 }
182 }
183 }
184
185 /**
186 * Returns the event layout for the given trace
187 *
188 * @param trace
189 * the trace
190 *
191 * @return the eventLayout
192 */
193 public IKernelAnalysisEventLayout getEventLayout(ITmfTrace trace) {
194 if (trace instanceof LttngKernelTrace) {
195 return ((LttngKernelTrace) trace).getKernelEventLayout();
196 }
197 return LttngEventLayout.getInstance();
198 }
199
200 /**
201 * Returns the system model
202 *
203 * @return the system
204 */
205 public LttngSystemModel getSystem() {
206 return fSystem;
207 }
208
209 }
This page took 0.169738 seconds and 5 git commands to generate.