Skip to content

Commit 45492c7

Browse files
xaionaro@dx.centerxaionaro@dx.center
authored andcommitted
feat: add cpuprofile and memprofile flags to genparcelspec
1 parent a7449c6 commit 45492c7

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

tools/cmd/genparcelspec/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"os"
77
"path/filepath"
8+
"runtime/pprof"
89
"strings"
910

1011
"github.com/xaionaro-go/binder/tools/pkg/parcelspec"
@@ -14,12 +15,35 @@ import (
1415
func main() {
1516
frameworksBase := flag.String("frameworks-base", "tools/pkg/3rdparty/frameworks-base", "Path to the AOSP frameworks-base directory")
1617
output := flag.String("output", "parcelspecs", "Output directory for YAML spec files")
18+
cpuProfile := flag.String("cpuprofile", "", "Write CPU profile to file")
19+
memProfile := flag.String("memprofile", "", "Write memory profile to file")
1720
flag.Parse()
1821

22+
if *cpuProfile != "" {
23+
f, err := os.Create(*cpuProfile)
24+
if err != nil {
25+
fmt.Fprintf(os.Stderr, "Error creating CPU profile: %v\n", err)
26+
os.Exit(1)
27+
}
28+
defer f.Close()
29+
pprof.StartCPUProfile(f)
30+
defer pprof.StopCPUProfile()
31+
}
32+
1933
if err := run(*frameworksBase, *output); err != nil {
2034
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
2135
os.Exit(1)
2236
}
37+
38+
if *memProfile != "" {
39+
f, err := os.Create(*memProfile)
40+
if err != nil {
41+
fmt.Fprintf(os.Stderr, "Error creating memory profile: %v\n", err)
42+
os.Exit(1)
43+
}
44+
defer f.Close()
45+
pprof.WriteHeapProfile(f)
46+
}
2347
}
2448

2549
func run(

0 commit comments

Comments
 (0)