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

Simplify logging interface & add RPC method #121

Merged
merged 23 commits into from
Mar 22, 2017
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7e5c64d
Implement a simpler logging interface.
ben-clayton Mar 8, 2017
12af1f1
Add log streaming RPC.
ben-clayton Mar 8, 2017
a5bc0a6
core/app: Bind the exe name as the log process field.
ben-clayton Mar 20, 2017
49a1916
core/log: Add verbose severity.
ben-clayton Mar 20, 2017
7d7ed0f
gapir/client: Parse log message from gapir
ben-clayton Mar 20, 2017
d741198
core/log: Add style names
ben-clayton Mar 20, 2017
a71b4d2
core/text/note: Remove the now unused package
ben-clayton Mar 20, 2017
0042fe0
gapic: Merge logs from GAPIS, GAPIR and GAPIC.
ben-clayton Mar 21, 2017
a93d16f
gapit: Prefix the protodata with a header
ben-clayton Mar 21, 2017
5728cc1
gapic: Don't clear the log with each new message.
ben-clayton Mar 21, 2017
f707ba1
Address code review comments
ben-clayton Mar 21, 2017
2a3e51c
Reglob
ben-clayton Mar 21, 2017
51fa2ae
Remove proto that got moved to a subdirectoy
ben-clayton Mar 21, 2017
3ccf954
Make formatTime static.
ben-clayton Mar 21, 2017
170092f
Reduce some of the GAPIR spam to DEBUG level.
ben-clayton Mar 21, 2017
c0a7a28
Address more review comments.
ben-clayton Mar 21, 2017
e3456e1
gapir: Adjust logs to be less spammy
ben-clayton Mar 22, 2017
992634e
Fixes for new changes landed in master
ben-clayton Mar 22, 2017
e4b785a
core/log: Handle verbose severity
ben-clayton Mar 22, 2017
7133d5d
Fix javadoc link
ben-clayton Mar 22, 2017
a422b22
Merge 'github/master' into logs
ben-clayton Mar 22, 2017
472c787
Address more review comments.
ben-clayton Mar 22, 2017
67521a6
Merge branch master into logs
ben-clayton Mar 22, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 2 additions & 0 deletions CMakeProto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ protoc_go("github.com/google/gapid/gapil/snippets" "gapil/snippets" "snippets.pr
protoc_java("gapil/snippets" "snippets.proto" "com/google/gapid/proto/service/snippets/SnippetsProtos")
protoc_go("github.com/google/gapid/core/image" "core/image" "image.proto")
protoc_java("core/image" "image.proto" "com/google/gapid/proto/image/Image")
protoc_go("github.com/google/gapid/core/log/log_pb" "core/log/log_pb" "log.proto")
protoc_java("core/log/log_pb" "log.proto" "com/google/gapid/proto/log/Log")
protoc_go("github.com/google/gapid/core/os/android/apk" "core/os/android/apk" "apk.proto")
protoc_go("github.com/google/gapid/core/os/android" "core/os/android" "keycodes.proto")
protoc_go("github.com/google/gapid/core/os/device/bind" "core/os/device/bind" "bind.proto")
Expand Down
74 changes: 37 additions & 37 deletions cmd/annotate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package main

import (
"bufio"
"context"
"flag"
"fmt"
"os"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/fault/cause"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/os/file"
"github.com/google/gapid/gapil"
Expand Down Expand Up @@ -54,7 +54,7 @@ func main() {
app.Run(Run)
}

func Run(ctx log.Context) error {
func Run(ctx context.Context) error {
args := flag.Args()
if len(args) < 1 {
app.Usage(ctx, "Missing api file")
Expand All @@ -66,65 +66,65 @@ func Run(ctx log.Context) error {
return nil
}
apiName := args[0]
ctx = ctx.S("api", apiName)
ctx.Print("Parse and resolve")
l := log.Bind(ctx, log.V{"api": apiName})
l.I("Parse and resolve")
processor := gapil.NewProcessor()
if len(searchPath) > 0 {
processor.Loader = gapil.NewSearchLoader(searchPath)
}
compiled, errs := processor.Resolve(apiName)
ctx.Print("Check for errors")
l.I("Check for errors")
if err := gapil.CheckErrors(apiName, errs, maxErrors); err != nil {
return err
}
ctx.Print("Annotating")
l.I("Annotating")
a := annotate.Annotate(compiled)
if len(textFilename) != 0 {
ctx := ctx.S("textFile", textFilename)
if textFile, err := os.Create(textFilename); err != nil {
return cause.Explain(ctx, err, "Failed to open {{textFile}} for text output")
} else {
buf := bufio.NewWriter(textFile)
defer buf.Flush()
a.Print(buf)
ctx := log.V{"textFile": textFilename}.Bind(ctx)
textFile, err := os.Create(textFilename)
if err != nil {
return log.Err(ctx, err, "Failed to open {{textFile}} for text output")
}
buf := bufio.NewWriter(textFile)
defer buf.Flush()
a.Print(buf)
}
if len(base64Filename) != 0 {
ctx := ctx.S("base64File", base64Filename)
if base64File, err := os.Create(base64Filename); err != nil {
return cause.Explain(ctx, err, "Failed to open {{base64File}} for base64 output")
} else {
if err := a.Base64(base64File); err != nil {
os.Remove(base64Filename)
return cause.Explain(ctx, err, "Failed to encode {{base64File}}")
}
ctx := log.V{"base64File": base64Filename}.Bind(ctx)
base64File, err := os.Create(base64Filename)
if err != nil {
return log.Err(ctx, err, "Failed to open {{base64File}} for base64 output")
}
if err := a.Base64(base64File); err != nil {
os.Remove(base64Filename)
return log.Err(ctx, err, "Failed to encode {{base64File}}")
}
}
if len(globalsTextFilename) == 0 && len(globalsBase64Filename) == 0 {
return nil
}
ctx.Print("Globals Analysis")
l.I("Globals Analysis")
g := a.Globals()
if len(globalsTextFilename) != 0 {
ctx := ctx.S("globalsTextFile", globalsTextFilename)
if globalsTextFile, err := os.Create(globalsTextFilename); err != nil {
return cause.Explain(ctx, err, "Failed to open {{globalsTextFile}} for text output")
} else {
buf := bufio.NewWriter(globalsTextFile)
defer buf.Flush()
fmt.Fprint(buf, &g)
ctx := log.V{"globalsTextFile": globalsTextFilename}.Bind(ctx)
globalsTextFile, err := os.Create(globalsTextFilename)
if err != nil {
return log.Err(ctx, err, "Failed to open {{globalsTextFile}} for text output")
}
buf := bufio.NewWriter(globalsTextFile)
defer buf.Flush()
fmt.Fprint(buf, &g)
}
gg := a.GlobalsGrouped()
if len(globalsBase64Filename) != 0 {
ctx := ctx.S("globalsBase64File", globalsBase64Filename)
if globalsBase64File, err := os.Create(globalsBase64Filename); err != nil {
return cause.Explain(ctx, err, "Failed to open {{globalsBase64File}} for base64 output")
} else {
if err := gg.Base64(globalsBase64File); err != nil {
os.Remove(globalsBase64Filename)
return cause.Explain(ctx, err, "Failed to encode {{globalsBase64File}}")
}
ctx := log.V{"globalsBase64File": globalsBase64Filename}.Bind(ctx)
globalsBase64File, err := os.Create(globalsBase64Filename)
if err != nil {
return log.Err(ctx, err, "Failed to open {{globalsBase64File}} for base64 output")
}
if err := gg.Base64(globalsBase64File); err != nil {
os.Remove(globalsBase64Filename)
return log.Err(ctx, err, "Failed to encode {{globalsBase64File}}")
}
}
return nil
Expand Down
15 changes: 8 additions & 7 deletions cmd/apic/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package main

import (
"bytes"
"context"
"flag"
"io/ioutil"
"path/filepath"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/context/jot"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/text/parse"
"github.com/google/gapid/gapil/format"
Expand All @@ -40,7 +40,7 @@ func init() {
app.AddVerb(verb)
}

func doFormat(ctx log.Context, flags flag.FlagSet) error {
func doFormat(ctx context.Context, flags flag.FlagSet) error {
args := flags.Args()
if len(args) < 1 {
app.Usage(ctx, "Missing api file")
Expand All @@ -55,26 +55,27 @@ func doFormat(ctx log.Context, flags flag.FlagSet) error {
paths = append(paths, files...)
}
for _, path := range paths {
ctx := ctx.S("file", path)
ctx := log.V{"file": path}.Bind(ctx)
f, err := ioutil.ReadFile(path)
if err != nil {
jot.Fail(ctx, err, "Failed to read api file")
log.F(ctx, "Failed to read api file. Error: %v", err)
continue
}
m := parse.NewCSTMap()
api, errs := parser.Parse(path, string(f), m)
if len(errs) > 0 {
ctx.Error().Log("Errors while parsing api file:")
l := log.From(ctx)
l.E("Errors while parsing api file:")
for i, e := range errs {
ctx.Error().Logf("%d: %v", i, e)
l.E("%d: %v", i, e)
}
continue
}

buf := &bytes.Buffer{}
format.Format(api, m, buf)
if err = ioutil.WriteFile(path, buf.Bytes(), 0777); err != nil {
jot.Fail(ctx, err, "Failed to write formatted api file")
log.E(ctx, "Failed to write formatted api file. Error: %v", err)
}
}
return nil
Expand Down
13 changes: 7 additions & 6 deletions cmd/apic/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"context"
"flag"
"fmt"
"go/build"
Expand Down Expand Up @@ -56,7 +57,7 @@ func init() {
app.AddVerb(verb)
}

func doTemplate(ctx log.Context, flags flag.FlagSet) error {
func doTemplate(ctx context.Context, flags flag.FlagSet) error {
args := flags.Args()
if len(args) < 1 {
app.Usage(ctx, "Missing api file")
Expand All @@ -71,7 +72,7 @@ func doTemplate(ctx log.Context, flags flag.FlagSet) error {
build.Default.GOPATH = filepath.FromSlash(gopath)
}
mainTemplate := args[1]
ctx.Info().S("api", apiName).Log("Reading")
log.I(ctx, "Reading %v", apiName)
processor := gapil.NewProcessor()
if len(searchPath) > 0 {
processor.Loader = gapil.NewSearchLoader(searchPath)
Expand Down Expand Up @@ -107,11 +108,11 @@ func cwd() string {
return p
}

func writeDeps(ctx log.Context) error {
func writeDeps(ctx context.Context) error {
if len(deps) == 0 {
return nil
}
ctx.Info().S("deps", deps).Log("Write")
log.I(ctx, "Writing deps %v", deps)
file, err := os.Create(deps)
if err != nil {
return err
Expand All @@ -121,11 +122,11 @@ func writeDeps(ctx log.Context) error {
return file.Close()
}

func writeCMake(ctx log.Context) error {
func writeCMake(ctx context.Context) error {
if len(cmake) == 0 {
return nil
}
ctx.Info().S("cmake", cmake).Log("Write")
log.I(ctx, "Writing cmake %v", cmake)
file, err := os.Create(cmake)
if err != nil {
return err
Expand Down
5 changes: 3 additions & 2 deletions cmd/apic/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package main

import (
"context"
"flag"
"fmt"
"os"
Expand All @@ -38,7 +39,7 @@ func init() {
app.AddVerb(verb)
}

func doValidate(ctx log.Context, flags flag.FlagSet) error {
func doValidate(ctx context.Context, flags flag.FlagSet) error {
args := flags.Args()
if len(args) < 1 {
app.Usage(ctx, "Missing api file")
Expand All @@ -50,7 +51,7 @@ func doValidate(ctx log.Context, flags flag.FlagSet) error {
if err := gapil.CheckErrors(apiName, errs, maxErrors); err != nil {
return err
}
ctx.Info().S("api", apiName).Log("Validating")
log.I(ctx, "Validating %v", apiName)
issues := validate.Validate(compiled, processor.Mappings, nil)
fmt.Fprintf(os.Stderr, "%v\n", issues)
if c := len(issues); c > 0 {
Expand Down
7 changes: 4 additions & 3 deletions cmd/clean_generated/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package main

import (
"context"
"flag"
"io/ioutil"
"os"
Expand Down Expand Up @@ -45,7 +46,7 @@ If the -n flag is not specified, the file will then be removed.
app.Run(run)
}

func run(ctx log.Context) error {
func run(ctx context.Context) error {
paths := flag.Args()
if len(paths) == 0 {
paths = []string{"."}
Expand Down Expand Up @@ -79,7 +80,7 @@ func run(ctx log.Context) error {
}
}
if len(sections) > 0 {
ctx.Printf("rewrite %s", path)
log.I(ctx, "rewrite %s", path)
if !*noactions {
out, err := os.Create(path)
if err != nil {
Expand All @@ -106,7 +107,7 @@ func run(ctx log.Context) error {
}
}
} else {
ctx.Printf("rm %s", path)
log.I(ctx, "rm %s", path)
if !*noactions {
os.Remove(path)
}
Expand Down
22 changes: 11 additions & 11 deletions cmd/codergen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package main

import (
"context"
"flag"
"fmt"
"os"
"sync"

"path/filepath"
"sync"

"github.com/google/gapid/core/app"
"github.com/google/gapid/core/log"
Expand Down Expand Up @@ -71,14 +71,14 @@ func (l *errors) Error() string {
}
}

func worker(ctx log.Context, wg *sync.WaitGroup, errs *errors, tasks chan generate.Generate) {
func worker(ctx context.Context, wg *sync.WaitGroup, errs *errors, tasks chan generate.Generate) {
wg.Add(1)
go func() {
defer wg.Done()
t := template.New()
for task := range tasks {
out := task.Output
ctx := ctx.V("Out", out)
ctx := log.V{"out": out}.Bind(ctx)
if *nowrite {
task.Output = ""
}
Expand All @@ -87,18 +87,18 @@ func worker(ctx log.Context, wg *sync.WaitGroup, errs *errors, tasks chan genera
errs.Add(err)
} else if changed {
if *nowrite {
ctx.Print("Not writing")
log.I(ctx, "Not writing")
} else {
ctx.Print("Generated")
log.I(ctx, "Generated")
}
} else {
ctx.Print("No change")
log.I(ctx, "No change")
}
}
}()
}

func run(ctx log.Context) error {
func run(ctx context.Context) error {
wd := *base
if wd == "" {
cwd, err := os.Getwd()
Expand All @@ -108,7 +108,7 @@ func run(ctx log.Context) error {
wd = cwd
}
scanner := scan.New(ctx, wd, filepath.FromSlash(*gopath))
ctx.Print("Scanning")
log.I(ctx, "Scanning")
args := flag.Args()
if len(args) == 0 {
args = append(args, "./...")
Expand All @@ -118,15 +118,15 @@ func run(ctx log.Context) error {
return err
}
}
ctx.Print("Processing")
log.I(ctx, "Processing")
if err := scanner.Process(ctx); err != nil {
return err
}
modules, err := generate.From(scanner)
if err != nil {
return err
}
ctx.Print("Generating")
log.I(ctx, "Generating")
wg := sync.WaitGroup{}
errs := errors{}
gen := make(chan generate.Generate)
Expand Down
Loading