diff --git a/cmd/gapit/BUILD.bazel b/cmd/gapit/BUILD.bazel index 8ced9c9956..5f15448e27 100644 --- a/cmd/gapit/BUILD.bazel +++ b/cmd/gapit/BUILD.bazel @@ -21,6 +21,7 @@ go_library( "benchmark.go", "commands.go", "common.go", + "create_graph_visualization.go", "devices.go", "dump.go", "dump_fbo.go", @@ -29,7 +30,6 @@ go_library( "dump_shaders.go", "export_replay.go", "flags.go", - "graph_visualization.go", "inputs.go", "main.go", "memory.go", diff --git a/cmd/gapit/create_graph_visualization.go b/cmd/gapit/create_graph_visualization.go new file mode 100644 index 0000000000..3dbb8d8bb6 --- /dev/null +++ b/cmd/gapit/create_graph_visualization.go @@ -0,0 +1,74 @@ +// Copyright (C) 2018 Google Inc. +// +// 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 ( + "context" + "flag" + "github.com/google/gapid/core/app" + "github.com/google/gapid/core/log" + "io/ioutil" + "os" +) + +type createGraphVisualizationVerb struct{ CreateGraphVisualizationFlags } + +func init() { + verb := &createGraphVisualizationVerb{} + app.AddVerb(&app.Verb{ + Name: "create_graph_visualization", + ShortHelp: "Create graph visualization file from capture", + Action: verb, + }) +} + +func (verb *createGraphVisualizationVerb) Run(ctx context.Context, flags flag.FlagSet) error { + if flags.NArg() != 1 { + app.Usage(ctx, "Exactly one gfx trace file expected, got %d", flags.NArg()) + return nil + } + + client, capture, err := getGapisAndLoadCapture(ctx, verb.Gapis, GapirFlags{}, flags.Arg(0), CaptureFileFlags{}) + if err != nil { + return err + } + defer client.Close() + + log.I(ctx, "Creating graph visualization file from capture id: %s", capture.ID) + + graphVisualization, err := client.GetGraphVisualization(ctx, capture) + if err != nil { + return log.Errf(ctx, err, "ExportCapture(%v)", capture) + } + + filePath := verb.Out + if filePath == "" { + filePath = "graph_visualization.dot" + } + + _, err = os.Stat(filePath) + if os.IsNotExist(err) { + file, err := os.Create(filePath) + if err != nil { + log.Errf(ctx, err, "Creating file (%v)", filePath) + } + defer file.Close() + } + + if err := ioutil.WriteFile(filePath, []byte(graphVisualization), 0666); err != nil { + return log.Errf(ctx, err, "Writing file: %v", filePath) + } + return nil +} diff --git a/cmd/gapit/flags.go b/cmd/gapit/flags.go index e0391c15ab..1601f2809d 100644 --- a/cmd/gapit/flags.go +++ b/cmd/gapit/flags.go @@ -335,9 +335,8 @@ type ( Out string `help:"output file to save the profiling result"` } - GraphVisualizationFlags struct { + CreateGraphVisualizationFlags struct { Gapis GapisFlags - Gapir GapirFlags - Out string `help:"path to Save Dot File"` + Out string `help:"path to save graph visualization"` } ) diff --git a/cmd/gapit/graph_visualization.go b/cmd/gapit/graph_visualization.go deleted file mode 100644 index f1b5184048..0000000000 --- a/cmd/gapit/graph_visualization.go +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (C) 2018 Google Inc. -// -// 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 ( - "context" - "flag" - "github.com/google/gapid/core/app" - "github.com/google/gapid/core/log" - "io/ioutil" - "path/filepath" -) - -type graph_visualizationVerb struct{ GraphVisualizationFlags } - -func init() { - verb := &graph_visualizationVerb{} - app.AddVerb(&app.Verb{ - Name: "graph_visualization", - ShortHelp: "Get and Write graph-visualization file from capture", - Action: verb, - }) -} - -func (verb *graph_visualizationVerb) Run(ctx context.Context, flags flag.FlagSet) error { - if flags.NArg() != 1 { - app.Usage(ctx, "Exactly one gfx capture file expected, got %d", flags.NArg()) - return nil - } - - capturePath, err := filepath.Abs(flags.Arg(0)) - if err != nil { - return log.Errf(ctx, err, "Finding file: %v", flags.Arg(0)) - } - - client, err := getGapis(ctx, verb.Gapis, verb.Gapir) - if err != nil { - return log.Err(ctx, err, "Failed to connect to the GAPIS server") - } - defer client.Close() - - capture, err := client.LoadCapture(ctx, capturePath) - if err != nil { - return log.Errf(ctx, err, "LoadCapture(%v)", capturePath) - } - - graphVisualizationFile, err := client.GetGraphVisualizationFile(ctx, capture) - if err != nil { - return log.Errf(ctx, err, "ExportCapture(%v)", capture) - } - - graphVisualizationName := verb.Out - if graphVisualizationName == "" { - graphVisualizationName = "graph_visualizatione.dot" - } - if err := ioutil.WriteFile(graphVisualizationName, []byte(graphVisualizationFile), 0666); err != nil { - return log.Errf(ctx, err, "Writing file: %v", graphVisualizationName) - } - return nil -} diff --git a/gapis/client/client.go b/gapis/client/client.go index 1f2321df28..0133d41013 100644 --- a/gapis/client/client.go +++ b/gapis/client/client.go @@ -485,8 +485,8 @@ func (c *client) GetTimestamps(ctx context.Context, capture *path.Capture, devic return res, nil } -func (c *client) GetGraphVisualizationFile(ctx context.Context, capture *path.Capture) (string, error) { - res, err := c.client.GetGraphVisualizationFile(ctx, &service.GraphVisualizationFileRequest{ +func (c *client) GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error) { + res, err := c.client.GetGraphVisualization(ctx, &service.GraphVisualizationRequest{ Capture: capture, }) if err != nil { @@ -495,5 +495,5 @@ func (c *client) GetGraphVisualizationFile(ctx context.Context, capture *path.Ca if err := res.GetError(); err != nil { return "", err.Get() } - return res.GetGraphVisualizationFile(), nil + return res.GetGraphVisualization(), nil } diff --git a/gapis/resolve/dependencygraph2/graph_visualization/BUILD.bazel b/gapis/resolve/dependencygraph2/graph_visualization/BUILD.bazel index c993020d83..dcf5c1bd3d 100644 --- a/gapis/resolve/dependencygraph2/graph_visualization/BUILD.bazel +++ b/gapis/resolve/dependencygraph2/graph_visualization/BUILD.bazel @@ -20,7 +20,6 @@ go_library( importpath = "github.com/google/gapid/gapis/resolve/dependencygraph2/graph_visualization", visibility = ["//visibility:public"], deps = [ - "//core/log:go_default_library", "//core/math/interval:go_default_library", "//gapis/api:go_default_library", "//gapis/capture:go_default_library", diff --git a/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go b/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go index ceb2cd594a..4532f63144 100644 --- a/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go +++ b/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go @@ -1,17 +1,29 @@ +// Copyright (C) 2018 Google Inc. +// +// 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 graph_visualization import ( "context" - "github.com/google/gapid/core/log" "github.com/google/gapid/core/math/interval" "github.com/google/gapid/gapis/api" "github.com/google/gapid/gapis/capture" "github.com/google/gapid/gapis/resolve/dependencygraph2" ) -func GetGraphVisualizationFileFromCapture(ctx context.Context, p *capture.Capture) (string, error) { +func GetGraphVisualizationFromCapture(ctx context.Context, p *capture.Capture) (string, error) { - log.I(ctx, "Working on GetGraphDotFileFromCapture") config := dependencygraph2.DependencyGraphConfig{} dependencyGraph, err := dependencygraph2.BuildDependencyGraph(ctx, config, p, []api.Cmd{}, interval.U64RangeList{}) _ = dependencyGraph diff --git a/gapis/server/grpc.go b/gapis/server/grpc.go index 6e85413dcb..c395cb6897 100644 --- a/gapis/server/grpc.go +++ b/gapis/server/grpc.go @@ -423,13 +423,13 @@ func (s *grpcServer) DCECapture(ctx xctx.Context, req *service.DCECaptureRequest return &service.DCECaptureResponse{Res: &service.DCECaptureResponse_Capture{Capture: capture}}, nil } -func (s *grpcServer) GetGraphVisualizationFile(ctx xctx.Context, req *service.GraphVisualizationFileRequest) (*service.GraphVisualizationFileResponse, error) { +func (s *grpcServer) GetGraphVisualization(ctx xctx.Context, req *service.GraphVisualizationRequest) (*service.GraphVisualizationResponse, error) { defer s.inRPC()() - graphVisualizationFile, err := s.handler.GetGraphVisualizationFile(s.bindCtx(ctx), req.Capture) + graphVisualization, err := s.handler.GetGraphVisualization(s.bindCtx(ctx), req.Capture) if err := service.NewError(err); err != nil { - return &service.GraphVisualizationFileResponse{Res: &service.GraphVisualizationFileResponse_Error{Error: err}}, nil + return &service.GraphVisualizationResponse{Res: &service.GraphVisualizationResponse_Error{Error: err}}, nil } - return &service.GraphVisualizationFileResponse{Res: &service.GraphVisualizationFileResponse_GraphVisualizationFile{GraphVisualizationFile: graphVisualizationFile}}, nil + return &service.GraphVisualizationResponse{Res: &service.GraphVisualizationResponse_GraphVisualization{GraphVisualization: graphVisualization}}, nil } func (s *grpcServer) GetDevices(ctx xctx.Context, req *service.GetDevicesRequest) (*service.GetDevicesResponse, error) { diff --git a/gapis/server/server.go b/gapis/server/server.go index 3ccfbc21c0..ec2a097e80 100644 --- a/gapis/server/server.go +++ b/gapis/server/server.go @@ -299,17 +299,19 @@ func (s *server) DCECapture(ctx context.Context, p *path.Capture, requested []*p return trimmed, nil } -func (s *server) GetGraphVisualizationFile(ctx context.Context, p *path.Capture) (string, error) { - ctx = log.Enter(ctx, "Inside GetGraphVisualizationFile function") +func (s *server) GetGraphVisualization(ctx context.Context, p *path.Capture) (string, error) { + ctx = status.Start(ctx, "RPC GetGraphVisualization") + defer status.Finish(ctx) + ctx = log.Enter(ctx, "GetGraphVisualization") c, err := capture.ResolveFromPath(ctx, p) if err != nil { return "", err } - graphVisualizationFile, err := graph_visualization.GetGraphVisualizationFileFromCapture(ctx, c) + graphVisualization, err := graph_visualization.GetGraphVisualizationFromCapture(ctx, c) if err != nil { return "", err } - return graphVisualizationFile, nil + return graphVisualization, nil } func (s *server) GetDevices(ctx context.Context) ([]*path.Device, error) { diff --git a/gapis/service/service.go b/gapis/service/service.go index b16b5b3ebc..be85619ddf 100644 --- a/gapis/service/service.go +++ b/gapis/service/service.go @@ -84,7 +84,7 @@ type Service interface { // DCECapture returns a new capture containing only the requested commands and their dependencies. DCECapture(ctx context.Context, capture *path.Capture, commands []*path.Command) (*path.Capture, error) - GetGraphVisualizationFile(ctx context.Context, capture *path.Capture) (string, error) + GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error) // GetDevices returns the full list of replay devices avaliable to the server. // These include local replay devices and any connected Android devices. diff --git a/gapis/service/service.proto b/gapis/service/service.proto index deb20040b6..9be0bde4f8 100644 --- a/gapis/service/service.proto +++ b/gapis/service/service.proto @@ -316,12 +316,12 @@ message DCECaptureResponse { } } -message GraphVisualizationFileRequest { +message GraphVisualizationRequest { path.Capture capture = 1; } -message GraphVisualizationFileResponse { +message GraphVisualizationResponse { oneof res { - string graphVisualizationFile = 1; + string graphVisualization = 1; Error error = 2; } } @@ -563,8 +563,8 @@ service Gapid { rpc DCECapture(DCECaptureRequest) returns (DCECaptureResponse) { } - rpc GetGraphVisualizationFile(GraphVisualizationFileRequest) - returns (GraphVisualizationFileResponse) { + rpc GetGraphVisualization(GraphVisualizationRequest) + returns (GraphVisualizationResponse) { } // GetDevices returns the full list of replay devices avaliable to the server. // These include local replay devices and any connected Android devices.