Skip to content

Instantly share code, notes, and snippets.

@kitten
Created April 2, 2015 00:58
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 kitten/a2ca1a7718d9fe94aa7d to your computer and use it in GitHub Desktop.
Save kitten/a2ca1a7718d9fe94aa7d to your computer and use it in GitHub Desktop.
Little bash function that uses Spark to display the CPU usage on a dual core Mac.
function cpu() {
usage=$(ps aux | awk {'sum+=$3;print int(sum/4+.5)'} | tail -n 1)
graph=$(spark 0 ${usage} 100 | awk '{print substr($0,4,3)}')
echo "[$usage%] $graph"
}
@kitten
Copy link
Author

kitten commented Apr 2, 2015

int(sum/4+.5) can be modified for quad core or single code machines (or any). Just replace the 4 with your number of cores. Remember Hyper Threading.

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