ruricolist / cl-flamegraph

A wrapper around SBCL's statistical profiler, to generate FlameGraph charts for Common Lisp programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cl-flamegraph

Rationale

Flamegraphs are a cool way to search for hotspots in your code.

images/quickload.svg

images/speedscope-flamegraph.gif

Installation

Setup an Ultralisp.org distribution:

(ql-dist:install-dist "http://dist.ultralisp.org/"
                      :prompt nil)

Or clone repository to your ~/quicklisp/local-projects folder.

Then install the system:

(ql:quickload :flamegraph)

Download the FlameGraph chart generator. It is written in Perl. This tool prepares data in a simple text format that can be processed by the flamegraph.pl script to generate an SVG diagram.

Or you can upload results to the Speedscope.app site and inspect it in the browser!

Usage

Wrap the code with flamegraph:save-flame-graph macro:

CL-USER> (defun foo ()
           (sleep 0.01))
FOO
CL-USER> (defun bar ()
           (sleep 0.05))
BAR
CL-USER> (defun blah ()
           (loop repeat 1000
                 do (foo)
                    (bar)))
BLAH
CL-USER> (flamegraph:save-flame-graph ("/tmp/foo.stack")
           (blah))
; No values

This will generate a file with the content:

BLAH 8
BLAH;BAR 5
BLAH;BAR;NANOSLEEP 5
BLAH;BAR;NANOSLEEP;foreign function __syscall 2
BLAH;BAR;NANOSLEEP;foreign function sb_nanosleep 3
BLAH;BAR;NANOSLEEP;foreign function sb_nanosleep;foreign function clock_get_time 3
BLAH;BAR;NANOSLEEP;foreign function sb_nanosleep;foreign function clock_get_time;foreign function mach_msg_trap 3
BLAH;FOO 3
BLAH;FOO;NANOSLEEP 3
BLAH;FOO;NANOSLEEP;foreign function __syscall 1
BLAH;FOO;NANOSLEEP;foreign function sb_nanosleep 2
BLAH;FOO;NANOSLEEP;foreign function sb_nanosleep;foreign function clock_get_time 2
BLAH;FOO;NANOSLEEP;foreign function sb_nanosleep;foreign function clock_get_time;foreign function mach_msg_trap 2

Pipe it through flamegraph.pl to get a nice SVG:

cat /tmp/foo.stack | flamegraph.pl > /tmp/foo.svg

And here is the result:

images/foo.svg

Similar projects

clim.flamegraph
SBCL’s sprof flamegraph inspector with it’s own UI built with McClim.
TeMPOraL’s tracer
a hack on SBCL’s tracing implementation which is able to produce data for loading into Chrome’s chrome://tracing tool.
SAM
Simple sampling profiler for ClozureCL. Without graphical interface.
ccl-metering
a tool similar to TeMPOraL’s tracer, but for ClozureCL and without any graphical interface.

About

A wrapper around SBCL's statistical profiler, to generate FlameGraph charts for Common Lisp programs


Languages

Language:Common Lisp 100.0%