-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutate_profile.go
53 lines (44 loc) · 1023 Bytes
/
mutate_profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"github.com/google/pprof/profile"
)
var profileFile = flag.String("profile", "", "The profile to mutate.")
var outFile = flag.String("output", "", "The mutated profile file to write. By default, appends '.mutated' to input profile.")
func parse() (*profile.Profile, error) {
f, err := os.Open(*profileFile)
if err != nil {
return nil, fmt.Errorf("failed to open %q: %w", *profileFile, err)
}
return profile.Parse(f)
}
func write(prof *profile.Profile) error {
fName := *outFile
if fName == "" {
fName = *profileFile + ".mutated"
}
f, err := os.Create(fName)
if err != nil {
return err
}
return prof.Write(f)
}
func main() {
flag.Parse()
prof, err := parse()
if err != nil {
log.Fatal(err)
}
// Mutations on the profile.
for _, f := range prof.Function {
f.Name = strings.ReplaceAll(f.Name, "[...]", "")
f.Name = strings.ReplaceAll(f.Name, "*filter", "*Filter")
}
if err := write(prof); err != nil {
log.Fatal(err)
}
}