-
Notifications
You must be signed in to change notification settings - Fork 14
/
allochound
executable file
·53 lines (46 loc) · 2.04 KB
/
allochound
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
set -euo pipefail
### Normalize path -- all work should be relative to this script's location.
## Set up gopath -- also relative to this dir, so we work in isolation.
cd "$( dirname "${BASH_SOURCE[0]}" )"
export GOPATH="$PWD/.gopath/"
funcs=()
funcs+=("Benchmark_ArrayFlatIntToJson_Refmt")
funcs+=("Benchmark_ArrayFlatIntToJson_Stdlib")
funcs+=("Benchmark_ArrayFlatStrToJson_Refmt")
funcs+=("Benchmark_ArrayFlatStrToJson_Stdlib")
funcs+=("Benchmark_StructToJson_Refmt")
funcs+=("Benchmark_StructToJson_Stdlib")
profPath=".gopath/tmp/prof/" ; mkdir -p "$profPath"
go test -i .
export GODEBUG=allocfreetrace=1
while read -r -u3 -d' ' func; do
(go test \
-run=XXX -bench=$func \
-count=1
) 2> "$profPath/$func.allocfreetrace" | grep "^Benchmark_"
done 3< <(echo "${funcs[@]} ")
ls -lah "$profPath"/*.allocfreetrace
##
## Recommendations for extracting knowledge:
## - grep for 'refmt' lines with context ~8
## - you really want to get the 'tracealloc' lines in sight, because they list the object type being allocated in plain english
## - to find the beginning of a run, it's currently correct to grep for 'api.go', then find the start of pump.Run,
## then feed that line number back into a grep (where your first grep for refmt lines emits line numbers).
## - you'll see ~3 different line numbers from api.go; the least frequent is the start of Run.
## - grepping ", tok.Token)" is also valid, since we have succeeded at only allocating that once per Run
## (though actually it's a bit of a wonder to me that it doesn't stay on the stack).
##
##
## More generally: want:
## - foreach tracealloc line: that line
## - accept the following '^goroutine' line
## - skip lines matching '^runtime.' and '^t'
## - maybe keep the '^runtime.' lines, because they tell you if 'newObject' vs 'makeSlice'
## - accept two lines -- this is the proximate cause, call and source file.
## - you can probably discard the rest
##
##
## ALTERNATIVELY to all of this:
## just try '-gcflags -m' for things. Result is much shorter, much faster, much more to the point.
##