Skip to content

Commit

Permalink
GPU Queue/Render stages UI.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuetschard committed Jul 26, 2019
1 parent 158df76 commit b828cc2
Show file tree
Hide file tree
Showing 7 changed files with 359 additions and 7 deletions.
28 changes: 23 additions & 5 deletions gapic/src/main/com/google/gapid/models/Perfetto.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.gapid.perfetto.TimeSpan;
import com.google.gapid.perfetto.models.CounterInfo;
import com.google.gapid.perfetto.models.GpuInfo;
import com.google.gapid.perfetto.models.ProcessInfo;
import com.google.gapid.perfetto.models.QueryEngine;
import com.google.gapid.perfetto.models.ThreadInfo;
Expand Down Expand Up @@ -86,9 +87,10 @@ protected ListenableFuture<Data> doLoad(Path.Capture source) {
return
transformAsync(withStatus("Examining the trace...", examineTrace(data)), $1 ->
transformAsync(withStatus("Querying threads...", queryThreads(data)), $2 ->
transformAsync(withStatus("Querying counters...", queryCounters(data)), $3 ->
transform(withStatus("Enumerating tracks...", enumerateTracks(data)), $4 ->
data.build()))));
transformAsync(withStatus("Querying GPU info...", queryGpu(data)), $3 ->
transformAsync(withStatus("Querying counters...", queryCounters(data)), $4 ->
transform(withStatus("Enumerating tracks...", enumerateTracks(data)), $5 ->
data.build())))));
}

private static ListenableFuture<Data.Builder> examineTrace(Data.Builder data) {
Expand All @@ -102,6 +104,10 @@ private static ListenableFuture<Data.Builder> queryThreads(Data.Builder data) {
return ThreadInfo.listThreads(data);
}

private static ListenableFuture<Data.Builder> queryGpu(Data.Builder data) {
return GpuInfo.listGpus(data);
}

private static ListenableFuture<Data.Builder> queryCounters(Data.Builder data) {
return CounterInfo.listCounters(data);
}
Expand Down Expand Up @@ -165,17 +171,19 @@ public static class Data {
public final int numCpus;
public final ImmutableMap<Long, ProcessInfo> processes;
public final ImmutableMap<Long, ThreadInfo> threads;
public final GpuInfo gpu;
public final ImmutableMap<Long, CounterInfo> counters;
public final TrackConfig tracks;

public Data(QueryEngine queries, TimeSpan traceTime, int numCpus,
ImmutableMap<Long, ProcessInfo> processes, ImmutableMap<Long, ThreadInfo> threads,
ImmutableMap<Long, CounterInfo> counters, TrackConfig tracks) {
GpuInfo gpu, ImmutableMap<Long, CounterInfo> counters, TrackConfig tracks) {
this.qe = queries;
this.traceTime = traceTime;
this.numCpus = numCpus;
this.processes = processes;
this.threads = threads;
this.gpu = gpu;
this.counters = counters;
this.tracks = tracks;
}
Expand All @@ -186,6 +194,7 @@ public static class Builder {
private int numCpus;
private ImmutableMap<Long, ProcessInfo> processes;
private ImmutableMap<Long, ThreadInfo> threads;
private GpuInfo gpu = GpuInfo.NONE;
private ImmutableMap<Long, CounterInfo> counters;
private ImmutableListMultimap<String, CounterInfo> countersByName;
public final TrackConfig.Builder tracks = new TrackConfig.Builder();
Expand Down Expand Up @@ -230,6 +239,15 @@ public Builder setThreads(ImmutableMap<Long, ThreadInfo> threads) {
return this;
}

public GpuInfo getGpu() {
return gpu;
}

public Builder setGpu(GpuInfo gpu) {
this.gpu = gpu;
return this;
}

public ImmutableMap<Long, CounterInfo> getCounters() {
return counters;
}
Expand All @@ -246,7 +264,7 @@ public Builder setCounters(ImmutableMap<Long, CounterInfo> counters) {
}

public Data build() {
return new Data(qe, traceTime, numCpus, processes, threads, counters, tracks.build());
return new Data(qe, traceTime, numCpus, processes, threads, gpu, counters, tracks.build());
}
}
}
Expand Down
75 changes: 75 additions & 0 deletions gapic/src/main/com/google/gapid/perfetto/models/GpuInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.perfetto.models;

import static com.google.common.collect.Iterators.transform;
import static com.google.common.collect.Iterators.unmodifiableIterator;
import static com.google.gapid.util.MoreFutures.transform;

import com.google.common.util.concurrent.ListenableFuture;
import com.google.gapid.models.Perfetto;
import com.google.gapid.perfetto.models.GpuInfo.Gpu;

import java.util.Collections;
import java.util.Iterator;
import java.util.SortedMap;

/**
* Data about a GPU in the trace.
*/
public class GpuInfo implements Iterable<Gpu> {
public static final GpuInfo NONE = new GpuInfo(Collections.emptySortedMap());

private static final String MAX_DEPTH_QUERY =
"select ref, max(depth) + 1 from slices where ref_type = 'gpu' group by ref";

private final SortedMap<Long, Integer> maxDepth;

private GpuInfo(SortedMap<Long, Integer> maxDepth) {
this.maxDepth = maxDepth;
}

@Override
public Iterator<Gpu> iterator() {
return unmodifiableIterator(transform(
maxDepth.entrySet().iterator(), e -> new Gpu(e.getKey(), e.getValue())));
}

public static ListenableFuture<Perfetto.Data.Builder> listGpus(Perfetto.Data.Builder data) {
return transform(maxDepth(data.qe), maxDepth -> {
return data.setGpu(new GpuInfo(maxDepth));
});
}

private static ListenableFuture<SortedMap<Long, Integer>> maxDepth(QueryEngine qe) {
return transform(qe.queries(MAX_DEPTH_QUERY),
res -> res.sortedMap(row -> row.getLong(0), row -> row.getInt(1)));
}

public static class Gpu {
public final long id;
public final int maxDepth;

public Gpu(long id, int maxDepth) {
this.id = id;
this.maxDepth = maxDepth;
}

public String getDisplay() {
return "GPU Queue " + id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.gapid.views.StatusBar;

import java.util.Map;
import java.util.SortedMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
Expand Down Expand Up @@ -207,6 +208,12 @@ public <K, V> Map<K, V> map(Function<Row, K> key, Function<Row, V> value) {
return map;
}

public <K extends Comparable<K>, V> SortedMap<K, V> sortedMap(
Function<Row, K> key, Function<Row, V> value) {
SortedMap<K, V> map = Maps.newTreeMap();
forEachRow(($, row) -> map.put(key.apply(row), value.apply(row)));
return map;
}

public long getLong(int row, int column, long deflt) {
Perfetto.QueryResult.ColumnValues c = res.getColumns(column);
Expand Down
24 changes: 23 additions & 1 deletion gapic/src/main/com/google/gapid/perfetto/models/SliceTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
*/
public class SliceTrack extends Track<SliceTrack.Data> {
private static final String THREAD_FILTER = "utid = %d";
private static final String GPU_FILTER = "ref_type = 'gpu' and ref = %d";
private static final String SLICES_VIEW =
"select ts, dur, cat, name, depth, stack_id, parent_stack_id from slices where %s";
private static final String SLICES_SQL =
Expand All @@ -71,6 +72,10 @@ public class SliceTrack extends Track<SliceTrack.Data> {
private static final String THREAD_SLICE_RANGE_SQL =
"select stack_id, ts, dur, utid, cat, name, parent_stack_id from slices " +
"where utid = %d and ts < %d and ts + dur >= %d and depth >= %d and depth <= %d";
private static final String GPU_SLICE_RANGE_SQL =
"select stack_id, ts, dur, utid, cat, name, parent_stack_id from slices " +
"where ref_type = 'gpu' and ref = %d and ts < %d and ts + dur >= %d " +
"and depth >= %d and depth <= %d";

private final String filter;

Expand All @@ -83,6 +88,10 @@ public static SliceTrack forThread(long utid) {
return new SliceTrack("thread_slices_" + utid, format(THREAD_FILTER, utid));
}

public static SliceTrack forGpu(long gpu) {
return new SliceTrack("gpu_slices_" + gpu, format(GPU_FILTER, gpu));
}

@Override
protected ListenableFuture<?> initialize(QueryEngine qe) {
String slices = tableName("slices");
Expand Down Expand Up @@ -171,6 +180,19 @@ private static String threadSliceRangeSql(long utid, TimeSpan ts, int minDepth,
return format(THREAD_SLICE_RANGE_SQL, utid, ts.end, ts.start, minDepth, maxDepth);
}

public static ListenableFuture<List<Slice>> getGpuSlices(
QueryEngine qe, long gpu, TimeSpan ts, int minDepth, int maxDepth) {
return transform(qe.queries(gpuSliceRangeSql(gpu, ts, minDepth, maxDepth)), res -> {
List<Slice> slices = Lists.newArrayList();
res.forEachRow((i, r) -> slices.add(new Slice(SliceType.Gpu, r)));
return slices;
});
}

private static String gpuSliceRangeSql(long gpu, TimeSpan ts, int minDepth, int maxDepth) {
return format(GPU_SLICE_RANGE_SQL, gpu, ts.end, ts.start, minDepth, maxDepth);
}

public static class Data extends Track.Data {
public final long[] ids;
public final long[] starts;
Expand All @@ -192,7 +214,7 @@ public Data(DataRequest request, long[] ids, long[] starts, long[] ends, int[] d
}

public static enum SliceType {
Thread("Thread Slices");
Thread("Thread Slices"), Gpu("GPU Render Stages");

public final String title;

Expand Down
11 changes: 11 additions & 0 deletions gapic/src/main/com/google/gapid/perfetto/models/Tracks.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.gapid.perfetto.models.TrackConfig.Group;
import com.google.gapid.perfetto.views.CounterPanel;
import com.google.gapid.perfetto.views.CpuSummaryPanel;
import com.google.gapid.perfetto.views.GpuQueuePanel;
import com.google.gapid.perfetto.views.ProcessSummaryPanel;
import com.google.gapid.perfetto.views.ThreadPanel;
import com.google.gapid.perfetto.views.TitlePanel;
Expand Down Expand Up @@ -86,6 +87,16 @@ public static ListenableFuture<Perfetto.Data.Builder> enumerateCounters(

public static Perfetto.Data.Builder enumerateGpu(Perfetto.Data.Builder data) {
boolean found = false;
for (GpuInfo.Gpu gpu : data.getGpu()) {
if (!found) {
addGpuGroup(data);
found = true;
}
SliceTrack track = SliceTrack.forGpu(gpu.id);
data.tracks.addTrack("gpu", track.getId(), gpu.getDisplay(),
single(state -> new GpuQueuePanel(state, gpu, track), true));
}

for (CounterInfo counter : data.getCounters().values()) {
if ("gpu".equals(counter.refType)) {
if (!found) {
Expand Down
Loading

0 comments on commit b828cc2

Please sign in to comment.