Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main Perfetto UI for System Profiling #2785

Merged
merged 4 commits into from May 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added gapic/res/icons/arrow_drop_down.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/arrow_drop_down@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/arrow_drop_right.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/arrow_drop_right@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/range_end.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/range_end@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/range_start.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/range_start@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/unfold_less.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/unfold_less@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/unfold_more.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added gapic/res/icons/unfold_more@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions gapic/src/main/BUILD.bazel
Expand Up @@ -60,6 +60,7 @@ java_library(
"//gapidapk/pkginfo:pkginfo_java_proto",
"//gapis/api:api_java_proto",
"//gapis/memory:memory_java_proto",
"//gapis/perfetto/service:perfetto_java_proto",
"//gapis/service:service_java_proto",
"//gapis/service/box:box_java_proto",
"//gapis/service/path:path_java_proto",
Expand Down
3 changes: 2 additions & 1 deletion gapic/src/main/com/google/gapid/GraphicsTraceView.java
Expand Up @@ -60,7 +60,7 @@
/**
* Main view shown when a graphics trace is loaded.
*/
public class GraphicsTraceView extends Composite {
public class GraphicsTraceView extends Composite implements MainWindow.MainView {
private final Models models;
private final Widgets widgets;
protected final Set<MainTab.Type> hiddenTabs;
Expand Down Expand Up @@ -134,6 +134,7 @@ private static Set<MainTab.Type> getHiddenTabs(Settings settings) {
return hiddenTabs;
}

@Override
public void updateViewMenu(MenuManager manager) {
manager.removeAll();

Expand Down
59 changes: 55 additions & 4 deletions gapic/src/main/com/google/gapid/MainWindow.java
Expand Up @@ -37,6 +37,7 @@
import com.google.gapid.models.CommandStream.CommandIndex;
import com.google.gapid.models.Models;
import com.google.gapid.models.Settings;
import com.google.gapid.proto.service.Service;
import com.google.gapid.proto.service.Service.ClientAction;
import com.google.gapid.server.Client;
import com.google.gapid.util.Loadable.Message;
Expand All @@ -59,6 +60,7 @@
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.program.Program;
Expand Down Expand Up @@ -102,8 +104,8 @@ public void initMainUi(Client client, Models models, Widgets widgets) {
showLoadingMessage("Setting up UI...");
initMenus(client, models, widgets);

LoadablePanel<GraphicsTraceView> mainUi = new LoadablePanel<GraphicsTraceView>(
mainArea, widgets, parent -> new GraphicsTraceView(parent, models, widgets));
LoadablePanel<MainViewContainer> mainUi = new LoadablePanel<MainViewContainer>(
mainArea, widgets, parent -> new MainViewContainer(parent, models, widgets));
models.capture.addListener(new Capture.Listener() {
@Override
public void onCaptureLoadingStart(boolean maintainState) {
Expand All @@ -117,9 +119,11 @@ public void onCaptureLoaded(Message error) {
if (error != null) {
mainUi.showMessage(error);
} else {
mainUi.stopLoading();
mainUi.getContents().updateViewMenu(findMenu(MenuItems.VIEW_ID));
MainView view = mainUi.getContents().updateAndGet(
models.capture.getData().capture.getType());
view.updateViewMenu(findMenu(MenuItems.VIEW_ID));
getMenuBarManager().updateAll(true);
mainUi.stopLoading();
}
}
});
Expand Down Expand Up @@ -352,6 +356,45 @@ private MenuManager createHelpMenu(Client client, Models models, Widgets widgets
return manager;
}

private static class MainViewContainer extends Composite {
private final Models models;
private final Widgets widgets;

private Service.TraceType current;
private MainView view;

public MainViewContainer(Composite parent, Models models, Widgets widgets) {
super(parent, SWT.NONE);
this.models = models;
this.widgets = widgets;

setLayout(new FillLayout());
}

public MainView updateAndGet(Service.TraceType traceType) {
if (traceType == current) {
return view;
}
if (view != null) {
((Control)view).dispose();
}

current = traceType;
switch (traceType) {
case Graphics:
view = new GraphicsTraceView(this, models, widgets);
break;
case Perfetto:
view = new PerfettoTraceView(this, models, widgets);
break;
default:
throw new AssertionError("Trace type not supported: " + traceType);
}
layout();
return view;
}
}

/**
* The menu items shown in the main application window menus.
*/
Expand All @@ -370,6 +413,7 @@ public static enum MenuItems {
ViewThumbnails("Show Filmstrip"),
ViewLeft("Show Left Tabs"),
ViewRight("Show Right Tabs"),
ViewDarkMode("Dark Mode", 'D'),

HelpOnlineHelp("&Online Help\tF1", SWT.F1),
HelpAbout("&About"),
Expand Down Expand Up @@ -420,4 +464,11 @@ private Action configure(Action action) {
return action;
}
}

/**
* Main view shown once a trace is loaded.
*/
public static interface MainView {
public void updateViewMenu(MenuManager manager);
}
}
70 changes: 70 additions & 0 deletions gapic/src/main/com/google/gapid/PerfettoTraceView.java
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2019 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.gapid;

import com.google.gapid.models.Models;
import com.google.gapid.perfetto.QueryViewer;
import com.google.gapid.perfetto.TraceView;
import com.google.gapid.perfetto.views.StyleConstants;
import com.google.gapid.widgets.Widgets;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

/**
* Main view shown when a Perfetto trace is loaded.
*/
public class PerfettoTraceView extends Composite implements MainWindow.MainView {
private final Models models;

public PerfettoTraceView(Composite parent, Models models, Widgets widgets) {
super(parent, SWT.NONE);
this.models = models;

setLayout(new FillLayout());

TabFolder folder = new TabFolder(this, SWT.TOP);
TabItem main = new TabItem(folder, SWT.NONE);
main.setText("Perfetto");
main.setControl(new TraceView(folder, models, widgets));

TabItem query = new TabItem(folder, SWT.NONE);
query.setText("Query");
query.setControl(new QueryViewer(folder, models));
}

@Override
public void updateViewMenu(MenuManager manager) {
manager.removeAll();

Action darkMode = MainWindow.MenuItems.ViewDarkMode.createCheckbox((dark) -> {
models.settings.perfettoDarkMode = dark;
StyleConstants.setDark(dark);
Rectangle size = getClientArea();
redraw(size.x, size.y, size.width, size.height, true);
});
darkMode.setChecked(models.settings.perfettoDarkMode);
StyleConstants.setDark(models.settings.perfettoDarkMode);

manager.add(darkMode);
}
}
5 changes: 5 additions & 0 deletions gapic/src/main/com/google/gapid/models/ApiContext.java
Expand Up @@ -64,6 +64,11 @@ protected Path.Any getPath(Path.Capture capturePath) {
.build();
}

@Override
protected boolean shouldLoad(Capture capture) {
return capture.isGraphics();
}

@Override
protected ListenableFuture<Contexts> doLoad(Path.Any path, Path.Device device) {
return MoreFutures.transform(MoreFutures.transformAsync(client.get(path, device), val -> {
Expand Down
8 changes: 8 additions & 0 deletions gapic/src/main/com/google/gapid/models/Capture.java
Expand Up @@ -68,6 +68,14 @@ public void loadCapture(File file) {
load(file, true);
}

public boolean isGraphics() {
return isLoaded() && getData().capture.getType() == Service.TraceType.Graphics;
}

public boolean isPerfetto() {
return isLoaded() && getData().capture.getType() == Service.TraceType.Perfetto;
}

@Override
protected ListenableFuture<Data> doLoad(File file) {
if (!file.exists() || !file.canRead()) {
Expand Down
Expand Up @@ -46,7 +46,7 @@ public void onCaptureLoadingStart(boolean maintainState) {

@Override
public void onCaptureLoaded(Loadable.Message error) {
if (error == null) {
if (error == null && shouldLoad(capture)) {
load(getPath(capture.getData().path), false);
} else {
reset(false);
Expand All @@ -64,6 +64,11 @@ protected void reset(boolean maintainState) {
reset();
}

/**
* Whether this model should be loaded for the given capture.
*/
protected abstract boolean shouldLoad(Capture capture);

public abstract static class ForValue<T extends Data, L extends Events.Listener>
extends CaptureDependentModel<T, L> {
public ForValue(Logger log, Shell shell, Analytics analytics, Client client,
Expand Down
2 changes: 1 addition & 1 deletion gapic/src/main/com/google/gapid/models/Devices.java
Expand Up @@ -71,7 +71,7 @@ public void onCaptureLoadingStart(boolean maintainState) {

@Override
public void onCaptureLoaded(Loadable.Message error) {
if (error == null) {
if (error == null && capture.isGraphics()) {
loadReplayDevices(capture.getData().path);
}
}
Expand Down
7 changes: 5 additions & 2 deletions gapic/src/main/com/google/gapid/models/Models.java
Expand Up @@ -37,12 +37,13 @@ public class Models {
public final ConstantSets constants;
public final Geometries geos;
public final Memory memory;
public final Perfetto perfetto;
public final StatusBar status; // The "model" part of this "widget".

public Models(Settings settings, Analytics analytics, Follower follower, Capture capture,
Devices devices, CommandStream commands, ApiContext contexts, Timeline timeline,
Resources resources, ApiState state, Reports reports, ImagesModel images,
ConstantSets constants, Geometries geos, Memory memory, StatusBar status) {
ConstantSets constants, Geometries geos, Memory memory, Perfetto perfetto, StatusBar status) {
this.settings = settings;
this.analytics = analytics;
this.follower = follower;
Expand All @@ -58,6 +59,7 @@ public Models(Settings settings, Analytics analytics, Follower follower, Capture
this.constants = constants;
this.geos = geos;
this.memory = memory;
this.perfetto = perfetto;
this.status = status;
}

Expand All @@ -79,8 +81,9 @@ public static Models create(
ImagesModel images = new ImagesModel(client, devices, capture, settings);
Geometries geometries = new Geometries(shell, analytics, client, devices, commands);
Memory memory = new Memory(shell, analytics, client, devices, commands);
Perfetto perfetto = new Perfetto(shell, analytics, client, capture, status);
return new Models(settings, analytics, follower, capture, devices, commands, contexts, timeline,
resources, state, reports, images, constants, geometries, memory, status);
resources, state, reports, images, constants, geometries, memory, perfetto, status);
}

public void dispose() {
Expand Down