Skip to content

Commit

Permalink
callstack: Add FlameGraphTest, FlameGraph{Sel}View
Browse files Browse the repository at this point in the history
-From incubator. Include the related dependencies.

Just like the Incubator version, skip the otherwise usual
package-info.java for FlameGraphTest's package, as its originating
implementation excluded @NonNullByDefault that way too.

Also keep FlameGraphView's own, class-scope disabling of
@NonNullByDefault, set (through package-info.java) at package level.

Reuse o.e.t.i.a.profiling.ui.flamegraph.SortOption in FlameGraphView,
rather than adding Incubator's SortOption which has the same
implementation. Slightly adapt profiling.ui.flamegraph.SortOption so it
can be reused this way. Fix file formatting while editing it in Eclipse.

Beside other amends in o.e.t.a.c.ui/META-INF/MANIFEST.MF, import
com.google.common.base at runtime so its Predicate class and company are
found, upon manually opening these new Flame Graph views.

[Added] o.e.t.i.a.callstack.ui.flamegraph.FlameGraphView
[Added] o.e.t.i.a.callstack.ui.flamegraph.FlameGraphSelView

Change-Id: Ie364180b55f856cbeb9cc5111d3397f583df6f91
Signed-off-by: Marco Miller <marco.miller@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/c/tracecompass/org.eclipse.tracecompass/+/199841
Tested-by: Trace Compass Bot <tracecompass-bot@eclipse.org>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
  • Loading branch information
marco-miller committed Mar 31, 2023
1 parent 2936de9 commit 6281c6f
Show file tree
Hide file tree
Showing 25 changed files with 2,297 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tracecompass.tmf.ctf.core
Export-Package: org.eclipse.tracecompass.internal.analysis.callstack.core;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.base;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.callgraph;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.flamegraph;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.callgraph;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests,org.eclipse.tracecompass.analysis.callstack.ui",
org.eclipse.tracecompass.internal.analysis.callstack.core.flamegraph;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests,org.eclipse.tracecompass.analysis.callstack.ui,org.eclipse.tracecompass.analysis.callstack.ui.swtbot.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.instrumented;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests,org.eclipse.tracecompass.analysis.callstack.ui",
org.eclipse.tracecompass.internal.analysis.callstack.core.model;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests",
org.eclipse.tracecompass.internal.analysis.callstack.core.tree;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests"
org.eclipse.tracecompass.internal.analysis.callstack.core.tree;x-friends:="org.eclipse.tracecompass.analysis.callstack.core.tests,org.eclipse.tracecompass.analysis.callstack.ui"
Import-Package: com.google.common.annotations,
com.google.common.base,
com.google.common.cache,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,20 @@ Bundle-Localization: plugin
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Automatic-Module-Name: org.eclipse.tracecompass.analysis.callstack.ui.swtbot.tests
Require-Bundle: org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
Require-Bundle: org.eclipse.equinox.registry,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional,
org.eclipse.jface,
org.eclipse.swtbot.eclipse.finder,
org.eclipse.swtbot.junit4_x,
org.eclipse.tracecompass.analysis.callstack.core,
org.eclipse.tracecompass.analysis.callstack.core.tests,
org.eclipse.tracecompass.analysis.callstack.ui,
org.eclipse.tracecompass.tmf.core,
org.eclipse.tracecompass.tmf.ui,
org.eclipse.tracecompass.tmf.ui.swtbot.tests,
org.eclipse.tracecompass.tmf.ui.tests,
org.eclipse.ui.workbench,
org.junit
Export-Package: org.eclipse.tracecompass.analysis.callstack.ui.swtbot.tests;x-internal:=true
Import-Package: com.google.common.collect,
org.apache.log4j
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
/*******************************************************************************
* Copyright (c) 2016 Ericsson
*
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0 which
* accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/

package org.eclipse.tracecompass.analysis.callstack.ui.swtbot.tests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.stream.StreamSupport;

import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Logger;
import org.apache.log4j.SimpleLayout;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.tracecompass.analysis.callstack.core.tests.callgraph.AggregationTreeTest;
import org.eclipse.tracecompass.analysis.callstack.core.tests.stubs.CallGraphAnalysisStub;
import org.eclipse.tracecompass.internal.analysis.callstack.core.flamegraph.FlameGraphDataProvider;
import org.eclipse.tracecompass.internal.analysis.callstack.core.flamegraph.FlameGraphDataProviderFactory;
import org.eclipse.tracecompass.internal.analysis.callstack.ui.flamegraph.FlameGraphView;
import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers.SWTBotTestCondition;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotTimeGraph;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.TimeGraphViewer;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.ITimeGraphEntry;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.NullTimeEvent;
import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.model.TimeEvent;
import org.eclipse.ui.IViewPart;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.runner.RunWith;

/**
* Unit tests for the flame graph view
*
* @author Matthew Khouzam
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class FlameGraphTest extends AggregationTreeTest {

private static final String SECONDARY_ID = "org.eclipse.tracecompass.analysis.callstack.ui.swtbot.test";
private static final String FLAMEGRAPH_ID = FlameGraphView.ID;

private static final Logger fLogger = Logger.getRootLogger();

private SWTWorkbenchBot fBot;
private SWTBotView fViewBot;
private FlameGraphView fFg;
/** The Log4j logger instance. */
private TimeGraphViewer fTimeGraphViewer;
private SWTBotTimeGraph fTimeGraph;

/**
* Initialization
*/
@BeforeClass
public static void beforeClass() {
SWTBotUtils.initialize();
Thread.currentThread().setName("SWTBotTest");
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
fLogger.removeAllAppenders();
fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
SWTWorkbenchBot bot = new SWTWorkbenchBot();
SWTBotUtils.closeView("welcome", bot);
/* Switch perspectives */
SWTBotUtils.switchToTracingPerspective();
/* Finish waiting for eclipse to load */
WaitUtils.waitForJobs();
}

/**
* Open a flamegraph
*/
@Override
@Before
public void before() {
// Open the flame graph first
fBot = new SWTWorkbenchBot();
SWTBotUtils.openView(FLAMEGRAPH_ID, SECONDARY_ID);
SWTBotView view = fBot.viewById(FLAMEGRAPH_ID);
assertNotNull(view);
fViewBot = view;
FlameGraphView flamegraph = UIThreadRunnable.syncExec((Result<FlameGraphView>) () -> {
IViewPart viewRef = fViewBot.getViewReference().getView(true);
return (viewRef instanceof FlameGraphView) ? (FlameGraphView) viewRef : null;
});
assertNotNull(flamegraph);
fTimeGraphViewer = flamegraph.getTimeGraphViewer();
assertNotNull(fTimeGraphViewer);
SWTBotUtils.maximize(flamegraph);
fFg = flamegraph;
fTimeGraph = new SWTBotTimeGraph(view.bot());
// Now open the trace
super.before();
}

/**
* Clean up after a test, reset the views and reset the states of the
* timegraph by pressing reset on all the resets of the legend
*/
@After
public void after() {
// Calling maximize again will minimize
FlameGraphView fg = fFg;
if (fg != null) {
SWTBotUtils.maximize(fg);
}
// Reset the data provider so old data is not used to build view
FlameGraphDataProviderFactory.registerDataProviderWithId(SECONDARY_ID, null);
// Setting the input to null so the view can be emptied, to avoid race
// conditions with subsequent tests
TimeGraphViewer tg = fTimeGraphViewer;
if (tg != null) {
UIThreadRunnable.syncExec(() -> {
tg.setInput(null);
tg.refresh();
});
}
fBot.waitUntil(new SWTBotTestCondition() {
@Override
public boolean test() throws Exception {
return fTimeGraph.getEntries().length == 0;
}

@Override
public String getFailureMessage() {
return "Flame graph not emptied";
}
});
fViewBot.close();
fBot.waitUntil(ConditionHelpers.viewIsClosed(fViewBot));
}

private void loadFlameGraph() {
CallGraphAnalysisStub cga = Objects.requireNonNull(getCga());
ITmfTrace trace = getTrace();
fFg.setTrace(trace);
// Add the new provider and rebuild the view
FlameGraphDataProvider<?, ?, ?> dp = new FlameGraphDataProvider<>(trace, cga, FlameGraphDataProvider.ID + ':' + SECONDARY_ID);
FlameGraphDataProviderFactory.registerDataProviderWithId(SECONDARY_ID, dp);
UIThreadRunnable.syncExec(() -> fFg.buildFlameGraph(trace, null, null));
fBot.waitUntil(new SWTBotTestCondition() {
@Override
public boolean test() throws Exception {
return fTimeGraph.getEntries().length > 0;
}

@Override
public String getFailureMessage() {
return "Flame graph not ready";
}
});
}

private ITimeGraphEntry selectRoot() {
UIThreadRunnable.syncExec(() -> {
fTimeGraphViewer.selectNextItem();
fTimeGraphViewer.selectNextItem();
fTimeGraphViewer.selectNextItem();
});
ITimeGraphEntry entry = fTimeGraphViewer.getSelection();
assertNotNull(entry);
return entry;
}

private static ITimeEvent getFirstEvent(ITimeGraphEntry actualEntry) {
Optional<@NonNull ? extends ITimeEvent> actualEventOpt = StreamSupport.stream(Spliterators.spliteratorUnknownSize(actualEntry.getTimeEventsIterator(), Spliterator.NONNULL), false)
.filter(i -> (i instanceof TimeEvent)).filter(j -> !(j instanceof NullTimeEvent))
.findFirst();
assertTrue(actualEventOpt.isPresent());
return actualEventOpt.get();
}

@Override
public void emptyStateSystemTest() {
super.emptyStateSystemTest();
loadFlameGraph();
ITimeGraphEntry entry = fTimeGraphViewer.getSelection();
assertNull(entry);
}

@Override
public void cascadeTest() {
super.cascadeTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(3, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(996, actualEvent.getDuration());
}

@Override
public void mergeFirstLevelCalleesTest() {
super.mergeFirstLevelCalleesTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(3, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(80, actualEvent.getDuration());
}

@Override
public void multiFunctionRootsSecondTest() {
super.multiFunctionRootsSecondTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(2, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(10, actualEvent.getDuration());
}

@Override
public void mergeSecondLevelCalleesTest() {
super.mergeSecondLevelCalleesTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(4, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(90, actualEvent.getDuration());
}

@Override
public void multiFunctionRootsTest() {
super.multiFunctionRootsTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(2, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(10, actualEvent.getDuration());
}

/**
* Also test statistics tooltip
*/
@Override
public void treeTest() {
super.treeTest();
loadFlameGraph();
ITimeGraphEntry entry = selectRoot();
assertEquals(3, entry.getChildren().size());
ITimeGraphEntry actualEntry = entry.getChildren().get(1);
ITimeEvent actualEvent = getFirstEvent(actualEntry);
assertNotNull(actualEvent);
assertEquals(80, actualEvent.getDuration());
FlameGraphView fg = fFg;
Map<String, String> tooltip = fg.getPresentationProvider().getEventHoverToolTipInfo(actualEvent);
assertTrue(tooltip.toString().contains("duration=80 ns"));
assertTrue(tooltip.toString().contains("duration=40 ns"));
tooltip = fg.getPresentationProvider().getEventHoverToolTipInfo(actualEvent, 5);
assertTrue(tooltip.toString().contains("duration=80 ns"));
assertTrue(tooltip.toString().contains("duration=40 ns"));
}

/**
* Takes too much ram
*/
@Ignore
@Override
public void largeTest() {
// Do nothing
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ Require-Bundle: org.eclipse.core.resources,
org.eclipse.tracecompass.analysis.callstack.core,
org.eclipse.tracecompass.analysis.os.linux.core,
org.eclipse.tracecompass.analysis.os.linux.ui,
org.eclipse.tracecompass.analysis.profiling.ui,
org.eclipse.tracecompass.analysis.timing.core,
org.eclipse.tracecompass.common.core,
org.eclipse.tracecompass.tmf.core,
org.eclipse.tracecompass.tmf.ui,
org.eclipse.ui
Export-Package: org.eclipse.tracecompass.internal.analysis.callstack.ui;x-internal:=true
Import-Package: com.google.common.base,
Export-Package: org.eclipse.tracecompass.internal.analysis.callstack.ui;x-internal:=true,
org.eclipse.tracecompass.internal.analysis.callstack.ui.flamegraph;x-friends:="org.eclipse.tracecompass.analysis.callstack.ui.swtbot.tests"
Import-Package: com.google.common.annotations,
com.google.common.base,
com.google.common.collect
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Bundle-Vendor = Eclipse Trace Compass
Bundle-Name = Trace Compass Analysis Callstack UI Plug-in

view.flameChart = Flame Chart (new Callstack)
view.flameGraph = Flame Graph (new Callstack)
view.flameGraphSel = Flame Graph Selection (new Callstack)
16 changes: 16 additions & 0 deletions analysis/org.eclipse.tracecompass.analysis.callstack.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,21 @@
name="%view.flameChart"
restorable="true">
</view>
<view
category="org.eclipse.linuxtools.tmf.ui.views.category"
class="org.eclipse.tracecompass.internal.analysis.callstack.ui.flamegraph.FlameGraphView"
icon="icons/elcl16/flame.png"
id="org.eclipse.tracecompass.analysis.callstack.ui.flamegraph"
name="%view.flameGraph"
restorable="true">
</view>
<view
category="org.eclipse.linuxtools.tmf.ui.views.category"
class="org.eclipse.tracecompass.internal.analysis.callstack.ui.flamegraph.FlameGraphSelView"
icon="icons/elcl16/flame.png"
id="org.eclipse.tracecompass.analysis.callstack.ui.flamegraph.selection"
name="%view.flameGraphSel"
restorable="true">
</view>
</extension>
</plugin>
Loading

0 comments on commit 6281c6f

Please sign in to comment.