+ try:
+ f = open(b'/proc/self/status', 'rb')
+ except IOError as e:
+ if not _linux_warned:
+ log('Warning: %s\n' % e)
+ _linux_warned = 1
+ return {}
+ for line in f:
+ # Note that on Solaris, this file exists but is binary. If that
+ # happens, this split() might not return two elements. We don't
+ # really need to care about the binary format since this output
+ # isn't used for much and report() can deal with missing entries.
+ t = re.split(br':\s*', line.strip(), 1)
+ if len(t) == 2:
+ k,v = t
+ d[k] = v
+ return d
+
+
+last = last_u = last_s = start = 0
+def report(count, out):
+ global last, last_u, last_s, start
+ headers = ['RSS', 'MajFlt', 'user', 'sys', 'ms']
+ ru = resource.getrusage(resource.RUSAGE_SELF)
+ now = time.time()
+ rss = int(ru.ru_maxrss // 1024)
+ if not rss:
+ rss = linux_memstat().get(b'VmRSS', b'??')
+ fields = [rss,
+ ru.ru_majflt,
+ int((ru.ru_utime - last_u) * 1000),
+ int((ru.ru_stime - last_s) * 1000),
+ int((now - last) * 1000)]
+ fmt = '%9s ' + ('%10s ' * len(fields))