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
8 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.analysis
.timing
.ui
.swtbot
.tests
.flamegraph
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotNull
;
14 import static org
.junit
.Assert
.assertNull
;
15 import static org
.junit
.Assert
.assertTrue
;
16 import static org
.junit
.Assert
.fail
;
19 import java
.util
.Optional
;
20 import java
.util
.Spliterator
;
21 import java
.util
.Spliterators
;
22 import java
.util
.stream
.StreamSupport
;
24 import org
.apache
.log4j
.ConsoleAppender
;
25 import org
.apache
.log4j
.Logger
;
26 import org
.apache
.log4j
.SimpleLayout
;
27 import org
.eclipse
.jdt
.annotation
.NonNull
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
29 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
30 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
31 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
32 import org
.eclipse
.swtbot
.swt
.finder
.results
.Result
;
33 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
34 import org
.eclipse
.tracecompass
.analysis
.timing
.core
.tests
.flamegraph
.AggregationTreeTest
;
35 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.flamegraph
.FlameGraphPresentationProvider
;
36 import org
.eclipse
.tracecompass
.internal
.analysis
.timing
.ui
.flamegraph
.FlameGraphView
;
37 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimeRange
;
38 import org
.eclipse
.tracecompass
.tmf
.core
.timestamp
.TmfTimestamp
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotTimeGraph
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotTimeGraphEntry
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
44 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
45 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
46 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
48 import org
.eclipse
.ui
.IViewPart
;
49 import org
.junit
.Before
;
50 import org
.junit
.BeforeClass
;
51 import org
.junit
.Ignore
;
52 import org
.junit
.Test
;
53 import org
.junit
.runner
.RunWith
;
56 * Unit tests for the flame graph view
58 * @author Matthew Khouzam
60 @RunWith(SWTBotJunit4ClassRunner
.class)
61 public class FlameGraphTest
extends AggregationTreeTest
{
63 private static final String FLAMEGRAPH_ID
= FlameGraphView
.ID
;
64 private SWTWorkbenchBot fBot
;
65 private SWTBotView fView
;
66 private FlameGraphView fFg
;
67 /** The Log4j logger instance. */
68 private static final Logger fLogger
= Logger
.getRootLogger();
69 private TimeGraphViewer fTimeGraphViewer
;
75 public static void beforeClass() {
77 SWTBotUtils
.initialize();
78 Thread
.currentThread().setName("SWTBotTest");
79 /* set up for swtbot */
80 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
81 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
82 fLogger
.removeAllAppenders();
83 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
84 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
85 SWTBotUtils
.closeView("welcome", bot
);
86 /* Switch perspectives */
87 SWTBotUtils
.switchToTracingPerspective();
88 /* Finish waiting for eclipse to load */
89 WaitUtils
.waitForJobs();
96 public void before() {
97 fBot
= new SWTWorkbenchBot();
98 SWTBotUtils
.openView(FLAMEGRAPH_ID
);
99 SWTBotView view
= fBot
.viewById(FLAMEGRAPH_ID
);
102 FlameGraphView flamegraph
= UIThreadRunnable
.syncExec((Result
<FlameGraphView
>) () -> {
103 IViewPart viewRef
= fView
.getViewReference().getView(true);
104 return (viewRef
instanceof FlameGraphView
) ?
(FlameGraphView
) viewRef
: null;
106 assertNotNull(flamegraph
);
107 fTimeGraphViewer
= flamegraph
.getTimeGraphViewer();
108 assertNotNull(fTimeGraphViewer
);
109 SWTBotUtils
.maximize(flamegraph
);
113 private void loadFlameGraph() {
114 UIThreadRunnable
.syncExec(() -> fFg
.buildFlameGraph(getCga()));
117 } catch (InterruptedException e
) {
118 fail(e
.getMessage());
122 private ITimeGraphEntry
selectRoot() {
123 UIThreadRunnable
.syncExec(() -> fTimeGraphViewer
.selectNextItem());
124 ITimeGraphEntry entry
= fTimeGraphViewer
.getSelection();
125 assertNotNull(entry
);
129 private static ITimeEvent
getFirstEvent(ITimeGraphEntry actualEntry
) {
130 Optional
<@NonNull ?
extends ITimeEvent
> actualEventOpt
= StreamSupport
.stream(Spliterators
.spliteratorUnknownSize(actualEntry
.getTimeEventsIterator(), Spliterator
.NONNULL
), false)
131 .filter(i
-> (i
instanceof TimeEvent
)).filter(j
-> !(j
instanceof NullTimeEvent
))
133 assertTrue(actualEventOpt
.isPresent());
134 return actualEventOpt
.get();
138 public void emptyStateSystemTest() {
139 super.emptyStateSystemTest();
141 ITimeGraphEntry entry
= fTimeGraphViewer
.getSelection();
146 public void cascadeTest() {
149 ITimeGraphEntry entry
= selectRoot();
150 assertEquals(3, entry
.getChildren().size());
151 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
152 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
153 assertNotNull(actualEvent
);
154 assertEquals(996, actualEvent
.getDuration());
159 public void mergeFirstLevelCalleesTest() {
160 super.mergeFirstLevelCalleesTest();
162 ITimeGraphEntry entry
= selectRoot();
163 assertEquals(3, entry
.getChildren().size());
164 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
165 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
166 assertNotNull(actualEvent
);
167 assertEquals(80, actualEvent
.getDuration());
171 public void multiFunctionRootsSecondTest() {
172 super.multiFunctionRootsSecondTest();
174 ITimeGraphEntry entry
= selectRoot();
175 assertEquals(2, entry
.getChildren().size());
176 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
177 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
178 assertNotNull(actualEvent
);
179 assertEquals(10, actualEvent
.getDuration());
183 public void mergeSecondLevelCalleesTest() {
184 super.mergeSecondLevelCalleesTest();
186 ITimeGraphEntry entry
= selectRoot();
187 assertEquals(4, entry
.getChildren().size());
188 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
189 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
190 assertNotNull(actualEvent
);
191 assertEquals(90, actualEvent
.getDuration());
195 public void multiFunctionRootsTest() {
196 super.multiFunctionRootsTest();
198 ITimeGraphEntry entry
= selectRoot();
199 assertEquals(2, entry
.getChildren().size());
200 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
201 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
202 assertNotNull(actualEvent
);
203 assertEquals(10, actualEvent
.getDuration());
207 * Also test statistics tooltip
210 public void treeTest() {
213 ITimeGraphEntry entry
= selectRoot();
214 assertEquals(3, entry
.getChildren().size());
215 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
216 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
217 assertNotNull(actualEvent
);
218 assertEquals(80, actualEvent
.getDuration());
219 Map
<String
, String
> tooltip
= new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent
);
221 tooltip
= new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent
, 5);
222 assertTrue(tooltip
.toString().contains("duration=80 ns"));
223 assertTrue(tooltip
.toString().contains("duration=40 ns"));
227 * Try to zoom by doubleclicking an event
229 * @throws InterruptedException
233 public void tryMouseDoubleclickZoom() throws InterruptedException
{
237 SWTBotTimeGraph sbtg
= new SWTBotTimeGraph(fView
.bot());
238 // Test the number of timegraph entries in the graph
239 SWTBotTimeGraphEntry sbtge
= sbtg
.getEntry("Thread");
240 assertEquals(3, sbtge
.getEntries().length
);
241 SWTBotTimeGraphEntry actualEntry
= sbtge
.getEntry("1");
243 actualEntry
.doubleClick(40);
246 assertEquals(new TmfTimeRange(TmfTimestamp
.fromNanos(0), TmfTimestamp
.fromNanos(80)), new TmfTimeRange(TmfTimestamp
.fromNanos(fTimeGraphViewer
.getTime0()), TmfTimestamp
.fromNanos(fTimeGraphViewer
.getTime1())));
254 public void largeTest() {