Module Expr Str ImportFrom alias ImportFrom alias Import alias Import alias Import alias Import alias TryExcept body Import alias handlers ExceptHandler type NameLoad body Expr Call AttributeLoad NameLoad attr Str Import alias FunctionDef arguments args defaults body Expr Call AttributeLoad NameLoad attr Num Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr decorator_list Assign NameStore Call AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr Assign NameStore Num FunctionDef arguments args NameParam NameParam defaults NameLoad body Expr Str Global identifier TryExcept body If NameLoad body AugAssignAdd NameStore BinOpMult Str BinOpSub SubscriptLoad Call AttributeLoad NameLoad attr Index Num Call NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad Num NameLoad AttributeLoad NameLoad attr orelse Expr Call AttributeLoad NameLoad attr NameLoad Num NameLoad Num handlers ExceptHandler type AttributeLoad NameLoad attr body Assign NameStore Num Expr Call AttributeLoad NameLoad attr Raise orelse AugAssignAdd NameStore Num decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore TupleLoad Str Str Str Str Str Str Str Str Assign NameStore Dict For TupleStore NameStore NameStore Call NameLoad NameLoad body Assign SubscriptStore NameLoad Index NameLoad BinOpLShift Num BinOpMult BinOpAdd NameLoad Num Num For NameStore Call NameLoad NameLoad body If CompareGtE NameLoad SubscriptLoad NameLoad Index NameLoad body Assign NameStore Call NameLoad BinOpDiv Call NameLoad NameLoad SubscriptLoad NameLoad Index NameLoad Return BinOpMod Str TupleLoad NameLoad NameLoad Return BinOpMod Str NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore ListLoad Assign NameStore Dict For NameStore Call AttributeLoad NameLoad attr body TryExcept body Assign AttributeStore NameLoad attr Call AttributeLoad NameLoad attr ListLoad Str Str Str Str Str Str Str Str TryExcept body AugAssignAdd SubscriptStore NameLoad Index SubscriptLoad AttributeLoad NameLoad attr Index Str Num handlers ExceptHandler type NameLoad body Assign SubscriptStore NameLoad Index SubscriptLoad AttributeLoad NameLoad attr Index Str Num handlers ExceptHandler type AttributeLoad NameLoad attr body Pass orelse Expr Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad NameLoad keyword Lambda arguments args NameParam defaults SubscriptLoad AttributeLoad NameLoad attr Index Str keyword NameLoad Return TupleLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str FunctionDef arguments args NameParam defaults body Assign NameStore BinOpMult Str Call NameLoad BinOpMult BinOpDiv Call NameLoad NameLoad Num Num Assign NameStore BinOpMult Str BinOpSub Num Call NameLoad NameLoad Return TupleLoad NameLoad NameLoad decorator_list Assign NameStore Call AttributeLoad NameLoad attr keyword Num keyword NameLoad For TupleStore NameStore NameStore Call NameLoad NameLoad body Assign TupleStore NameStore NameStore Call NameLoad NameLoad Expr Call NameLoad BinOpMod Str TupleLoad NameLoad NameLoad NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr Assign NameStore BinOpSub AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr BinOpAdd Call NameLoad Call NameLoad BinOpDiv BinOpDiv NameLoad Num Num Str BinOpAdd Call NameLoad Call NameLoad BinOpDiv BinOpDiv AttributeLoad NameLoad attr Num Num Str Expr Call NameLoad NameLoad Assign NameStore Call AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore Call NameLoad AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad NameLoad NameLoad AttributeLoad NameLoad attr BinOpAdd Call NameLoad Call NameLoad BinOpDiv BinOpDiv AttributeLoad NameLoad attr Num Num Str BinOpAdd Call NameLoad Call NameLoad BinOpDiv BinOpDiv AttributeLoad NameLoad attr Num Num Str Expr Call NameLoad NameLoad Assign NameStore ListLoad For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr body If NameLoad body Expr Call AttributeLoad NameLoad attr BinOpMod Str TupleLoad NameLoad NameLoad Expr Call AttributeLoad NameLoad attr keyword Lambda arguments args NameParam defaults CompareIn SubscriptLoad NameLoad Slice Num TupleLoad Str Str keyword Num Expr Call NameLoad BinOpMod Str TupleLoad NameLoad Call AttributeLoad Str attr NameLoad Assign NameStore BinOpSub Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Call AttributeLoad NameLoad attr Assign TupleStore NameStore NameStore NameStore Call AttributeLoad NameLoad attr Assign NameStore BinOpMod Str TupleLoad NameLoad NameLoad NameLoad SubscriptLoad Call AttributeLoad Call NameLoad NameLoad attr Str Index Num Expr Call NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam defaults body Expr Str Expr Call AttributeLoad NameLoad attr Assign NameStore Str Expr Call AttributeLoad NameLoad attr Assign NameStore BinOpMod NameLoad TupleLoad Str Str Str Str Str Str Str Str Str Expr Call NameLoad NameLoad Call NameLoad NameLoad Expr Call NameLoad Str Expr Call NameLoad NameLoad keyword NameLoad For NameStore NameLoad body If CompareIsNot SubscriptLoad AttributeLoad NameLoad attr Index Str NameLoad body Assign NameStore Call NameLoad keyword Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Assign NameStore BinOpMod Str TupleLoad BinOpMod BinOpFloorDiv AttributeLoad NameLoad attr Num Num Call AttributeLoad Call NameLoad BinOpMod AttributeLoad NameLoad attr Num attr Num SubscriptLoad Call NameLoad AttributeLoad NameLoad attr Slice Num orelse Assign NameStore Str If CompareIsNot SubscriptLoad AttributeLoad NameLoad attr Index Str NameLoad body Assign SubscriptStore AttributeLoad NameLoad attr Index Str Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Num orelse Assign SubscriptStore AttributeLoad NameLoad attr Index Str Str If CompareIs SubscriptLoad AttributeLoad NameLoad attr Index Str NameLoad body Assign SubscriptStore AttributeLoad NameLoad attr Index Str Str If SubscriptLoad AttributeLoad NameLoad attr Index Str body Assign NameStore SubscriptLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Slice Num orelse Assign NameStore Str Assign NameStore BinOpMod NameLoad TupleLoad AttributeLoad NameLoad attr NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Call NameLoad Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Str Num Call NameLoad Call NameLoad SubscriptLoad AttributeLoad NameLoad attr Index Str Str Num SubscriptLoad AttributeLoad NameLoad attr Index Str SubscriptLoad AttributeLoad NameLoad attr Index Str NameLoad BoolOpOr SubscriptLoad AttributeLoad NameLoad attr Index Str Str TryExcept body Expr Call NameLoad NameLoad handlers ExceptHandler type AttributeLoad NameLoad attr body Break Expr Call AttributeLoad NameLoad attr decorator_list FunctionDef arguments args defaults body TryExcept body Assign NameStore Num While NameLoad body Assign NameStore Call NameLoad NameLoad Expr Call NameLoad NameLoad Assign NameStore Num handlers ExceptHandler type TupleLoad NameLoad NameLoad body Pass decorator_list If CompareEq NameLoad Str body Expr Call NameLoad
N/A N/A 
A clone of top / htop.

Author: Giampaolo Rodola' <g.rodola@gmail.com>

$ python scripts/top.py
 CPU0  [|                                       ]   4.9%
 CPU1  [|||                                     ]   7.8%
 CPU2  [                                        ]   2.0%
 CPU3  [|||||                                   ]  13.9%
 Mem   [|||||||||||||||||||                     ]  49.8%  4920M/9888M
 Swap  [                                        ]   0.0%     0M/0M
 Processes: 287 (running=1, sleeping=286, zombie=1)
 Load average: 0.34 0.54 0.46  Uptime: 3 days, 10:16:37

PID    USER       NI  VIRT   RES   CPU% MEM%     TIME+  NAME
------------------------------------------------------------
989    giampaol    0   66M   12M    7.4  0.1   0:00.61  python
2083   root        0  506M  159M    6.5  1.6   0:29.26  Xorg
4503   giampaol    0  599M   25M    6.5  0.3   3:32.60  gnome-terminal
3868   giampaol    0  358M    8M    2.8  0.1  23:12.60  pulseaudio
3936   giampaol    0    1G  111M    2.8  1.1  33:41.67  compiz
4401   giampaol    0  536M  141M    2.8  1.4  35:42.73  skype
4047   giampaol    0  743M   76M    1.8  0.8  42:03.33  unity-panel-service
13155  giampaol    0    1G  280M    1.8  2.8  41:57.34  chrome
10     root        0    0B    0B    0.9  0.0   4:01.81  rcu_sched
339    giampaol    0    1G  113M    0.9  1.1   8:15.73  chrome
...
 datetime datetime datetime timedelta N/A atexit N/A os N/A sys N/A time N/A N/A N/A curses N/A N/A N/A ImportError N/A N/A N/A N/A sys exit platform not supported N/A psutil tear_down N/A N/A N/A N/A N/A N/A N/A win keypad 0 N/A N/A N/A curses nocbreak N/A N/A N/A curses echo N/A N/A N/A curses endwin N/A N/A win N/A N/A curses initscr N/A N/A N/A atexit register tear_down N/A N/A N/A curses endwin N/A lineno 0 print_line N/A N/A line highlight N/A False N/A N/A A thin wrapper around curses's addstr(). N/A lineno N/A N/A N/A highlight N/A N/A line N/A N/A N/A N/A N/A win getmaxyx N/A 1 N/A len line N/A N/A N/A win addstr lineno 0 line N/A curses A_REVERSE N/A N/A N/A N/A win addstr lineno 0 line 0 N/A N/A N/A N/A curses error N/A N/A lineno 0 N/A N/A N/A win refresh N/A N/A N/A lineno 1 N/A bytes2human N/A N/A n N/A N/A N/A 
    >>> bytes2human(10000)
    '9K'
    >>> bytes2human(100001221)
    '95M'
     N/A symbols N/A K M G T P E Z Y N/A prefix N/A N/A N/A i s N/A enumerate symbols N/A N/A N/A prefix N/A s N/A 1 N/A N/A i 1 10 N/A s N/A reversed symbols N/A N/A N/A n N/A prefix N/A s N/A N/A value N/A int N/A N/A float n N/A prefix N/A s N/A N/A %s%s N/A value s N/A N/A %sB n N/A poll N/A N/A interval N/A N/A N/A N/A N/A time sleep interval N/A procs N/A N/A procs_status N/A N/A p N/A N/A psutil process_iter N/A N/A N/A N/A N/A p dict N/A N/A p as_dict N/A username nice memory_info memory_percent cpu_percent cpu_times name status N/A N/A N/A N/A procs_status N/A N/A N/A p dict N/A status 1 N/A N/A N/A KeyError N/A N/A N/A procs_status N/A N/A N/A p dict N/A status 1 N/A N/A N/A N/A psutil NoSuchProcess N/A N/A N/A N/A N/A N/A procs append p N/A processes N/A sorted procs key N/A N/A N/A p N/A N/A N/A p dict N/A cpu_percent reverse True N/A N/A processes procs_status N/A print_header N/A N/A procs_status num_procs N/A N/A N/A Print system-related info, above the process list. get_dashes N/A N/A perc N/A N/A N/A dashes N/A | N/A int N/A N/A N/A float perc 10 4 N/A empty_dashes N/A N/A 40 N/A len dashes N/A N/A dashes empty_dashes N/A N/A percs N/A N/A psutil cpu_percent interval 0 percpu True N/A N/A cpu_num perc N/A enumerate percs N/A N/A N/A dashes empty_dashes N/A get_dashes perc N/A N/A print_line N/A  CPU%-2s [%s%s] %5s%% N/A cpu_num dashes empty_dashes perc N/A mem N/A N/A psutil virtual_memory N/A N/A dashes empty_dashes N/A get_dashes N/A mem percent N/A used N/A N/A mem total N/A mem available N/A line N/A  Mem   [%s%s] %5s%% %6s/%s N/A dashes empty_dashes N/A mem percent N/A N/A str N/A int N/A N/A used 1024 1024 M N/A N/A str N/A int N/A N/A N/A mem total 1024 1024 M N/A N/A print_line line N/A swap N/A N/A psutil swap_memory N/A N/A dashes empty_dashes N/A get_dashes N/A swap percent N/A line N/A  Swap  [%s%s] %5s%% %6s/%s N/A dashes empty_dashes N/A swap percent N/A N/A str N/A int N/A N/A N/A swap used 1024 1024 M N/A N/A str N/A int N/A N/A N/A swap total 1024 1024 M N/A N/A print_line line N/A st N/A N/A N/A x y N/A N/A procs_status items N/A N/A y N/A N/A N/A N/A st append N/A %s=%s N/A x y N/A N/A N/A st sort key N/A N/A N/A x N/A N/A N/A x N/A 3 N/A run sle reverse 1 N/A N/A print_line N/A  Processes: %s (%s) N/A num_procs N/A N/A ,  join st N/A uptime N/A N/A N/A datetime now N/A N/A datetime fromtimestamp N/A N/A psutil boot_time N/A N/A av1 av2 av3 N/A N/A os getloadavg N/A line N/A  Load average: %.2f %.2f %.2f  Uptime: %s N/A av1 av2 av3 N/A N/A N/A N/A str uptime split . N/A 0 N/A N/A print_line line N/A refresh_window N/A N/A procs procs_status N/A N/A N/A Print results on screen by using curses. N/A N/A N/A curses endwin N/A templ %-6s %-8s %4s %5s %5s %6s %4s %9s  %2s N/A N/A N/A win erase N/A header N/A templ N/A PID USER NI VIRT RES CPU% MEM% TIME+ NAME N/A N/A print_header procs_status N/A len procs N/A N/A print_line N/A N/A print_line header highlight True N/A p procs N/A N/A N/A N/A N/A p dict N/A cpu_times None N/A N/A ctime N/A timedelta seconds N/A sum N/A N/A p dict N/A cpu_times N/A ctime N/A %s:%s.%s N/A N/A N/A N/A ctime seconds 60 60 N/A N/A N/A str N/A N/A ctime seconds 60 zfill 2 N/A N/A str N/A ctime microseconds N/A 2 N/A N/A ctime N/A N/A N/A N/A p dict N/A memory_percent None N/A N/A N/A N/A p dict N/A memory_percent N/A round N/A N/A p dict N/A memory_percent 1 N/A N/A N/A N/A p dict N/A memory_percent N/A N/A N/A N/A p dict N/A cpu_percent None N/A N/A N/A N/A p dict N/A cpu_percent N/A N/A N/A p dict N/A username N/A N/A username N/A N/A N/A p dict N/A username N/A 8 N/A N/A username N/A line N/A templ N/A N/A p pid username N/A N/A p dict N/A nice N/A bytes2human N/A getattr N/A N/A p dict N/A memory_info vms 0 N/A bytes2human N/A getattr N/A N/A p dict N/A memory_info rss 0 N/A N/A p dict N/A cpu_percent N/A N/A p dict N/A memory_percent ctime N/A N/A N/A p dict N/A name N/A N/A N/A N/A print_line line N/A N/A N/A N/A curses error N/A N/A N/A N/A N/A win refresh N/A main N/A N/A N/A N/A N/A N/A N/A interval 0 N/A True N/A N/A args N/A poll interval N/A N/A refresh_window args N/A interval 1 N/A N/A N/A N/A KeyboardInterrupt SystemExit N/A N/A N/A N/A N/A __name__ __main__ N/A N/A N/A main