Skip to content

Commit

Permalink
Report whether a device supports taking a Perfetto trace.
Browse files Browse the repository at this point in the history
And allow the UI (hidden via a flag) to take a Perfetto trace.
  • Loading branch information
pmuetschard committed Apr 5, 2019
1 parent b3feb8b commit 4367d9f
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 10 deletions.
1 change: 1 addition & 0 deletions gapic/src/main/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,6 @@ java_library(
"//gapis/service/path:path_java_proto",
"//gapis/stringtable:stringtable_java_proto",
"//gapis/vertex:vertex_java_proto",
"@perfetto//:config_java_proto",
],
)
2 changes: 2 additions & 0 deletions gapic/src/main/com/google/gapid/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.gapid.util.Logging;
import com.google.gapid.util.Messages;
import com.google.gapid.util.Scheduler;
import com.google.gapid.views.TracerDialog;
import com.google.gapid.widgets.Theme;
import com.google.gapid.widgets.Widgets;

Expand Down Expand Up @@ -206,5 +207,6 @@ private static interface ShellRunnable {
Logging.logDir,
Follower.logFollowRequests,
Server.useCache,
TracerDialog.perfettoConfig,
};
}
3 changes: 3 additions & 0 deletions gapic/src/main/com/google/gapid/models/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class Settings {
public int[] shaderSplitterWeights = new int[] { 70, 30 };
public int[] texturesSplitterWeights = new int[] { 20, 80 };
public String traceDevice = "";
public String traceType = "Graphics";
public String traceApi = "";
public String traceUri = "";
public String traceArguments = "";
Expand Down Expand Up @@ -217,6 +218,7 @@ private void updateFrom(Properties properties) {
texturesSplitterWeights =
getIntList(properties, "texture.splitter.weights", texturesSplitterWeights);
traceDevice = properties.getProperty("trace.device", traceDevice);
traceType = properties.getProperty("trace.type", traceType);
traceApi = properties.getProperty("trace.api", traceApi);
traceUri = properties.getProperty("trace.uri", traceUri);
traceArguments = properties.getProperty("trace.arguments", traceArguments);
Expand Down Expand Up @@ -260,6 +262,7 @@ private void updateTo(Properties properties) {
setIntList(properties, "shader.splitter.weights", shaderSplitterWeights);
setIntList(properties, "texture.splitter.weights", texturesSplitterWeights);
properties.setProperty("trace.device", traceDevice);
properties.setProperty("trace.type", traceType);
properties.setProperty("trace.api", traceApi);
properties.setProperty("trace.uri", traceUri);
properties.setProperty("trace.arguments", traceArguments);
Expand Down
52 changes: 43 additions & 9 deletions gapic/src/main/com/google/gapid/views/TracerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static com.google.gapid.widgets.Widgets.withLayoutData;
import static com.google.gapid.widgets.Widgets.withMargin;
import static com.google.gapid.widgets.Widgets.withSpans;
import static java.util.stream.Collectors.toList;

import com.google.common.collect.Lists;
import com.google.gapid.models.Analytics;
Expand All @@ -41,10 +42,13 @@
import com.google.gapid.proto.service.Service.ClientAction;
import com.google.gapid.proto.service.Service.DeviceTraceConfiguration;
import com.google.gapid.proto.service.Service.StatusResponse;
import com.google.gapid.proto.service.Service.TraceType;
import com.google.gapid.proto.service.Service.TraceTypeCapabilities;
import com.google.gapid.server.Client;
import com.google.gapid.server.Tracer;
import com.google.gapid.server.Tracer.TraceRequest;
import com.google.gapid.util.Flags;
import com.google.gapid.util.Flags.Flag;
import com.google.gapid.util.Messages;
import com.google.gapid.util.OS;
import com.google.gapid.util.Scheduler;
Expand All @@ -54,6 +58,7 @@
import com.google.gapid.widgets.LoadingIndicator;
import com.google.gapid.widgets.Theme;
import com.google.gapid.widgets.Widgets;
import com.google.protobuf.TextFormat;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.ArrayContentProvider;
Expand All @@ -80,6 +85,10 @@
import org.eclipse.swt.widgets.Text;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
Expand All @@ -95,6 +104,10 @@
public class TracerDialog {
protected static final Logger LOG = Logger.getLogger(TracerDialog.class.getName());

public static final Flag<String> perfettoConfig = Flags.value("perfetto", "",
"Path to a file containing a perfetto trace config proto in text format. " +
"Specifying this flag will enable the Perfetto tracing UI features");

private TracerDialog() {
}

Expand Down Expand Up @@ -153,6 +166,16 @@ public void onCaptureDevicesLoaded() {
}
}

protected static void readPerfettoConfig(Service.TraceOptions.Builder options) {
try (Reader in = new InputStreamReader(new FileInputStream(perfettoConfig.get()))) {
TextFormat.merge(in, options.getPerfettoConfigBuilder());
} catch (IOException e) {
// This is temporary, experimental code, so just sort of crash.
throw new RuntimeException("Failed to read perfetto config from " + perfettoConfig.get(), e);
}
}


/**
* Dialog to request the information from the user to start a trace (which app, filename, etc.).
*/
Expand Down Expand Up @@ -277,7 +300,7 @@ public TraceInput(Composite parent, Models models, Widgets widgets, Runnable ref

deviceComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

createLabel(this, "API:");
createLabel(this, "Type:");
api = createApiDropDown(this);
api.getCombo().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

Expand Down Expand Up @@ -490,16 +513,22 @@ private void updateDevicesDropDown(Settings settings) {

private void updateApiDropdown(DeviceTraceConfiguration config, Settings settings) {
if (api != null && config != null) {
api.setInput(config.getApisList());
TraceTypeCapabilities deflt = config.getApis(0);
for (TraceTypeCapabilities c : config.getApisList()) {
if (c.getApi().equals(settings.traceApi)) {
deflt = c;
break;
List<TraceTypeCapabilities> caps = config.getApisList().stream()
.filter(t -> t.getType() != TraceType.Perfetto || !perfettoConfig.get().isEmpty())
.collect(toList());
api.setInput(caps);
if (!caps.isEmpty()) {
TraceTypeCapabilities deflt = caps.get(0);
for (TraceTypeCapabilities c : caps) {
if (c.getType().name().equals(settings.traceType) &&
(c.getApi().isEmpty() || c.getApi().equals(settings.traceApi))) {
deflt = c;
break;
}
}
api.setSelection(new StructuredSelection(deflt));
api.getCombo().notifyListeners(SWT.Selection, new Event());
}
api.setSelection(new StructuredSelection(deflt));
api.getCombo().notifyListeners(SWT.Selection, new Event());
}
}

Expand Down Expand Up @@ -577,6 +606,7 @@ public TraceRequest getTraceRequest(Settings settings) {
File output = getOutputFile();

settings.traceDevice = dev.device.getSerial();
settings.traceType = config.getType().name();
settings.traceApi = config.getApi();
settings.traceUri = traceTarget.getText();
settings.traceArguments = arguments.getText();
Expand Down Expand Up @@ -618,6 +648,10 @@ public TraceRequest getTraceRequest(Settings settings) {
options.setDisablePcs(disablePcs.getSelection());
}

if (config.getType() == TraceType.Perfetto) {
readPerfettoConfig(options);
}

return new TraceRequest(output, options.build());
}

Expand Down
5 changes: 4 additions & 1 deletion gapis/trace/android/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,16 @@ func NewTracer(dev bind.Device) tracer.Tracer {

// TraceConfiguration returns the device's supported trace configuration.
func (t *androidTracer) TraceConfiguration(ctx context.Context) (*service.DeviceTraceConfiguration, error) {
apis := make([]*service.TraceTypeCapabilities, 0, 2)
apis := make([]*service.TraceTypeCapabilities, 0, 3)
if t.b.Instance().GetConfiguration().GetDrivers().GetOpengl().GetVersion() != "" {
apis = append(apis, tracer.GLESTraceOptions())
}
if len(t.b.Instance().GetConfiguration().GetDrivers().GetVulkan().GetPhysicalDevices()) > 0 {
apis = append(apis, tracer.VulkanTraceOptions())
}
if t.b.Instance().GetConfiguration().GetOS().GetAPIVersion() >= 28 {
apis = append(apis, tracer.PerfettoTraceOptions())
}

return &service.DeviceTraceConfiguration{
Apis: apis,
Expand Down
10 changes: 10 additions & 0 deletions gapis/trace/tracer/default_api_trace_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,13 @@ func GLESTraceOptions() *service.TraceTypeCapabilities {
CanEnableUnsupportedExtensions: false,
}
}

// PerfettoTraceOptions returns the default trace options for Perfetto.
func PerfettoTraceOptions() *service.TraceTypeCapabilities {
return &service.TraceTypeCapabilities{
Type: service.TraceType_Perfetto,
CanDisablePcs: false,
MidExecutionCaptureSupport: service.FeatureStatus_Supported,
CanEnableUnsupportedExtensions: false,
}
}

0 comments on commit 4367d9f

Please sign in to comment.