Skip to content

Commit

Permalink
Make AllResourceData resolvable based on resource type.
Browse files Browse the repository at this point in the history
This means that dump_resources does not have to actually
kick off replays. It also means we don't have to store
as much data if we do not need all of it.
  • Loading branch information
AWoloszyn committed Jan 3, 2019
1 parent ec206a0 commit 64c7207
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions gapis/resolve/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//core/app/analytics:go_default_library",
"//core/app/crash:go_default_library",
"//core/app/status:go_default_library",
"//core/context/keys:go_default_library",
"//core/data/deep:go_default_library",
"//core/data/dictionary:go_default_library",
"//core/data/endian:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions gapis/resolve/resolvables.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ message ResourceDataResolvable {
message AllResourceDataResolvable {
path.Command after = 1;
path.ResolveConfig config = 2;
api.ResourceType type = 3;
}

message ResourceMetaResolvable {
Expand Down
33 changes: 24 additions & 9 deletions gapis/resolve/resource_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ type ResolvedResources struct {
func (r *AllResourceDataResolvable) Resolve(ctx context.Context) (interface{}, error) {
ctx = SetupContext(ctx, r.After.Capture, r.Config)

resources, err := buildResources(ctx, r.After)
resources, err := buildResources(ctx, r.After, r.Type)

if err != nil {
return nil, err
}
return resources, nil
}

func buildResources(ctx context.Context, p *path.Command) (*ResolvedResources, error) {
func buildResources(ctx context.Context, p *path.Command, t api.ResourceType) (*ResolvedResources, error) {
cmdIdx := p.Indices[0]

capture, err := capture.Resolve(ctx)
Expand Down Expand Up @@ -107,11 +107,13 @@ func buildResources(ctx context.Context, p *path.Command) (*ResolvedResources, e

resourceData := make(map[id.ID]interface{})
for k, v := range resources {
res, err := v.ResourceData(ctx, state)
if err != nil {
resourceData[k] = err
} else {
resourceData[k] = res
if v.ResourceType(ctx) == t {
res, err := v.ResourceData(ctx, state)
if err != nil {
resourceData[k] = err
} else {
resourceData[k] = res
}
}
}
return &ResolvedResources{idMap, resources, resourceData}, nil
Expand All @@ -129,15 +131,28 @@ func ResourceData(ctx context.Context, p *path.ResourceData, r *path.ResolveConf

// Resolve implements the database.Resolver interface.
func (r *ResourceDataResolvable) Resolve(ctx context.Context) (interface{}, error) {
resources, err := database.Build(ctx, &AllResourceDataResolvable{After: r.Path.After, Config: r.Config})
resTypes, err := Resources(ctx, r.Path.After.Capture, r.Config)
if err != nil {
return nil, err
}

id := r.Path.ID.ID()

t, ok := resTypes.ResourceTypes[id.String()]

if !ok {
return nil, log.Errf(ctx, nil, "Could not find resource %v", id)
}

resources, err := database.Build(ctx, &AllResourceDataResolvable{After: r.Path.After, Type: t, Config: r.Config})
if err != nil {
return nil, err
}
res, ok := resources.(*ResolvedResources)
if !ok {
return nil, fmt.Errorf("Cannot resolve resources at command: %v", r.Path.After)
}
id := r.Path.ID.ID()

if val, ok := res.resourceData[id]; ok {
if err, isErr := val.(error); isErr {
return nil, err
Expand Down
8 changes: 6 additions & 2 deletions gapis/resolve/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func (r *ResourcesResolvable) Resolve(ctx context.Context) (interface{}, error)
}

resources := []trackedResource{}
resourceTypes := map[string]api.ResourceType{}
seen := map[api.Resource]int{}

var currentCmdIndex uint64
Expand All @@ -63,13 +64,15 @@ func (r *ResourcesResolvable) Resolve(ctx context.Context) (interface{}, error)
currentCmdResourceCount++
seen[res] = len(seen)
context := currentAPI.Context(ctx, state, currentThread)
resources = append(resources, trackedResource{
tr := trackedResource{
resource: res,
id: genResourceID(currentCmdIndex, currentCmdResourceCount),
context: r.Capture.Context(id.ID(context.ID())),
accesses: []uint64{currentCmdIndex},
created: currentCmdIndex,
})
}
resources = append(resources, tr)
resourceTypes[tr.id.String()] = res.ResourceType(ctx)
}
state.OnResourceAccessed = func(r api.Resource) {
if index, ok := seen[r]; ok { // Update the list of accesses
Expand Down Expand Up @@ -128,6 +131,7 @@ func (r *ResourcesResolvable) Resolve(ctx context.Context) (interface{}, error)
for _, v := range types {
out.Types = append(out.Types, v)
}
out.ResourceTypes = resourceTypes

return out, nil
}
Expand Down
1 change: 1 addition & 0 deletions gapis/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ message RenderSettings {
// Resources contains the full list of resources used by a capture.
message Resources {
repeated ResourcesByType types = 1;
map<string, api.ResourceType> resourceTypes = 2;
}

// ResourcesByType contains all resources of a specific type.
Expand Down

0 comments on commit 64c7207

Please sign in to comment.