Skip to content

Commit

Permalink
flamegraph.sh title small, add version flamegraph rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmoon79 committed May 7, 2024
1 parent 4236304 commit e8e7c9c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tools/flamegraph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ FREQ=${FREQ-3000}
-- --version
)
rm -f -- perf.data perf.data.old "${OUT}"
FLAMEGRAPH_VERSION=$(cargo flamegraph --version)
RUST_VERSION_SHORT=$(rustc --version | cut -f1,2 -d' ')

NOTES=$("${PROGRAM}" --version)
if GITLOG_HASH1=$(git log -n1 --pretty=format:%h 2>/dev/null); then
Expand Down Expand Up @@ -115,7 +117,7 @@ else
)
fi

NOTES+="; -freq ${FREQ}; created $(date +%Y%m%dT%H%M%S%z)"
NOTES+="; -freq ${FREQ}; created $(date +%Y%m%dT%H%M%S%z); ${FLAMEGRAPH_VERSION}; ${RUST_VERSION_SHORT}"

function html_sed_escape() {
# escape for HTML and for sed
Expand All @@ -141,7 +143,7 @@ cargo flamegraph \
--deterministic \
--output "${OUT}" \
--bin "${BIN}" \
--notes "${NOTES_ESCAPED}" \
--notes "foo<br/>bar<br/>${NOTES_ESCAPED}" \
--root \
--ignore-status \
--no-inline \
Expand All @@ -159,9 +161,13 @@ cargo flamegraph \
BIN_ESCAPED=$(html_sed_escape "${BIN}")
ARGS_ESCAPED=$(html_sed_escape "${args[*]}")

sed -i -Ee 's/(<text id="title" .*>)Flame Graph(<\/text>)/\1Flame Graph: '"${NOTES_ESCAPED}"'<br\/>; '"${BIN_ESCAPED}"' '"${ARGS_ESCAPED}"'\2/' -- "${OUT}"
sed -i -Ee 's/(<text id="title" .*>)Flame Graph(<\/text>)/\1Flame Graph: '"${NOTES_ESCAPED}"'<br\/>; command: '"${BIN_ESCAPED}"' '"${ARGS_ESCAPED}"'\2/' -- "${OUT}"
# the title is now a long string so make the font smaller
sed -i -Ee 's/<text id="title" /<text id="title" style="font-size:small" /' -- "${OUT}"

if which xmllint &>/dev/null; then
# the generated .svg file is a few huge lines so make it git-friendly (more lines more often)
xmllint --format --recover --output "${OUT}" "${OUT}"
else
echo "xmllint not found; skip formatting of ${OUT}" >&2
fi

0 comments on commit e8e7c9c

Please sign in to comment.