Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Profiling FIRRTL

Chick Markley edited this page Jan 9, 2019 · 6 revisions

The best way I've found to profile FIRRTL is by using FlameGraphs! The following is what works for me on an MacOSX Laptop.

Required installation:

Then run:

sbt assembly
./utils/bin/firrtl-profiling -i <testcase>.fir -o dump.v # Creates output.hprof
stackcollapse-hprof output.hprof > output-folded.txt
flamegraph.pl output-folded.txt > output.svg

You can then use your browser (e.g. Chrome) to view output.svg

You get pretty graphs like this:

Some hints for applying the above to some other project

Firrtl already has assembly built in. If you want to create add assembly to some other project you need to add lines to your build.sbt file. Here is an example of what you have to add to the treadle projects build.sbt file to support assembly in treadle.

// Assembly

assemblyJarName in assembly := "treadle.jar"

mainClass in assembly := Some("treadle.TreadleRepl")

test in assembly := {} // Should there be tests?

assemblyOutputPath in assembly := file("./utils/bin/treadle.jar")

In the above example the command firrtl-profiling is just a script that has been created to invoke the desired options on the jar created by assembly. Here is an example of a similar file created in order to generate a flame graph for a regression test that is defined in a scala object Regression, so I added a treadle.profiling shell script with the necessary options

#!/bin/bash

# This may be a brittle way to find $(root_dir)/utils/bin, is there a better way?
path=`dirname "$0"`
cmd="java -agentlib:hprof=cpu=samples,depth=100,interval=7,lineno=y,thread=y,file=output.hprof -cp ${path}/treadle.jar treadle.Regression"

eval $cmd