Skip to content

Instantly share code, notes, and snippets.

@yonixw
Created February 23, 2022 17:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonixw/4aca7725633fe26b85cfea014aca611b to your computer and use it in GitHub Desktop.
Save yonixw/4aca7725633fe26b85cfea014aca611b to your computer and use it in GitHub Desktop.
nodejs xtrace dtrace trace performance heat map flame graph
if [ -z $1 ] || [ -z $2 ]
then
echo "Usage: [node file] [output svg]"
exit 1
fi
# https://www.brendangregg.com/blog/2014-09-17/node-flame-graphs-on-linux.html
# https://nodejs.org/en/docs/guides/diagnostics-flamegraph/
sudo perf record -e cycles:u -g -- node --interpreted-frames-native-stack --perf-basic-prof-only-functions "$1"
sudo perf script > perfs.out
sed -i \
-e "/( __libc_start| LazyCompile | v8::internal::| Builtin:| Stub:| LoadIC:|\[unknown\]| LoadPolymorphicIC:)/d" \
-e 's/ LazyCompile:[*~]\?/ /' \
perfs.out
./FlameGraph/stackcollapse-perf.pl < ./perfs.out | ./FlameGraph/flamegraph.pl > "$2"
echo "Done! saved to: $2"
# install & run perf (ubuntu)
sudo apt-get install linux-tools-common linux-tools-generic linux-tools-`uname -r`
# Make graph
git clone --depth 1 http://github.com/brendangregg/FlameGraph
@yonixw
Copy link
Author

yonixw commented Feb 23, 2022

For ts-node... but that Flame Graph I got was very generic... node -r ts-node/register ..... app.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment