Skip to content

Commit c6eaca1

Browse files
elviscapiaqbjoeris
authored andcommitted
Response to changes requested
Added GetGraphVisualizationFile function in the entire pipeline of Gapid.
1 parent ef4bedc commit c6eaca1

File tree

6 files changed

+25
-21
lines changed

6 files changed

+25
-21
lines changed

cmd/gapit/create_graph_visualization.go

+8-11
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"flag"
2020
"github.com/google/gapid/core/app"
2121
"github.com/google/gapid/core/log"
22-
"io/ioutil"
2322
"os"
2423
)
2524

@@ -50,25 +49,23 @@ func (verb *createGraphVisualizationVerb) Run(ctx context.Context, flags flag.Fl
5049

5150
graphVisualization, err := client.GetGraphVisualization(ctx, capture)
5251
if err != nil {
53-
return log.Errf(ctx, err, "ExportCapture(%v)", capture)
52+
return log.Errf(ctx, err, "GetGraphVisualization(%v)", capture)
5453
}
5554

5655
filePath := verb.Out
5756
if filePath == "" {
5857
filePath = "graph_visualization.dot"
5958
}
6059

61-
_, err = os.Stat(filePath)
62-
if os.IsNotExist(err) {
63-
file, err := os.Create(filePath)
64-
if err != nil {
65-
log.Errf(ctx, err, "Creating file (%v)", filePath)
66-
}
67-
defer file.Close()
60+
file, err := os.Create(filePath)
61+
if err != nil {
62+
return log.Errf(ctx, err, "Creating file (%v)", filePath)
6863
}
64+
defer file.Close()
6965

70-
if err := ioutil.WriteFile(filePath, []byte(graphVisualization), 0666); err != nil {
71-
return log.Errf(ctx, err, "Writing file: %v", filePath)
66+
bytesWritten, err := file.Write(graphVisualization)
67+
if err != nil {
68+
return log.Errf(ctx, err, "Error after writing %d bytes to file", bytesWritten)
7269
}
7370
return nil
7471
}

gapis/client/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -485,15 +485,15 @@ func (c *client) GetTimestamps(ctx context.Context, capture *path.Capture, devic
485485
return res, nil
486486
}
487487

488-
func (c *client) GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error) {
488+
func (c *client) GetGraphVisualization(ctx context.Context, capture *path.Capture) ([]byte, error) {
489489
res, err := c.client.GetGraphVisualization(ctx, &service.GraphVisualizationRequest{
490490
Capture: capture,
491491
})
492492
if err != nil {
493-
return "", err
493+
return []byte{}, err
494494
}
495495
if err := res.GetError(); err != nil {
496-
return "", err.Get()
496+
return []byte{}, err.Get()
497497
}
498498
return res.GetGraphVisualization(), nil
499499
}

gapis/resolve/dependencygraph2/graph_visualization/graph_visualization.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
"github.com/google/gapid/gapis/resolve/dependencygraph2"
2323
)
2424

25-
func GetGraphVisualizationFromCapture(ctx context.Context, p *capture.Capture) (string, error) {
25+
func GetGraphVisualizationFromCapture(ctx context.Context, p *capture.Capture) ([]byte, error) {
2626

2727
config := dependencygraph2.DependencyGraphConfig{}
2828
dependencyGraph, err := dependencygraph2.BuildDependencyGraph(ctx, config, p, []api.Cmd{}, interval.U64RangeList{})
2929
_ = dependencyGraph
3030

31-
return "OutputFile", err
31+
return []byte("OutputFile"), err
3232
}

gapis/server/server.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ import (
6363
_ "github.com/google/gapid/gapis/api/all"
6464
)
6565

66+
const (
67+
FILE_SIZE_LIMIT_IN_BYTES = 2147483647
68+
)
69+
6670
// Config holds the server configuration settings.
6771
type Config struct {
6872
Info *service.ServerInfo
@@ -299,17 +303,20 @@ func (s *server) DCECapture(ctx context.Context, p *path.Capture, requested []*p
299303
return trimmed, nil
300304
}
301305

302-
func (s *server) GetGraphVisualization(ctx context.Context, p *path.Capture) (string, error) {
306+
func (s *server) GetGraphVisualization(ctx context.Context, p *path.Capture) ([]byte, error) {
303307
ctx = status.Start(ctx, "RPC GetGraphVisualization")
304308
defer status.Finish(ctx)
305309
ctx = log.Enter(ctx, "GetGraphVisualization")
306310
c, err := capture.ResolveFromPath(ctx, p)
307311
if err != nil {
308-
return "", err
312+
return []byte{}, err
309313
}
310314
graphVisualization, err := graph_visualization.GetGraphVisualizationFromCapture(ctx, c)
311315
if err != nil {
312-
return "", err
316+
return []byte{}, err
317+
}
318+
if len(graphVisualization) > FILE_SIZE_LIMIT_IN_BYTES {
319+
return []byte{}, log.Errf(ctx, err, "The file size for graph visualization exceeds %d bytes", FILE_SIZE_LIMIT_IN_BYTES)
313320
}
314321
return graphVisualization, nil
315322
}

gapis/service/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type Service interface {
8484
// DCECapture returns a new capture containing only the requested commands and their dependencies.
8585
DCECapture(ctx context.Context, capture *path.Capture, commands []*path.Command) (*path.Capture, error)
8686

87-
GetGraphVisualization(ctx context.Context, capture *path.Capture) (string, error)
87+
GetGraphVisualization(ctx context.Context, capture *path.Capture) ([]byte, error)
8888

8989
// GetDevices returns the full list of replay devices avaliable to the server.
9090
// These include local replay devices and any connected Android devices.

gapis/service/service.proto

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ message GraphVisualizationRequest {
321321
}
322322
message GraphVisualizationResponse {
323323
oneof res {
324-
string graphVisualization = 1;
324+
bytes graphVisualization = 1;
325325
Error error = 2;
326326
}
327327
}

0 commit comments

Comments
 (0)