blob: 16ef651e785161f363c1e337f457ae85fff285bf [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// 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 main
import (
"flag"
"io"
"android.googlesource.com/platform/tools/gpu/framework/app"
"android.googlesource.com/platform/tools/gpu/framework/log"
)
// TODO: ensure predictable choice of indices given a seed.
func init() {
verb := &app.Verb{
Name: "redo",
ShortHelp: "Runs all benchmarks in the source .perfz and saves the output to a new file",
Run: redoVerb,
ShortUsage: "<source> <destination>",
}
verb.Flags.StringVar(&flagTextualOutput, "json", "-", "output results in JSON format")
app.AddVerb(verb)
}
func clonePerfzInputs(p *Perfz) (*Perfz, error) {
result := NewPerfz()
for _, sb := range p.Benchmarks {
db := result.NewBenchmarkWithName(sb.Input.Name)
db.Input = sb.Input
traceLink, err := result.NewLink(sb.Input.Trace.Get())
if err != nil {
return nil, err
}
db.Input.Trace = traceLink
gapis, err := newGapisLink(db, sb.Input.Gapis.Get().Bundle)
if err != nil {
return nil, err
}
db.Input.Gapis = gapis
}
return result, nil
}
func redoVerb(ctx log.Context, flags flag.FlagSet) error {
if flags.NArg() != 2 {
app.Usage(ctx, "Two arguments expected, got %d", flags.NArg())
return nil
}
perfzFile := flags.Arg(0)
perfz, err := LoadPerfz(ctx, perfzFile, flagVerifyHashes)
if err != nil {
return err
}
outputPerfz, err := clonePerfzInputs(perfz)
if err != nil {
return err
}
for _, bench := range outputPerfz.Benchmarks {
if err := fullRun(ctx, bench); err != nil {
return ctx.WrapError(err, "fullRun")
}
}
err = outputPerfz.WriteTo(ctx, flags.Arg(1))
if err != nil {
return ctx.WrapError(err, "outputPerfz.WriteTo")
}
return writeAllFn(flagTextualOutput, func(w io.Writer) error {
_, err := w.Write([]byte(outputPerfz.String()))
return err
})
}