Skip to content

Instantly share code, notes, and snippets.

@joshland
Created October 9, 2017 21:44
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 joshland/a417d17b44cb03d8845feb245c575eed to your computer and use it in GitHub Desktop.
Save joshland/a417d17b44cb03d8845feb245c575eed to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os, string
def _pmap(process):
import subprocess
try:
p = subprocess.Popen(["pmap", process], stdout=subprocess.PIPE)
retval = [ x.decode() for x in p.stdout]
except OSError:
raise "Error = This server does not have 'ethtool'"
return retval
def main():
sets = 0
totes = 0
for pid in os.listdir('/proc'):
if pid[0] not in string.digits:
continue
raw = _pmap(pid)[1:-1]
sets += len(set([ x[30:] for x in raw ]))
totes += len(raw)
continue
print("Total MAPS: %d" % totes)
print("Total MAPS (sets): %d" % sets)
if __name__ == "__main__":
import sys
results = 0
for x in sys.argv:
try:
results = int(x)
break
except ValueError:
continue
continue
if results:
import time
while 1:
main()
time.sleep(results)
continue
else:
main()
pass
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment