-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers_categorizecmd.py
executable file
·168 lines (129 loc) · 4.92 KB
/
helpers_categorizecmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/python3
def starts_with_one_of(s, stringlist): # TODO: change to regexp so I can more easily express whole name ,startswith, word-boundary, and such
for test in stringlist:
if s.startswith(test):
return True
return False
def categorize_cmd(cmd:str, merge_databases=False, merge_services=False):
""" This is based on pragmatism
- group lots of small kernel stuff
Takes str, or bytes (if bytes, assumes we can decode as utf8)
"""
if type(cmd) is bytes:
cmd = cmd.decode('utf8')
if starts_with_one_of(cmd, (
'systemd-',
'(sd-pam)',
'journalctl',
)):
return '(systemd)'
# These are more useful when kept separate
if merge_databases and starts_with_one_of(cmd, (
'postgres',
'mysql',
'rabbitmq', 'beam.smp',
'mosquitto',
'memcached',
)): # useful to keep separate, though
return '(database)'
if starts_with_one_of(cmd, (# drivery stuff
'oom_reaper','rcuos', 'rcu_', 'kworker', 'ksoftirqd', 'kthreadd', 'migration', 'watchdog',
'khelper', 'kdevtmpfs', 'kworker', 'irq/', 'cpuhp/', 'khungtaskd', 'khugepaged',
'kcompactd',
'irqbalance', 'devfreq', 'mm_percpu_wq',
'kstrp',
'edac-', 'acpid', 'acpi_',
'nv_queue',
'ttm_swap',
'ksmd',
#'nvidia-',
# support stuff
'init','getty', 'upstart', 'rsyslog', 'syslog',
'kauditd', 'polkitd', # security stuff
'packagekitd', 'unattended-','cleanupd', #update stuff
'runsv', 'runsvdir', 'my_init', # inside containers, probably
'accounts-daemon', # look up properly
'xprtiod', # look up properly
'unattended-',
)):
return '(kernel+system)'
if starts_with_one_of(cmd, (
# filesystem-supporting processes
'z_', 'zvol', 'zfs_', 'arc_', 'l2arc_', 'txg_', 'zil_', 'dp_zil_', 'dp_sync_', 'dbu_evict','dbuf_evict', 'metaslab_group',
'zed',
'spl_',
'ext4', 'ecryptfs', 'lvmetad',
'jbd2', 'xfsmalloc','xfsalloc','xfs_', 'jfsIO','jfsSync','jfsCommit','jfscommit',
# more directly related to disk IO
'scsi', 'ata_', 'kswap', 'fsnotify', 'writeback', 'kblockd', 'kthrotld', 'kintegrityd', 'raid5wq',
'smartd',
'udisksd',
'loop0', 'loop1',
'crypto', #practically
)):
return '(io+filesystem)'
if starts_with_one_of(cmd, (
'agetty',
'atd', 'cron', #'anacron',
'runsv','runsvdir',
'nvidia-',
'fancontrol',
'dbus-', # arguable
'charger_manager',
)):
return '(local-services)'
if merge_services and starts_with_one_of(cmd, (
'ipv6_addrconf',
'wpa_supplicant', 'cfg80211',
'networkd-',
'inetutils-inetd',
'rpc.', 'rpcbind', 'rpciod'
'ntpd',
'smbd',
'cups', 'lpqd',
'nfsd', 'xprtiod', 'blkmapd',
'lockd',
'rpc.', 'rpcbind', 'rpciod',
'tmux', 'screen',
'avahi-d',
#'sshd', # commented, this is something I want to know separately
'seaf',
'apache', 'htcacheclean',
'nginx',
'networkd-',
'winbindd',
'rpc.idmapd',
'rpc.mountd',
'rpciod',
'rpcbind',
'cupsd',
'cups-',
'epmd',
'lpqd',
'nfsd', 'blkmapd',
'smbd',
'pickup',
'munin-node',
)):
return '(network-services)'
elif starts_with_one_of(cmd, ('UVM ', 'docker', 'iprt-', 'containerd', 'VBox')):
return '(vm+container)'
elif starts_with_one_of(cmd, ('gnome-', 'gvfs-', 'gvfsd-', 'gsd-','gdm', 'at-spi', 'colord', 'gdostep',
#'gvfs' # maybe include GUI-supporting stuff in this too? also e.g. dbuf?
)):
return '(gui)'
if '/' in cmd:
cmd = cmd.split('/')[-1]
return cmd
if __name__ == '__main__':
# testing the above
import subprocess
p = subprocess.Popen("ps --no-header -eo comm",shell=True, stdout=subprocess.PIPE, encoding='u8') # rss is non-swapped physical
out,_ = p.communicate()
for name in sorted(set(out.splitlines())):
#name = name.encode('u8')
cat = categorize_cmd(name,True,True)
extra=''
if len(cat)==0 or cat[0]!='(':
extra = 'UNCAT'
print( '%20s %10s %s'%(name, extra, cat ) )