summaryrefslogtreecommitdiffstats
path: root/llgo
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2015-05-12 22:14:26 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2015-05-12 22:14:26 +0000
commitdd90dc8aa95dbcd59a6dbfa1d192047c9d996008 (patch)
treead21ea5140dde7408a6935b28d5db4a6e92581eb /llgo
parentf47198aa363c2cebb0fac3edb75785b03d17f604 (diff)
downloadbcm5719-llvm-dd90dc8aa95dbcd59a6dbfa1d192047c9d996008.tar.gz
bcm5719-llvm-dd90dc8aa95dbcd59a6dbfa1d192047c9d996008.zip
benchcomp: Add macho_symsizes mode for comparing Mach-O object symbol sizes.
llvm-svn: 237199
Diffstat (limited to 'llgo')
-rw-r--r--llgo/utils/benchcomp/main.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/llgo/utils/benchcomp/main.go b/llgo/utils/benchcomp/main.go
index c7e91c2b273..433add546e1 100644
--- a/llgo/utils/benchcomp/main.go
+++ b/llgo/utils/benchcomp/main.go
@@ -3,8 +3,10 @@ package main
import (
"bufio"
"debug/elf"
+ "debug/macho"
"fmt"
"os"
+ "sort"
"strconv"
"strings"
)
@@ -27,6 +29,50 @@ func symsizes(path string) map[string]float64 {
return m
}
+type bySectionThenOffset []macho.Symbol
+
+func (syms bySectionThenOffset) Len() int {
+ return len(syms)
+}
+
+func (syms bySectionThenOffset) Less(i, j int) bool {
+ if syms[i].Sect < syms[j].Sect {
+ return true
+ }
+ if syms[i].Sect > syms[j].Sect {
+ return false
+ }
+ return syms[i].Value < syms[j].Value
+}
+
+func (syms bySectionThenOffset) Swap(i, j int) {
+ syms[i], syms[j] = syms[j], syms[i]
+}
+
+func macho_symsizes(path string) map[string]float64 {
+ m := make(map[string]float64)
+ f, err := macho.Open(path)
+ if err != nil {
+ panic(err.Error())
+ }
+ syms := make([]macho.Symbol, len(f.Symtab.Syms))
+ copy(syms, f.Symtab.Syms)
+ sort.Sort(bySectionThenOffset(syms))
+ for i, sym := range syms {
+ if sym.Sect == 0 {
+ continue
+ }
+ var nextOffset uint64
+ if i == len(syms)-1 || syms[i+1].Sect != sym.Sect {
+ nextOffset = f.Sections[sym.Sect-1].Size
+ } else {
+ nextOffset = syms[i+1].Value
+ }
+ m[sym.Name] = float64(nextOffset - sym.Value)
+ }
+ return m
+}
+
func benchnums(path, stat string) map[string]float64 {
m := make(map[string]float64)
@@ -70,6 +116,9 @@ func main() {
case "symsizes":
cmp = symsizes
+ case "macho_symsizes":
+ cmp = macho_symsizes
+
case "benchns":
cmp = func(path string) map[string]float64 {
return benchnums(path, "ns/op")
OpenPOWER on IntegriCloud