Skip to content

Instantly share code, notes, and snippets.

@awreece
Created May 12, 2012 03:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save awreece/2663872 to your computer and use it in GitHub Desktop.
Save awreece/2663872 to your computer and use it in GitHub Desktop.
Go memory allocation distribtuion
$ cat *.trace | ./parse | sort -n
# allocation_size number_of_requests
1 2
3 3
8 71084
9 1
12 4
13 34
16 59685
32 35643
38 1
48 20403
64 34660
80 10656
96 12334
112 1322
128 3648
133 9
144 828
160 2608
176 53
192 1358
208 603
224 95
240 15
256 2615
288 220
320 186
352 11
384 325
448 27
512 1745
576 60
640 31
704 11
768 61
832 337
1024 135
1152 57
1280 76
1408 85
1536 1479
1664 27
2048 89
2304 21
2560 13
3072 9
3328 12
4096 1316
4352 1
4608 2
5120 5
6144 138
6656 1
8192 704
8704 5
10240 5
12288 3
13364 1
14080 1
16384 345
17664 46
21248 1
32768 136
36864 21
40960 1
49152 1
65536 43
69632 2
98304 6
131072 10
221184 1
237568 1
262144 7
307200 2
393216 6
614400 5
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
b := bufio.NewReader(os.Stdin)
smap := make(map[int]int)
line, _, err := b.ReadLine()
for ; err == nil; line, _, err = b.ReadLine() {
s := strings.Split(string(line), " ")
size, _ := strconv.Atoi(s[3])
if oldc, p := smap[size]; p {
smap[size] = oldc + 1
} else {
smap[size] = 1
}
}
for size, count := range smap {
fmt.Println(size, count)
}
}
$ hg diff
diff -r 9a55b03991e3 src/pkg/runtime/malloc.goc
--- a/src/pkg/runtime/malloc.goc Mon Apr 09 15:39:59 2012 -0400
+++ b/src/pkg/runtime/malloc.goc Thu May 10 22:41:03 2012 -0400
@@ -93,6 +93,7 @@
}
}
+ runtime·printf("%D %d] malloc %d -> %p\n", runtime·nanotime(), m->id, size, v);
if(dogc && mstats.heap_alloc >= mstats.next_gc)
runtime·gc(0);
return v;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment