Skip to content

Instantly share code, notes, and snippets.

@awreece
awreece / gist:2563735
Created April 30, 2012 23:53
Bad go build
$ go build -v
$ go tool dist install -v
$ hg diff malloc.goc
diff -r 4875dfefc730 src/pkg/runtime/malloc.goc
--- a/src/pkg/runtime/malloc.goc Mon Apr 16 10:25:20 2012 -0700
+++ b/src/pkg/runtime/malloc.goc Mon Apr 30 19:52:32 2012 -0400
@@ -25,7 +25,7 @@
// Small objects are allocated from the per-thread cache's free lists.
// Large objects (> 32 kB) are allocated straight from the heap.
void*
@awreece
awreece / Makefile
Created May 1, 2012 15:18
Difference between C and Go
all: run_c run_go
.PHONY: run_c run_go
run_c : sleep_10_ms_c
bash catproc.bash $<
run_go : sleep_10_ms_go
bash catproc.bash $<
@awreece
awreece / gist:2569437
Created May 1, 2012 16:31
Print Stack in main
areece@areece-laptop:/tmp$ gdb temp
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
areece@areece-laptop:/tmp$ gdb temp
Reading symbols from /tmp/temp...done.
Loading Go Runtime support.
(gdb) b main.main
Breakpoint 1 at 0x8048c00: file /tmp/temp.go, line 2.
(gdb) r
Starting program: /tmp/temp
[New LWP 6919]
[Switching to LWP 6919]
assert(sizeof(uintptr_t) == 8);
assert(sizeof(unsigned long long) == 8);
uintptr_t x = 0xffffffff80000000ULL;
x ^= (1 << 31);
printf("%llx\n", x);
$ ltrace -x malloc /usr/lib/firefox/firefox
WARNING: Couldn't find symbol "malloc" in file "/usr/lib/firefox/firefox"
--- SIGCHLD (Child exited) ---
+++ exited (status 0) +++
$ ./command-line-arguments.test --test.bench="Bench"
testing: warning: no tests to run
PASS
BenchmarkConcat 50000 46822 ns/op
BenchmarkJoin 200000 9121 ns/op
BenchmarkBuffer 200000 10764 ns/op
1336443958168278000 0] malloc 32 -> 0x1883bb40
1336443958168298000 0] malloc 48 -> 0x18895e70
1336443958168318000 0] malloc 64 -> 0x1883ecc0
1336443958168340000 0] malloc 208 -> 0x189d0000
1336443958168364000 4] free 0x1885fd20
1336443958168379000 4] free 0x1885fd20
1336443958168396000 4] malloc 96 -> 0x1885fd20
1336443958168418000 0] free 0x18844d80
1336443958168433000 0] free 0x18844d80
1336443958168448000 0] malloc 128 -> 0x18844d80
$ for t in build get main; do python parse.py $t.trace; done
# a trace of "go build file"
Malloc trace of 75809 mallocs over 5 cores
Cache line shared 2266 (2.99%) times
Cache line cold missed 12022 (15.86%) times
# a trace of "go get package"
Malloc trace of 163991 mallocs over 4 cores
Cache line shared 7507 (4.58%) times
@awreece
awreece / parse.go
Created May 12, 2012 03:08
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