Skip to content

Commit

Permalink
gapis: Add api.ResourceReference interface.
Browse files Browse the repository at this point in the history
Used to let deserialized objects remap their Resource identifiers to those returned by database.Store.

See google#1103 for more info.
  • Loading branch information
ben-clayton committed Sep 15, 2017
1 parent aaa8aef commit db2a2d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
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

0 comments on commit db2a2d6

Please sign in to comment.