1 /*******************************************************************************
2 * Copyright (c) 2015 École Polytechnique de Montréal
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.internal
.lttng2
.kernel
.core
.analysis
.graph
.building
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
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
;
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
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
47 * handler.handleEvent(event)
50 * @author Geneviève Bastien
51 * @author Francis Giraldeau
53 public class LttngKernelExecGraphProvider
extends AbstractTmfGraphProvider
{
55 private final LttngSystemModel fSystem
;
58 * Represents an interrupt context
61 /** Not in an interrupt */
63 /** The interrupt is a soft IRQ */
65 /** The interrupt is an IRQ */
67 /** The interrupt is a timer */
69 /** The inter-processor interrupt */
74 * A list of status a thread can be in
76 public enum ProcessStatus
{
77 /** Unknown process status */
79 /** Waiting for a fork */
81 /** Waiting for the CPU */
83 /** The thread has exited, but is not dead yet */
85 /** The thread is a zombie thread */
87 /** The thread is blocked */
89 /** The thread is running */
91 /** The thread is dead */
93 private final int fValue
;
95 private ProcessStatus(int value
) {
104 * Get the ProcessStatus associated with a long value
107 * The long value corresponding to a status
108 * @return The {@link ProcessStatus} enum value
110 static public ProcessStatus
getStatus(long val
) {
111 for (ProcessStatus e
: ProcessStatus
.values()) {
112 if (e
.value() == val
) {
124 * The trace on which to build graph
126 public LttngKernelExecGraphProvider(ITmfTrace trace
) {
127 super(trace
, "LTTng Kernel"); //$NON-NLS-1$
128 fSystem
= new LttngSystemModel();
130 registerHandler(new TraceEventHandlerStatedump(this));
131 registerHandler(new TraceEventHandlerSched(this));
132 registerHandler(new EventContextHandler(this));
133 registerHandler(new TraceEventHandlerExecutionGraph(this));
137 * Simplify graph after construction
141 TmfGraph graph
= getAssignedGraph();
143 throw new NullPointerException();
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) {
156 for (LttngWorker k
: kernelWorker
) {
157 List
<TmfVertex
> nodes
= graph
.getNodesOf(k
);
158 for (TmfVertex node
: nodes
) {
160 * send -> recv, it removes the vertex between the real source
163 TmfEdge nextH
= node
.getEdge(EdgeDirection
.OUTGOING_HORIZONTAL_EDGE
);
164 TmfEdge inV
= node
.getEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
);
165 if (inV
!= null && nextH
!= null) {
167 TmfVertex next
= nextH
.getVertexTo();
168 TmfEdge nextV
= next
.getEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
);
170 TmfVertex src
= inV
.getVertexFrom();
171 TmfVertex dst
= nextV
.getVertexTo();
174 node
.removeEdge(EdgeDirection
.INCOMING_VERTICAL_EDGE
);
175 next
.removeEdge(EdgeDirection
.OUTGOING_VERTICAL_EDGE
);
177 /* simplified link */
178 src
.linkVertical(dst
).setType(inV
.getType());
186 * Returns the event layout for the given trace
191 * @return the eventLayout
193 public IKernelAnalysisEventLayout
getEventLayout(ITmfTrace trace
) {
194 if (trace
instanceof LttngKernelTrace
) {
195 return ((LttngKernelTrace
) trace
).getKernelEventLayout();
197 return LttngEventLayout
.getInstance();
201 * Returns the system model
205 public LttngSystemModel
getSystem() {