Skip to content

Commit

Permalink
Add "Fixed Perfomance Mode" system profile capture option
Browse files Browse the repository at this point in the history
  • Loading branch information
olehkuznetsov committed Dec 18, 2024
1 parent 6a19e2e commit ce2e23a
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 8 deletions.
17 changes: 17 additions & 0 deletions core/os/android/adb/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ func (b *binding) QueryPerfettoServiceState(ctx context.Context) (*device.Perfet

// This has anecdotally not worked well in Q, but appears to be fine in R.
result.CanDownloadWhileTracing = true

result.HasFixedPerformanceMode = true
}

services, err := b.Shell("service", "list").Call(ctx)
Expand Down Expand Up @@ -437,6 +439,21 @@ func (b *binding) SupportsAngle(ctx context.Context) bool {
return os.GetAPIVersion() >= 29
}

func (b *binding) SetFixedPerformanceMode(ctx context.Context, value bool) error {
var stringValue string = "false"
if value {
stringValue = "true"
}
res, err := b.Shell("cmd power", "set-fixed-performance-mode-enabled", stringValue).Call(ctx)
if res != "" {
return log.Errf(ctx, nil, "cmd power set-fixed-performance-mode-enabled error: \n%s", res)
}
if err != nil {
return err
}
return nil
}

func (b *binding) QueryAngle(ctx context.Context) (*device.ANGLE, error) {
if !b.SupportsAngle(ctx) {
return nil, fmt.Errorf("ANGLE not supported on this device")
Expand Down
2 changes: 2 additions & 0 deletions core/os/android/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ type Device interface {
StartPerfettoTrace(ctx context.Context, config *perfetto_pb.TraceConfig, out string, stop task.Signal, ready task.Task) error
// SupportsAngle returns true if this device will work with ANGLE
SupportsAngle(ctx context.Context) bool
// Enable/Disable Fixed Performance Mode
SetFixedPerformanceMode(ctx context.Context, value bool) error
}

// LogcatMessage represents a single logcat message.
Expand Down
1 change: 1 addition & 0 deletions core/os/device/device.proto
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ message PerfettoCapability {
// Whether the Perfetto tracing API supports tracing to a file on the device
// given a path, rather than a file descriptor.
bool can_provide_trace_file_path = 7;
bool has_fixed_performance_mode = 8;
}

message GPUProfiling {
Expand Down
11 changes: 11 additions & 0 deletions gapic/src/main/com/google/gapid/server/Tracer.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public boolean stop() {
return sendEvent(Service.TraceEvent.Stop);
}

@Override
public boolean cancel() {
return sendEvent(Service.TraceEvent.Cancel);
}

private boolean sendEvent(Service.TraceEvent event) {
if (done.get()) {
return false;
Expand Down Expand Up @@ -145,6 +150,12 @@ public static interface Trace {
* @returns whether the stop request was sent.
*/
public boolean stop();

/**
* Requests the current trace to be canceled.
* @returns whether the cancel request was sent.
*/
public boolean cancel();
}

/**
Expand Down
3 changes: 2 additions & 1 deletion gapic/src/main/com/google/gapid/settings.proto
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ message Trace {
string device_serial = 1;
string device_name = 2;
string type = 3;
bool last_frame_trace_was_vulkan = 21;
string api = 4 [deprecated = true]; // Kept for de-serialization.
string uri = 5;
string arguments = 6;
Expand All @@ -133,6 +132,8 @@ message Trace {
Duration profile_duration = 18;
string process_name = 19;
bool load_validation_layer = 20;
bool last_frame_trace_was_vulkan = 21;
bool fixed_performance_mode = 22;
}

message Perfetto {
Expand Down
28 changes: 27 additions & 1 deletion gapic/src/main/com/google/gapid/views/TracerDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ private static class TraceInput extends Composite {
private final Button includeUnsupportedExtensions;
private final Button loadValidationLayer;
private final Button clearCache;
private final Button fixedPerformanceMode;
private final Composite systemTracingConfig;
private final Label systemTracingConfigLabel;
private final FileTextbox.Directory directory;
Expand Down Expand Up @@ -532,6 +533,10 @@ protected String createAndShowDialog(String current) {
optGroup, "Load Vulkan Validation Layer", trace.getLoadValidationLayer());
loadValidationLayer.setEnabled(false);
loadValidationLayer.setVisible(enableLoadValidationLayer.get());
fixedPerformanceMode = createCheckbox(
optGroup, "Fixed Performance Mode", trace.getFixedPerformanceMode());
fixedPerformanceMode.setEnabled(false);
fixedPerformanceMode.setVisible(false);

systemTracingConfig = withLayoutData(
createComposite(optGroup, withMargin(new GridLayout(2, false), 5, 0)),
Expand Down Expand Up @@ -776,6 +781,13 @@ private void updateOnConfigChange(Settings settings, SettingsProto.TraceOrBuilde

systemTracingConfig.setVisible(isSystem);

boolean hasFixedPerformanceMode =
isSystem
&& dev != null
&& dev.device.getConfiguration().getPerfettoCapability().getHasFixedPerformanceMode();
fixedPerformanceMode.setEnabled(hasFixedPerformanceMode);
fixedPerformanceMode.setVisible(hasFixedPerformanceMode);

if (!userHasChangedOutputFile) {
file.setText(formatTraceName(friendlyName));
userHasChangedOutputFile = false; // cancel the modify event from set call.
Expand Down Expand Up @@ -1092,6 +1104,8 @@ public TraceRequest getTraceRequest(Settings settings) {
trace.setClearCache(clearCache.getSelection());
options.setClearCache(clearCache.getSelection());
}
trace.setFixedPerformanceMode(fixedPerformanceMode.getSelection());
options.setFixedPerformanceMode(fixedPerformanceMode.getSelection());

if (dev.isFuchsia()) {
if(type == TraceType.System) {
Expand Down Expand Up @@ -1300,6 +1314,18 @@ public void onProgress(StatusResponse progress) {
update();
}

@Override
protected void handleShellCloseEvent() {
// trace.cancel();
super.handleShellCloseEvent();
}

@Override
protected void cancelPressed() {
// trace.cancel();
super.handleShellCloseEvent();
}

@Override
public void onFailure(Throwable e) {
error = e;
Expand Down Expand Up @@ -1341,7 +1367,7 @@ protected Control createDialogArea(Composite parent) {
// Make sure the stop signal is issued when the dialog is closed.
getShell().addListener(SWT.Close, e -> {
if (!successful()) {
trace.stop();
trace.cancel();
}
});

Expand Down
44 changes: 39 additions & 5 deletions gapis/perfetto/android/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ func hasDataSourceEnabled(perfettoConfig *perfetto_pb.TraceConfig, ds string) bo
return false
}

func setupFixedPerformanceMode(ctx context.Context, d adb.Device, opts *service.TraceOptions) (app.Cleanup, error) {
if opts.FixedPerformanceMode {
var cleanup app.Cleanup
cleanup = cleanup.Then(func(ctx context.Context) {
d.SetFixedPerformanceMode(ctx, false)
})
if err := d.SetFixedPerformanceMode(ctx, true); err != nil {
return cleanup.Invoke(ctx), err
}
return cleanup, nil
}
return nil, nil
}

// SetupProfileLayersSource configures the device to allow packages to be used as layer sources for profiling
func SetupProfileLayersSource(ctx context.Context, d adb.Device, apk *android.InstalledPackage, abi *device.ABI) (app.Cleanup, error) {
supported, packageName, cleanup, err := d.PrepareGpuProfiling(ctx, apk)
Expand Down Expand Up @@ -137,6 +151,14 @@ func Start(ctx context.Context, d adb.Device, a *android.ActivityAction, opts *s

var cleanup app.Cleanup

nextCleanup, err := setupFixedPerformanceMode(ctx, d, opts)
if nextCleanup != nil {
cleanup = cleanup.Then(nextCleanup)
}
if err != nil {
return nil, cleanup.Invoke(ctx), err
}

if a != nil {
ctx = log.V{
"package": a.Package.Name,
Expand Down Expand Up @@ -240,8 +262,14 @@ func (p *Process) Capture(ctx context.Context, start task.Signal, stop task.Sign
// Signal that we are ready to start.
atomic.StoreInt64(written, 1)

if p.deferred && !start.Wait(ctx) {
return 0, log.Err(ctx, nil, "Cancelled")
if p.deferred {
select {
case <-start:
break
case <-stop:
case <-task.ShouldStop(ctx):
return 0, log.Err(ctx, nil, "Cancelled")
}
}

if err := p.device.StartPerfettoTrace(ctx, p.config, perfettoTraceFile, stop, ready); err != nil {
Expand Down Expand Up @@ -356,9 +384,15 @@ func (p *Process) captureWithClientApi(ctx context.Context, start task.Signal, s
delayedReady := task.Delay(ready, 250*time.Millisecond)

atomic.StoreInt64(written, 1)
if p.deferred && !start.Wait(ctx) {
ts.Stop(ctx)
return 0, errors.New("Cancelled")
if p.deferred {
select {
case <-start:
break
case <-stop:
case <-task.ShouldStop(ctx):
ts.Stop(ctx)
return 0, errors.New("Cancelled")
}
}
delayedReady(ctx)
ts.Start(ctx)
Expand Down
3 changes: 3 additions & 0 deletions gapis/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ func (r *traceHandler) Event(ctx context.Context, req service.TraceEvent) (*serv
}
r.stopFunc(ctx)
r.doneSignal.Wait(ctx)
case service.TraceEvent_Cancel:
r.stopFunc(ctx)
r.doneSignal.Wait(ctx)
case service.TraceEvent_Status:
// intentionally empty
}
Expand Down
5 changes: 4 additions & 1 deletion gapis/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1370,12 +1370,15 @@ message TraceOptions {
bool load_validation_layer = 28;
// The config options to use if doing a Fuchsia trace.
FuchsiaTraceConfig fuchsia_trace_config = 29;
// Do we need to set fixed performance mode on device
bool fixed_performance_mode = 30;
}

enum TraceEvent {
Begin = 0; // Begin tracing (only valid if started with MidExecution)
Stop = 1; // Flush and stop the trace
Status = 2; // Get the status of the trace
Cancel = 2; // Cancel the trace
Status = 3; // Get the status of the trace
}

message StatusResponse {
Expand Down

0 comments on commit ce2e23a

Please sign in to comment.