Created
October 21, 2024 19:58
-
-
Save AdamBrouwersHarries/ddd0dfa1eff5d42e192ed980b8a4d872 to your computer and use it in GitHub Desktop.
A short bash program to start firefox, capture a profile, and load the resulting profile with samply.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Start firefox with the profiler running, and capture a profile. | |
# This is a utility script to quickly run firefox and gather a profile while | |
# iterating on the format of markers, or other front-end formatting that | |
# relies on backend changes. | |
# The time to run the profile. Default to 10 seconds | |
profiletime=${1:-10} | |
# The time to gather the profile. Default is $profiletime | |
gathertime=${2:-$profiletime} | |
get_profile() { | |
# figure out what path `./mach run` will use | |
command=$(timeout -s TERM 3 ./mach run | head -n 1 | grep -o "\/.*") | |
echo -e "\033[37;45;1;4mRunning: $command\033[0m" | |
# Run `command`, and get the PID. | |
# We do it this way (rather than using `mach` directly) as otherwise $! | |
# will only tell us the PID of the `mach` program or python | |
# We could alternatively use `timeout` again to send SIGUSR2 and SIGKILL | |
# but that would prevent us from learning the firefox PID, which we need | |
# in order to load the profile using samply | |
MOZ_PROFILER_STARTUP=1 $command & | |
firefox_pid=$! | |
echo -e "\033[37;45;1;4mFound firefox pid: $!\033[0m" | |
echo -e "\033[37;45;1;4mSleeping for $1\033[0m" | |
sleep $1 | |
echo -e "\033[37;45;1;4mStarting profile gathering\033[0m" | |
kill -s USR2 $firefox_pid | |
echo -e "\033[37;45;1;4mSleeping for $2\033[0m" | |
sleep $2 | |
kill -s TERM $firefox_pid | |
echo -e "\033[37;45;1;4mLoading in samply: ~/Downloads/profile_0_$firefox_pid.json\033[0m" | |
samply load ~/Downloads/profile_0_$firefox_pid.json | |
} | |
get_profile $profiletime $gathertime |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment