diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2017-05-26 16:11:54 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2017-05-29 13:15:17 +0200 |
| commit | adc9c8bb06990ffb36b8b1f6a25bd71f8ebe66b0 (patch) | |
| tree | 03b54a4607071f0ae30a4a94d67ffc9e71b7c8c1 /sysgen | |
| parent | b6bb95c0abc1b3f572a04618eb62427b15e3adf5 (diff) | |
sysgen: speed up
Formatting generated sources takes tremendous amount of time (6s).
Leave them unformatted. Reduces sysgen time to virtually 0.
Diffstat (limited to 'sysgen')
| -rw-r--r-- | sysgen/sysgen.go | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/sysgen/sysgen.go b/sysgen/sysgen.go index e47960012..7454ae60c 100644 --- a/sysgen/sysgen.go +++ b/sysgen/sysgen.go @@ -8,12 +8,13 @@ import ( "bytes" "flag" "fmt" - "go/format" "io" "io/ioutil" "os" "path/filepath" "regexp" + "runtime" + "runtime/pprof" "sort" "strconv" "strings" @@ -22,7 +23,10 @@ import ( ) var ( - flagV = flag.Int("v", 0, "verbosity") + flagV = flag.Int("v", 0, "verbosity") + flagMemProfile = flag.String("memprofile", "", "write a memory profile to the file") + + intRegExp = regexp.MustCompile("^int([0-9]+|ptr)(be)?(:[0-9]+)?$") ) const ( @@ -87,6 +91,18 @@ func main() { } generateExecutorSyscalls(desc.Syscalls, consts) + + if *flagMemProfile != "" { + f, err := os.Create(*flagMemProfile) + if err != nil { + failf("could not create memory profile: ", err) + } + runtime.GC() // get up-to-date statistics + if err := pprof.WriteHeapProfile(f); err != nil { + failf("could not write memory profile: ", err) + } + f.Close() + } } func readConsts(arch string) map[string]uint64 { @@ -672,7 +688,6 @@ func generateArg( dir = "in" fmt.Fprintf(out, "&PtrType{%v, Type: %v}", common(), generateType(a[1], a[0], desc, consts)) default: - intRegExp := regexp.MustCompile("^int([0-9]+|ptr)(be)?(:[0-9]+)?$") if intRegExp.MatchString(typ) { canBeArg = true size, bigEndian, bitfieldLen := decodeIntType(typ) @@ -791,12 +806,7 @@ func isIdentifier(s string) bool { return true } -func writeSource(file string, data []byte) { - src, err := format.Source(data) - if err != nil { - fmt.Printf("%s\n", data) - failf("failed to format output: %v", err) - } +func writeSource(file string, src []byte) { if oldSrc, err := ioutil.ReadFile(file); err == nil && bytes.Equal(src, oldSrc) { return } |
