diff --git a/cmd/gapit/create_graph_visualization.go b/cmd/gapit/create_graph_visualization.go index 3dbb8d8bb6..b2e0f4ea8a 100644 --- a/cmd/gapit/create_graph_visualization.go +++ b/cmd/gapit/create_graph_visualization.go @@ -19,7 +19,6 @@ import ( "flag" "github.com/google/gapid/core/app" "github.com/google/gapid/core/log" - "io/ioutil" "os" ) @@ -50,7 +49,7 @@ func (verb *createGraphVisualizationVerb) Run(ctx context.Context, flags flag.Fl graphVisualization, err := client.GetGraphVisualization(ctx, capture) if err != nil { - return log.Errf(ctx, err, "ExportCapture(%v)", capture) + return log.Errf(ctx, err, "GetGraphVisualization(%v)", capture) } filePath := verb.Out @@ -58,17 +57,15 @@ func (verb *createGraphVisualizationVerb) Run(ctx context.Context, flags flag.Fl 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() + file, err := os.Create(filePath) + if err != nil { + return 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) + bytesWritten, err := file.Write(graphVisualization) + if err != nil { + return log.Errf(ctx, err, "Error after writing %d bytes to file", bytesWritten) } return nil } diff --git a/gapis/client/client.go b/gapis/client/client.go index 0133d41013..4b4e8bbf46 100644 --- a/gapis/client/client.go +++ b/gapis/client/client.go @@ -485,15 +485,15 @@ func (c *client) GetTimestamps(ctx context.Context, capture *path.Capture, devic return res, nil } -func (c *client) GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error) { +func (c *client) GetGraphVisualization(ctx context.Context, capture *path.Capture) ([]byte, error) { res, err := c.client.GetGraphVisualization(ctx, &service.GraphVisualizationRequest{ Capture: capture, }) if err != nil { - return "", err + return []byte{}, err } if err := res.GetError(); err != nil { - return "", err.Get() + return []byte{}, err.Get() } return res.GetGraphVisualization(), nil } diff --git a/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go b/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go index 4532f63144..67198045f9 100644 --- a/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go +++ b/gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go @@ -22,11 +22,11 @@ import ( "github.com/google/gapid/gapis/resolve/dependencygraph2" ) -func GetGraphVisualizationFromCapture(ctx context.Context, p *capture.Capture) (string, error) { +func GetGraphVisualizationFromCapture(ctx context.Context, p *capture.Capture) ([]byte, error) { config := dependencygraph2.DependencyGraphConfig{} dependencyGraph, err := dependencygraph2.BuildDependencyGraph(ctx, config, p, []api.Cmd{}, interval.U64RangeList{}) _ = dependencyGraph - return "OutputFile", err + return []byte("OutputFile"), err } diff --git a/gapis/server/server.go b/gapis/server/server.go index ec2a097e80..c6651f870a 100644 --- a/gapis/server/server.go +++ b/gapis/server/server.go @@ -63,6 +63,10 @@ import ( _ "github.com/google/gapid/gapis/api/all" ) +const ( + FILE_SIZE_LIMIT_IN_BYTES = 2147483647 +) + // Config holds the server configuration settings. type Config struct { Info *service.ServerInfo @@ -299,17 +303,20 @@ func (s *server) DCECapture(ctx context.Context, p *path.Capture, requested []*p return trimmed, nil } -func (s *server) GetGraphVisualization(ctx context.Context, p *path.Capture) (string, error) { +func (s *server) GetGraphVisualization(ctx context.Context, p *path.Capture) ([]byte, 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 + return []byte{}, err } graphVisualization, err := graph_visualization.GetGraphVisualizationFromCapture(ctx, c) if err != nil { - return "", err + return []byte{}, err + } + if len(graphVisualization) > FILE_SIZE_LIMIT_IN_BYTES { + return []byte{}, log.Errf(ctx, err, "The file size for graph visualization exceeds %d bytes", FILE_SIZE_LIMIT_IN_BYTES) } return graphVisualization, nil } diff --git a/gapis/service/service.go b/gapis/service/service.go index be85619ddf..a99051be03 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) - GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error) + GetGraphVisualization(ctx context.Context, capture *path.Capture) ([]byte, 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 9be0bde4f8..df92b1458f 100644 --- a/gapis/service/service.proto +++ b/gapis/service/service.proto @@ -321,7 +321,7 @@ message GraphVisualizationRequest { } message GraphVisualizationResponse { oneof res { - string graphVisualization = 1; + bytes graphVisualization = 1; Error error = 2; } }