Skip to content

Commit

Permalink
Add -memprofile option to l-tm
Browse files Browse the repository at this point in the history
For profiling memory allocations used for producing reproducible
instructions for analysing allocations.

Usage:

This command collects a profile:

```
l-tm -memprofile=mem.pprof <input llvm>
```

This one loads pprof in a mode showing all allocations that occurred by
count (rather than by size, which is alloc_space).

```
go tool pprof -sample_index=alloc_objects mem.pprof
```

Useful commands thereafter: `top10` or `web`.
  • Loading branch information
pwaller committed Dec 9, 2018
1 parent bc6a508 commit 4d63f0c
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions cmd/l-tm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ import (
"fmt"
"log"
"os"
"runtime"
"runtime/pprof"
"time"

"github.com/llir/llvm/asm"
)

func main() {
var cpuprofile string
flag.StringVar(&cpuprofile, "cpuprofile", "", "write cpu profile to file")
var (
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
memprofile = flag.String("memprofile", "", "write mem profile to file")
)
flag.Parse()
if cpuprofile != "" {
f, err := os.Create(cpuprofile)

if *cpuprofile != "" {
fd, err := os.Create(*cpuprofile)
if err != nil {
log.Fatalf("%+v", err)
}
pprof.StartCPUProfile(f)
pprof.StartCPUProfile(fd)
defer pprof.StopCPUProfile()
}

if *memprofile != "" {
runtime.MemProfileRate = 1
}

for _, llPath := range flag.Args() {
fmt.Printf("=== [ %v ] =======================\n", llPath)
fmt.Println()
Expand All @@ -35,4 +44,17 @@ func main() {
_ = m
//pretty.Println(m)
}

if *memprofile != "" {
fd, err := os.Create(*memprofile)
if err != nil {
log.Fatalf("%+v", err)
}
runtime.GC()
err = pprof.WriteHeapProfile(fd)
if err != nil {
log.Fatalf("WriteHeapProfile: %v", err)
}

}
}

0 comments on commit 4d63f0c

Please sign in to comment.