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
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
38 import org
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
39 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.TimeGraphViewer
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeEvent
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.ITimeGraphEntry
;
42 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.NullTimeEvent
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.widgets
.timegraph
.model
.TimeEvent
;
44 import org
.eclipse
.ui
.IViewPart
;
45 import org
.junit
.Before
;
46 import org
.junit
.BeforeClass
;
47 import org
.junit
.Ignore
;
48 import org
.junit
.runner
.RunWith
;
51 * Unit tests for the flame graph view
53 * @author Matthew Khouzam
55 @RunWith(SWTBotJunit4ClassRunner
.class)
56 public class FlameGraphTest
extends AggregationTreeTest
{
58 private static final String FLAMEGRAPH_ID
= FlameGraphView
.ID
;
59 private SWTWorkbenchBot fBot
;
60 private SWTBotView fView
;
61 private FlameGraphView fFg
;
62 /** The Log4j logger instance. */
63 private static final Logger fLogger
= Logger
.getRootLogger();
64 private TimeGraphViewer fTimeGraphViewer
;
70 public static void beforeClass() {
72 SWTBotUtils
.initialize();
73 Thread
.currentThread().setName("SWTBotTest");
74 /* set up for swtbot */
75 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
76 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
77 fLogger
.removeAllAppenders();
78 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
79 SWTWorkbenchBot bot
= new SWTWorkbenchBot();
80 SWTBotUtils
.closeView("welcome", bot
);
81 /* Switch perspectives */
82 SWTBotUtils
.switchToTracingPerspective();
83 /* Finish waiting for eclipse to load */
84 WaitUtils
.waitForJobs();
91 public void before() {
92 fBot
= new SWTWorkbenchBot();
93 SWTBotUtils
.openView(FLAMEGRAPH_ID
);
94 SWTBotView view
= fBot
.viewById(FLAMEGRAPH_ID
);
97 FlameGraphView flamegraph
= UIThreadRunnable
.syncExec((Result
<FlameGraphView
>) () -> {
98 IViewPart viewRef
= fView
.getViewReference().getView(true);
99 return (viewRef
instanceof FlameGraphView
) ?
(FlameGraphView
) viewRef
: null;
101 assertNotNull(flamegraph
);
102 fTimeGraphViewer
= flamegraph
.getTimeGraphViewer();
103 assertNotNull(fTimeGraphViewer
);
104 SWTBotUtils
.maximize(flamegraph
);
108 private void loadFlameGraph() {
109 UIThreadRunnable
.syncExec(() -> fFg
.buildFlameGraph(getCga()));
112 } catch (InterruptedException e
) {
113 fail(e
.getMessage());
117 private ITimeGraphEntry
selectRoot() {
118 UIThreadRunnable
.syncExec(() -> fTimeGraphViewer
.selectNextItem());
119 ITimeGraphEntry entry
= fTimeGraphViewer
.getSelection();
120 assertNotNull(entry
);
124 private static ITimeEvent
getFirstEvent(ITimeGraphEntry actualEntry
) {
125 Optional
<@NonNull ?
extends ITimeEvent
> actualEventOpt
= StreamSupport
.stream(Spliterators
.spliteratorUnknownSize(actualEntry
.getTimeEventsIterator(), Spliterator
.NONNULL
), false)
126 .filter(i
-> (i
instanceof TimeEvent
)).filter(j
-> !(j
instanceof NullTimeEvent
))
128 assertTrue(actualEventOpt
.isPresent());
129 ITimeEvent actualEvent
= actualEventOpt
.get();
134 public void emptyStateSystemTest() {
135 super.emptyStateSystemTest();
137 ITimeGraphEntry entry
= fTimeGraphViewer
.getSelection();
142 public void cascadeTest() {
145 ITimeGraphEntry entry
= selectRoot();
146 assertEquals(3, entry
.getChildren().size());
147 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
148 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
149 assertNotNull(actualEvent
);
150 assertEquals(996, actualEvent
.getDuration());
155 public void mergeFirstLevelCalleesTest() {
156 super.mergeFirstLevelCalleesTest();
158 ITimeGraphEntry entry
= selectRoot();
159 assertEquals(3, entry
.getChildren().size());
160 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
161 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
162 assertNotNull(actualEvent
);
163 assertEquals(80, actualEvent
.getDuration());
167 public void multiFunctionRootsSecondTest() {
168 super.multiFunctionRootsSecondTest();
170 ITimeGraphEntry entry
= selectRoot();
171 assertEquals(2, entry
.getChildren().size());
172 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
173 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
174 assertNotNull(actualEvent
);
175 assertEquals(10, actualEvent
.getDuration());
179 public void mergeSecondLevelCalleesTest() {
180 super.mergeSecondLevelCalleesTest();
182 ITimeGraphEntry entry
= selectRoot();
183 assertEquals(4, entry
.getChildren().size());
184 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
185 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
186 assertNotNull(actualEvent
);
187 assertEquals(90, actualEvent
.getDuration());
191 public void multiFunctionRootsTest() {
192 super.multiFunctionRootsTest();
194 ITimeGraphEntry entry
= selectRoot();
195 assertEquals(2, entry
.getChildren().size());
196 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
197 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
198 assertNotNull(actualEvent
);
199 assertEquals(10, actualEvent
.getDuration());
203 * Also test statistics tooltip
206 public void treeTest() {
209 ITimeGraphEntry entry
= selectRoot();
210 assertEquals(3, entry
.getChildren().size());
211 ITimeGraphEntry actualEntry
= entry
.getChildren().get(1);
212 ITimeEvent actualEvent
= getFirstEvent(actualEntry
);
213 assertNotNull(actualEvent
);
214 assertEquals(80, actualEvent
.getDuration());
215 Map
<String
, String
> tooltip
= new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent
);
217 tooltip
= new FlameGraphPresentationProvider().getEventHoverToolTipInfo(actualEvent
, 5);
218 assertTrue(tooltip
.toString().contains("duration=80 ns"));
219 assertTrue(tooltip
.toString().contains("duration=40 ns"));
227 public void largeTest() {