Skip to content

Instantly share code, notes, and snippets.

@miketheman
Created July 17, 2013 14:54
Show Gist options
  • Select an option

  • Save miketheman/6021309 to your computer and use it in GitHub Desktop.

Select an option

Save miketheman/6021309 to your computer and use it in GitHub Desktop.
using psutil to get a process' cpu times
import psutil
psutil.cpu_times()
# => cputimes(
# user=4482262.9199999999,
# nice=70491.440000000002,
# system=717972.08999999997,
# idle=25366818.309999999,
# iowait=84943.889999999999,
# irq=0.0,
# softirq=13153.200000000001
# )
psutil.get_pid_list()
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ....]
p = psutil.Process(18000)
p.get_cpu_times()
# => cputimes(user=0.25, system=0.059999999999999998)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment