Skip to content

Instantly share code, notes, and snippets.

@smiley-yoyo
Created August 1, 2024 04:39
Show Gist options
  • Select an option

  • Save smiley-yoyo/9bdcd48754f79dc405edebfea8dc0c86 to your computer and use it in GitHub Desktop.

Select an option

Save smiley-yoyo/9bdcd48754f79dc405edebfea8dc0c86 to your computer and use it in GitHub Desktop.
using py-spy record top cpu usage python program
#!/bin/bash
output=$1
if [ -z "$output" ]; then
output="profile.svg"
fi
# assume that the top usage program is python program, or you can customize the top command
# using head/tail to get the top 1 line (the first 8 are headers)
topid=`top -b -n 1| head -n 8 |tail -n 1|awk '{print $1}'`
echo "top pid: $topid, recording..."
py-spy record -o $output --pid $topid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment