aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorRob Pike <r@golang.org>2014-01-08 15:56:40 -0800
committerRob Pike <r@golang.org>2014-01-08 15:56:40 -0800
commitfca453e062a39f64b0760aa4555bb974f504aba3 (patch)
tree478465ad1f55af5baa7603551022cecd7a0d752b /src/cmd
parent43108ee53a62bdbafc16a1224eeed3c0e2fa71a6 (diff)
downloadgo-fca453e062a39f64b0760aa4555bb974f504aba3.tar.xz
cmd/nm: add -sort=size
When printing the size, we often want to sort on that key. Because it's used when looking for large things, make the sort go from largest to smallest. Perfect recreation of CL 45150044, which was lost to some blunder. R=golang-codereviews, gobot, rsc CC=golang-codereviews https://golang.org/cl/48500044
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/nm/doc.go3
-rw-r--r--src/cmd/nm/nm.go10
2 files changed, 11 insertions, 2 deletions
diff --git a/src/cmd/nm/doc.go b/src/cmd/nm/doc.go
index f40073f7a2..81662f8721 100644
--- a/src/cmd/nm/doc.go
+++ b/src/cmd/nm/doc.go
@@ -31,8 +31,9 @@
// for compatibility with other nm commands
// -size
// print symbol size in decimal between address and type
-// -sort {address,name,none}
+// -sort {address,name,none,size}
// sort output in the given order (default name)
+// size orders from largest to smallest
// -type
// print symbol type after name
//
diff --git a/src/cmd/nm/nm.go b/src/cmd/nm/nm.go
index d369a4ab54..fdf6ef673e 100644
--- a/src/cmd/nm/nm.go
+++ b/src/cmd/nm/nm.go
@@ -58,7 +58,7 @@ func main() {
flag.Parse()
switch *sortOrder {
- case "address", "name", "none":
+ case "address", "name", "none", "size":
// ok
default:
fmt.Fprintf(os.Stderr, "nm: unknown sort order %q\n", *sortOrder)
@@ -135,6 +135,8 @@ HaveSyms:
sort.Sort(byAddr(syms))
case "name":
sort.Sort(byName(syms))
+ case "size":
+ sort.Sort(bySize(syms))
}
w := bufio.NewWriter(os.Stdout)
@@ -170,3 +172,9 @@ type byName []Sym
func (x byName) Len() int { return len(x) }
func (x byName) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
func (x byName) Less(i, j int) bool { return x[i].Name < x[j].Name }
+
+type bySize []Sym
+
+func (x bySize) Len() int { return len(x) }
+func (x bySize) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
+func (x bySize) Less(i, j int) bool { return x[i].Size > x[j].Size }