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
diff --git a/zip/cmd/main.go b/zip/cmd/main.go
index e379b07..a2fbf41 100644
--- a/zip/cmd/main.go
+++ b/zip/cmd/main.go
@@ -20,6 +20,8 @@
"io/ioutil"
"os"
"runtime"
+ "runtime/pprof"
+ "runtime/trace"
"strconv"
"strings"
@@ -154,6 +156,32 @@
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 @@
err := zip.Run(zip.ZipArgs{
FileArgs: fileArgsBuilder.FileArgs(),
OutputFilePath: *out,
- CpuProfileFilePath: *cpuProfile,
- TraceFilePath: *traceFile,
EmulateJar: *emulateJar,
AddDirectoryEntriesToZip: *directories,
CompressionLevel: *compLevel,