1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
4 * All rights reserved. This program and the accompanying materials are made
5 * 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
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.flamegraph
;
14 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
15 import org
.eclipse
.core
.runtime
.IStatus
;
16 import org
.eclipse
.core
.runtime
.Status
;
17 import org
.eclipse
.core
.runtime
.jobs
.Job
;
18 import org
.eclipse
.swt
.SWT
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.core
.callgraph
.CallGraphAnalysis
;
22 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.callgraph
.CallGraphAnalysisUI
;
23 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSignalHandler
;
24 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceClosedSignal
;
25 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceOpenedSignal
;
26 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
27 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfTrace
;
28 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceUtils
;
29 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.ITmfTraceEditor
;
30 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.TmfView
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphPresentationProvider
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
33 import org
.eclipse
.ui
.IEditorPart
;
36 * View to display the flame graph .This uses the flameGraphNode tree generated
37 * by CallGraphAnalysisUI.
39 * @author Sonia Farrah
41 public class FlameGraphView
extends TmfView
{
46 public static final String ID
= FlameGraphView
.class.getPackage().getName() + ".flamegraphView"; //$NON-NLS-1$
48 private TimeGraphViewer fTimeGraphViewer
;
50 private FlameGraphContentProvider fTimeGraphContentProvider
;
52 private TimeGraphPresentationProvider fPresentationProvider
;
54 private ITmfTrace fTrace
;
59 public FlameGraphView() {
64 public void createPartControl(Composite parent
) {
65 super.createPartControl(parent
);
66 fTimeGraphViewer
= new TimeGraphViewer(parent
, SWT
.NONE
);
67 fTimeGraphContentProvider
= new FlameGraphContentProvider();
68 fPresentationProvider
= new FlameGraphPresentationProvider();
69 fTimeGraphViewer
.setTimeGraphContentProvider(fTimeGraphContentProvider
);
70 fTimeGraphViewer
.setTimeGraphProvider(fPresentationProvider
);
71 IEditorPart editor
= getSite().getPage().getActiveEditor();
72 if (editor
instanceof ITmfTraceEditor
) {
73 ITmfTrace trace
= ((ITmfTraceEditor
) editor
).getTrace();
75 traceSelected(new TmfTraceSelectedSignal(this, trace
));
81 * Handler for the trace opened signal
87 public void TraceOpened(TmfTraceOpenedSignal signal
) {
88 fTrace
= signal
.getTrace();
90 CallGraphAnalysis flamegraphModule
= TmfTraceUtils
.getAnalysisModuleOfClass(fTrace
, CallGraphAnalysis
.class, CallGraphAnalysisUI
.ID
);
91 buildFlameGraph(flamegraphModule
);
96 * Handler for the trace selected signal
102 public void traceSelected(final TmfTraceSelectedSignal signal
) {
103 fTrace
= signal
.getTrace();
104 if (fTrace
!= null) {
105 CallGraphAnalysis flamegraphModule
= TmfTraceUtils
.getAnalysisModuleOfClass(fTrace
, CallGraphAnalysis
.class, CallGraphAnalysisUI
.ID
);
106 buildFlameGraph(flamegraphModule
);
111 * Get the necessary data for the flame graph and display it
113 * @param flamegraphModule
114 * the callGraphAnalysis
116 private void buildFlameGraph(CallGraphAnalysis callGraphAnalysis
) {
117 fTimeGraphViewer
.setInput(null);
118 callGraphAnalysis
.schedule();
119 Job j
= new Job(Messages
.CallGraphAnalysis_Execution
) {
122 protected IStatus
run(IProgressMonitor monitor
) {
123 if (monitor
.isCanceled()) {
124 return Status
.CANCEL_STATUS
;
126 callGraphAnalysis
.waitForCompletion(monitor
);
127 Display
.getDefault().asyncExec(() -> {
128 fTimeGraphViewer
.setInput(callGraphAnalysis
.getThreadNodes());
130 return Status
.OK_STATUS
;
137 * Trace is closed: clear the data structures and the view
140 * the signal received
143 public void traceClosed(final TmfTraceClosedSignal signal
) {
144 if (signal
.getTrace() == fTrace
) {
145 fTimeGraphViewer
.setInput(null);
150 public void setFocus() {
151 fTimeGraphViewer
.setFocus();