Skip to content
A wrapper around SBCL's statistical profiler, to generate FlameGraph charts for Common Lisp programs
Common Lisp
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
images
.gitignore Added links to the similar projects. Feb 14, 2020
README.org
core.lisp Initial. Feb 13, 2020
flamegraph.asd

README.org

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 a FlameGraph chart generator. It is written in Perl. This system prepares a data in simple text format and this file should be processed by the flamegraph.pl to generate SVG file with the 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.
You can’t perform that action at this time.