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

gapis: Add api.ResourceReference interface. #1105

Merged
merged 1 commit into from
Sep 15, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion gapis/api/cmd_observations.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ import (
"github.com/google/gapid/gapis/memory/memory_pb"
)

// ResourceReference is the interface implemented by types that hold references
// to Resource identifiers which require remapping. Resources are stored in
// the capture files using an identifier that is generated by the interceptor.
// When resources are stored into the server database, the database returns a
// different identifier for this data. To simplify things, we use
// RemapResourceIDs to transform the capture resource identifier to the database
// resource identifier as the capture is loaded.
type ResourceReference interface {
// RemapResourceIDs returns this object with the serialized resource
// identifier replaced with the identifier used to store the resource in the
// database.
RemapResourceIDs(map[id.ID]id.ID) ResourceReference
}

// CmdObservations is a collection of reads and write observations performed by an
// command.
type CmdObservations struct {
Expand Down Expand Up @@ -57,7 +71,7 @@ func (o *CmdObservations) ApplyReads(p *memory.Pool) {
}
}

// ApplyReads applies all the observed writes to the memory pool p.
// ApplyWrites applies all the observed writes to the memory pool p.
// This is a no-op when called when o is nil.
func (o *CmdObservations) ApplyWrites(p *memory.Pool) {
if o != nil {
Expand Down Expand Up @@ -100,6 +114,17 @@ func (o CmdObservation) String() string {
return fmt.Sprintf("{Range: %v, ID: %v}", o.Range, o.ID)
}

var _ ResourceReference = (*CmdObservation)(nil)

// RemapResourceIDs remaps the serialized resource identifier with the
// identifier used to store the resource in the database.
func (o CmdObservation) RemapResourceIDs(ids map[id.ID]id.ID) ResourceReference {
if id, found := ids[o.ID]; found {
o.ID = id
}
return o
}

func init() {
protoconv.Register(
func(ctx context.Context, a CmdObservation) (*memory_pb.Observation, error) {
Expand Down
3 changes: 0 additions & 3 deletions gapis/capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ func (b *builder) addAPI(ctx context.Context, api api.API) {

func (b *builder) addObservation(ctx context.Context, o *api.CmdObservation) {
interval.Merge(&b.observed, o.Range.Span(), true)
if id, found := b.idmap[o.ID]; found {
o.ID = id
}
}

func (b *builder) addRes(ctx context.Context, id id.ID, data []byte) error {
Expand Down
4 changes: 4 additions & 0 deletions gapis/capture/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ func (d *decoder) decode(ctx context.Context, in proto.Message) (interface{}, er
return nil, err
}

if r, ok := obj.(api.ResourceReference); ok {
obj = r.RemapResourceIDs(d.builder.idmap)
}

switch obj := obj.(type) {
case *Header:
d.header = obj
Expand Down