Skip to content

Instantly share code, notes, and snippets.

@fhunleth
Created February 16, 2023 00:13
Show Gist options
  • Save fhunleth/dd5ed61cd75500bcfb03163a2da5db25 to your computer and use it in GitHub Desktop.
Save fhunleth/dd5ed61cd75500bcfb03163a2da5db25 to your computer and use it in GitHub Desktop.
Running gprof with Nerves

Add this to erlang.mk:

define ERLANG_BUILD_GPROF
        $(TARGET_MAKE_ENV) $(ERLANG_CONF_ENV) TARGET='riscv64-buildroot-linux-gnu' $(MAKE) -C $(@D)/erts/emulator gprof
endef

ERLANG_POST_BUILD_HOOKS += ERLANG_BUILD_GPROF

This makes beam.gprof.smp. Copy it to staging:

cp build/erlang-25.2.2/bin/riscv64-buildroot-linux-gnu/beam.gprof.smp staging/usr/lib/erlang/erts-13.1.4/bin/beam.smp

Add the following to erlinit.config:

-e GMON_OUT_PREFIX=/root/gmon

Run. You should get a gmon.<pid> file written to /root.

Copy the file back:

gprof staging/usr/lib/erlang/erts-13.1.4/bin/beam.smp gmon.54 >analysis.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment