Skip to content

Instantly share code, notes, and snippets.

@NicolasT
Last active December 15, 2015 00:19
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save NicolasT/5172330 to your computer and use it in GitHub Desktop.
OCaml SystemTap probes
[nicolas@tau OCaml]$ cat demogc.ml
let main () =
let rec loop = function
| 0 -> ()
| n -> let _ = Array.make 1024 1 in
loop (n - 1)
in
loop 1024
;;
main ()
[nicolas@tau OCaml]$ ./4.00.1/bin/ocamlbuild demogc.native
Finished, 4 targets (0 cached) in 00:00:00.
[nicolas@tau OCaml]$ stap -L 'process("demogc.native").mark("*")'
process("demogc.native").mark("minor_collection__entry") $arg1:long
process("demogc.native").mark("minor_collection__return") $arg1:long
[nicolas@tau OCaml]$ cat gc.stp
probe process.provider("camlgc").mark("minor_collection__entry") {
printf("%s.%s: allocated words = %d\n", $$provider, $$name, $arg1);
}
probe process.provider("camlgc").mark("minor_collection__return") {
printf("%s.%s: promoted words = %d\n", $$provider, $$name, $arg1);
}
[nicolas@tau OCaml]$ stap -c ./demogc.native gc.stp
camlgc.minor_collection__entry: allocated words = 262409
camlgc.minor_collection__return: promoted words = 23
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
nicolas@tau OCaml]$ cat demogc.ml
let main () =
let rec loop = function
| 0 -> ()
| n -> let _ = Array.make 1024 1 in
loop (n - 1)
in
loop 1024
;;
main ()
[nicolas@tau OCaml]$ ./4.00.1/bin/ocamlbuild demogc.native
Finished, 4 targets (0 cached) in 00:00:00.
[nicolas@tau OCaml]$ stap -L 'process("demogc.native").mark("*")' | grep Demogc
process("demogc.native").mark("camlDemogc__entry")
process("demogc.native").mark("camlDemogc__loop_1009")
process("demogc.native").mark("camlDemogc__main_1008")
[nicolas@tau OCaml]$ cat gc.stp
global loopcnt = 0
probe process.provider("camlgc").mark("minor_collection__entry") {
printf("Hit minor GC collection after %u loop iterations\n", loopcnt);
loopcnt = 0;
printf("%s.%s: allocated words = %d\n", $$provider, $$name, $arg1);
}
probe process.provider("camlgc").mark("minor_collection__return") {
printf("%s.%s: promoted words = %d\n", $$provider, $$name, $arg1);
}
probe process.provider("camlfun").mark("camlDemogc__loop_1009") {
loopcnt++;
}
[nicolas@tau OCaml]$ stap gc.stp -c ./demogc.native
Hit minor GC collection after 256 loop iterations
camlgc.minor_collection__entry: allocated words = 262409
camlgc.minor_collection__return: promoted words = 23
Hit minor GC collection after 256 loop iterations
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
Hit minor GC collection after 256 loop iterations
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
Hit minor GC collection after 256 loop iterations
camlgc.minor_collection__entry: allocated words = 262400
camlgc.minor_collection__return: promoted words = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment