Debian Codegraph @

dev/doc/profiling.md

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 # How to profile Rocq?
2
3 I (Pierre-Marie Pédrot) mainly use two OCaml branches to profile Rocq, whether I
4 want to profile time or memory consumption. AFAIK, this only works for Linux.
5
6 ## Time
7
8 In Rocq source folder:
9
10 ```
11 opam switch 4.14.0+trunk+fp
12 make world
13 perf record -g _build/install/default/bin/coqc file.v
14 perf report -g fractal,callee --no-children
15 ```
16
17 To profile only part of a file, first load it using
18
19 ```
20 bin/coqtop -l file.v
21 ```
22
23 and plug into the process
24
25 ```
26 perf record -g -p PID
27 ```
28
29 ### Per-component [flame graphs](https://github.com/brendangregg/FlameGraph)
30
31 I (Andres Erbsen) have found it useful to look at library-wide flame graphs of
32 rocq time consumption. As the Ltac interpreter stack is reflected in the OCaml
33 stack, calls to the same primitive can appear on top of multiple essentially
34 equivalent stacks. To make the profiles more readable, one could either try to
35 edit the stack trace to merge "equivalent" frames, or simply look at the
36 aggregate profile on a component-by-component basis. Here is how to do the
37 second for the standard library ([example output](https://cdn.rawgit.com/andres-erbsen/b29b29cb6480dfc6a662062e4fcd0ae3/raw/304fc3fea9630c8e453929aa7920ca8a2a570d0b/stdlib_categorized_outermost.svg)).
38
39 ```
40 #!/usr/bin/env bash
41 make clean
42 make states
43 perf record -F99 `# ~1GB of data` --call-graph=dwarf -- make world
44 perf script --time '0%-100%' |
45 stackcollapse-perf.pl |
46 grep Coqtop__compile |
47 sed -rf <(cat <<'EOF'
48 s/;caml/;/g
49 s/_[0-9]*;/;/g
50 s/Logic_monad__fun;//g
51 s/_apply[0-9];//g
52 s/;System/@&@/
53 s/;Hashcons/@&@/
54 s/;Grammar/@&@/
55 s/;Declaremods/@&@/
56 s/;Tactics/@&@/
57 s/;Pretyping/@&@/
58 s/;Typeops/@&@/
59 s/;Reduction/@&@/
60 s/;Unification/@&@/
61 s/;Evarutil/@&@/
62 s/;Evd/@&@/
63 s/;EConstr/@&@/
64 s/;Constr/@&@/
65 s/;Univ/@&@/
66 s/;Ugraph/@&@/
67 s/;UState/@&@/
68 s/;Micromega/@&@/
69 s/;Omega/@&@/
70 s/;Auto/@&@/
71 s/;Ltac_plugin__Tacinterp/@&@/
72 s/;Ltac_plugin__Rewrite/@&@/
73 s/[^@]*@;([^@]*)@/\1;\1/
74 s/@//g
75 :a; s/;([^;]+);\1;/;\1;/g;ta
76 EOF
77 ) |
78 flamegraph.pl
79 ```
80
81 ## Memory (memtrace)
82
83 [memtrace](https://github.com/janestreet/memtrace) is a client library
84 for OCaml's Memprof statistical memory profiler.
85
86 See this blog post for more details:
87 https://blog.janestreet.com/finding-memory-leaks-with-memtrace/
88
89 To profile a file, you need to install the `memtrace` library, then
90 recompile Rocq. We also recommend you make a copy of the .v file (if
91 working on the stdlib to avoid issues with artifacts.
92
93 The following command sequence will do all that:
94 ```
95 opam install memtrace
96 make world # to build deps
97 cp theories/Corelib/Classes/RelationClasses.v /tmp
98 MEMTRACE=trace-byte.tcr dune exec -- rocq c /tmp/RelationClasses.v
99 memtrace-viewer trace-byte.tcr
100 ```