blob: 047912c6289003627226a7bbe0f63039871a7d13 [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"
"os"
"strings"
"android.googlesource.com/platform/tools/gpu/framework/app"
"android.googlesource.com/platform/tools/gpu/framework/log"
"android.googlesource.com/platform/tools/gpu/gapid/search/script"
"android.googlesource.com/platform/tools/gpu/gapid/stash"
)
var monitor = false
func init() {
verb := &app.Verb{
Name: "search",
ShortHelp: "Prints information about stash entries",
Run: doInfo,
}
verb.Flags.BoolVar(&monitor, "monitor", monitor, "Monitor for changes")
app.AddVerb(verb)
}
func doInfo(ctx log.Context, flags flag.FlagSet) error {
return withStore(ctx, false, func(ctx log.Context, store stash.Store) error {
return getInfo(ctx, store, strings.Join(flags.Args(), " "))
})
}
func getInfo(ctx log.Context, store stash.Store, expression string) error {
out := ctx.Raw("")
expr, err := script.Parse(ctx, expression)
if err != nil {
return ctx.WrapError(err, "Malformed search query")
}
query := expr.Query()
query.Monitor = monitor
err = store.Search(ctx, query, func(ctx log.Context, entry *stash.Entity) error {
out.Logf("%s", entry)
return nil
})
if err == nil && monitor {
os.Stdin.Read([]byte{0})
}
return err
}