FDD-book/examples/part-07/ch33-performance/lab03-pmcstat/callgraph.sh
Edson Brandi 6e6dac94fe Add book companion files under examples/
Organize companion code and materials by book part:

  part-01/      Foundations
  part-02/      Kernel & driver fundamentals
  part-03/      Character & block devices
  part-04/      Networking & storage
  part-05/      Buses & advanced topics
  part-06/      Debugging & performance
  part-07/      Real-world drivers
  appendices/   Supplementary material
  README.md     Overview and build instructions
2026-04-25 16:51:00 +00:00

24 lines
693 B
Bash
Executable file

#!/bin/sh
#
# callgraph.sh - collect callgraph samples while a workload runs.
#
# Usage: ./callgraph.sh [duration_seconds]
#
# Produces pmc.cg, which can be converted to a flame graph with:
# pmcstat -R pmc.cg -G - | stackcollapse-pmc.pl | flamegraph.pl > out.svg
# (stackcollapse-pmc.pl and flamegraph.pl are from Brendan Gregg's
# FlameGraph repository.)
DURATION=${1:-30}
if ! kldstat | grep -q hwpmc; then
echo "Loading hwpmc..."
sudo kldload hwpmc
fi
echo "Collecting callgraph samples for $DURATION seconds..."
sudo pmcstat -S cycles -O pmc.cg -n 1 sleep $DURATION
echo
echo "Samples written to pmc.cg. Top functions by call count:"
sudo pmcstat -R pmc.cg -G - | head -30