diff options
author | Colin Cross <ccross@android.com> | 2018-09-27 15:04:24 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2018-09-28 13:56:06 -0700 |
commit | b051ab5cb54f8802807680a8fb24092b445a3ddb (patch) | |
tree | de11d0cb17d8addfdebe00b93b1eef840ab6c01b /zip | |
parent | fe945b4401a839cc7b177d4d745ab64c8347d93a (diff) | |
download | build_soong-b051ab5cb54f8802807680a8fb24092b445a3ddb.tar.gz build_soong-b051ab5cb54f8802807680a8fb24092b445a3ddb.tar.bz2 build_soong-b051ab5cb54f8802807680a8fb24092b445a3ddb.zip |
soong_zip: move profiling from zip library to soong_zip
Profiling is only used by the standalone soong_zip command,
move it out of the shared zip library.
Bug: 116751500
Test: m checkbuild
Change-Id: I443c34fb39cf8955e163a7720d6f7ed585e4172a
Diffstat (limited to 'zip')
-rw-r--r-- | zip/cmd/main.go | 30 | ||||
-rw-r--r-- | zip/zip.go | 30 |
2 files changed, 28 insertions, 32 deletions
diff --git a/zip/cmd/main.go b/zip/cmd/main.go index e379b07f..a2fbf411 100644 --- a/zip/cmd/main.go +++ b/zip/cmd/main.go @@ -20,6 +20,8 @@ import ( "io/ioutil" "os" "runtime" + "runtime/pprof" + "runtime/trace" "strconv" "strings" @@ -154,6 +156,32 @@ func main() { flags.Usage() } + if *cpuProfile != "" { + f, err := os.Create(*cpuProfile) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + defer f.Close() + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } + + if *traceFile != "" { + f, err := os.Create(*traceFile) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + defer f.Close() + err = trace.Start(f) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + defer trace.Stop() + } + if fileArgsBuilder.Error() != nil { fmt.Fprintln(os.Stderr, fileArgsBuilder.Error()) os.Exit(1) @@ -162,8 +190,6 @@ func main() { err := zip.Run(zip.ZipArgs{ FileArgs: fileArgsBuilder.FileArgs(), OutputFilePath: *out, - CpuProfileFilePath: *cpuProfile, - TraceFilePath: *traceFile, EmulateJar: *emulateJar, AddDirectoryEntriesToZip: *directories, CompressionLevel: *compLevel, @@ -25,8 +25,6 @@ import ( "log" "os" "path/filepath" - "runtime/pprof" - "runtime/trace" "sort" "strings" "sync" @@ -196,8 +194,6 @@ type zipEntry struct { type ZipArgs struct { FileArgs []FileArg OutputFilePath string - CpuProfileFilePath string - TraceFilePath string EmulateJar bool AddDirectoryEntriesToZip bool CompressionLevel int @@ -251,32 +247,6 @@ func ReadRespFile(bytes []byte) []string { } func Run(args ZipArgs) (err error) { - if args.CpuProfileFilePath != "" { - f, err := os.Create(args.CpuProfileFilePath) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - defer f.Close() - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() - } - - if args.TraceFilePath != "" { - f, err := os.Create(args.TraceFilePath) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - defer f.Close() - err = trace.Start(f) - if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) - } - defer trace.Stop() - } - if args.OutputFilePath == "" { return fmt.Errorf("output file path must be nonempty") } |