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

Only take the slow-path in MutationCmdsFor if we really have to. #2203

Merged
merged 1 commit into from
Sep 13, 2018
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
5 changes: 5 additions & 0 deletions gapis/api/gvr/gvr.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func (API) FlattenSubcommandIdx(idx api.SubCmdIdx, data *sync.Data, unused bool)
return api.CmdID(0), false
}

// IsTrivialTerminator returns true if the terminator is just stopping at the given index
func (API) IsTrivialTerminator(ctx context.Context, p *path.Capture, command api.SubCmdIdx) (bool, error) {
return true, nil
}

// RecoverMidExecutionCommand returns a virtual command, used to describe the
// a subcommand that was created before the start of the trace
// GVR has no subcommands of this type, so this should never be called
Expand Down
16 changes: 14 additions & 2 deletions gapis/api/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type SynchronizedAPI interface {
// a subcommand that was created before the start of the trace.
// If the api does not have mid-execution commands, NoMECSubcommandsError should be returned.
RecoverMidExecutionCommand(ctx context.Context, c *path.Capture, data interface{}) (api.Cmd, error)

// IsTrivialTerminator returns true if stopping at the given command is trivial.
IsTrivialTerminator(ctx context.Context, c *path.Capture, cmd api.SubCmdIdx) (bool, error)
}

type writer struct {
Expand Down Expand Up @@ -112,13 +115,19 @@ func MutationCmdsFor(ctx context.Context, c *path.Capture, data *Data, cmds []ap

terminators := make([]transform.Terminator, 0)
transforms := transform.Transforms{}

isTrivial := true
for _, api := range rc.APIs {
if sync, ok := api.(SynchronizedAPI); ok {
term, err := sync.GetTerminator(ctx, c)
if err != nil {
return nil, err
}

t, err := sync.IsTrivialTerminator(ctx, c, fullCommand)
if err != nil {
return nil, err
}
isTrivial = t && isTrivial
if term != nil {
terminators = append(terminators, term)
continue
Expand All @@ -132,9 +141,12 @@ func MutationCmdsFor(ctx context.Context, c *path.Capture, data *Data, cmds []ap
}
transforms.Add(t)
}

if isTrivial {
return cmds[0:id], nil
}
w := &writer{rc.NewState(ctx), nil}
transforms.Transform(ctx, cmds, w)

return w.cmds, nil
}

Expand Down
24 changes: 24 additions & 0 deletions gapis/api/vulkan/vulkan.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,30 @@ func (API) FlattenSubcommandIdx(idx api.SubCmdIdx, data *sync.Data, initialCall
return api.CmdID(0), false
}

// IsTrivialTerminator returns true if the terminator is just stopping at the given index
func (API) IsTrivialTerminator(ctx context.Context, p *path.Capture, after api.SubCmdIdx) (bool, error) {
s, err := resolve.SyncData(ctx, p)
if err != nil {
return false, err
}

if len(after) == 1 {
a := api.CmdID(after[0])
// If we are not running subcommands we can probably batch
for _, v := range s.SortedKeys() {
if v > a {
return true, nil
}
for _, k := range s.CommandRanges[v].SortedKeys() {
if k > a {
return false, nil
}
}
}
}
return false, nil
}

// RecoverMidExecutionCommand returns a virtual command, used to describe the
// a subcommand that was created before the start of the trace
func (API) RecoverMidExecutionCommand(ctx context.Context, c *path.Capture, dat interface{}) (api.Cmd, error) {
Expand Down