Debian Codegraph @

doc/HOWTO-gperftools.adoc

raw
1 = How to monitor and tune Gauche runtime and VM
2
3 In order to monitor and tune Gauche runtime and VM, we support to link
4 link:https://github.com/gperftools/gperftools[gperftools] to Gauche.
5
6 (NB: If you want to profile and tune Scheme programs, use Gauche's
7 profiling option instead. See
8 link:http://practical-scheme.net/gauche/man/?l=en&p=Profiling%20and%20tuning[Profiling and tuning]
9 section of the manual.)
10
11
12 == Prerequisites
13
14 You need gperftools installed on your machine. The source is available
15 in the above url. On Debian/Ubuntu, you can get it with apt:
16
17 [source,console]
18 ----
19 # apt-get install google-perftools libgoogle-perftools-dev
20 ----
21
22
23 == Build:
24
25 To link gperftools, give `--with-gperftools` option to `./configure`:
26
27 [source,console]
28 ----
29 $ ./configure --with-gperftools
30 ----
31
32 Just linking gperftools doesn't affect much on runtime, but the behavior
33 of the program can be modified with environment variables, so we recommend
34 you not to use it for production releases.
35
36 Note that if you compile with this option, `SIGPROF` is reserved to
37 gperftools and not available for Scheme programs.
38
39
40 == Profile
41
42 When linked with gperftools, you can turn on CPU profiler by giving
43 a profile output filename to the environment variable `CPUPROFILE`.
44
45 [source,console]
46 ----
47 $ env CPUPROFILE=prof.out gosh <arguments> ...
48 ----
49
50 After `gosh` exits, profiling data is dumped to `prof.out` in the above
51 example.
52
53 Browsing the data is done by `pprof` tool. Note that, on Ubuntu, it is
54 named `google-pprof` to avoid name conflict.
55
56 This shows call graph and sample analysis (replace `gosh` path appropriately):
57
58 [source,console]
59 ----
60 $ pprof --gv /usr/local/bin/gosh prof.out
61 ----
62
63 This shows samples per line, along the source code:
64
65 [source,console]
66 ----
67 $ pprof --list=<function-name> gosh prof.out
68 ----
69
70 And this shows samples per instruction:
71
72 [source,console]
73 ----
74 $ pprof --disasm=<function-name> gosh prof.out
75 ----
76
77 NB: Some versions of gperftools dumps the profiler output to a
78 file prof.out_{PID} where PID is the profiled process id. If that's the
79 case, prof.out itself is empty. Check the directory before referring
80 to the profiler output.