Rev 147: Start expermienting with a memory perf counter for Linux. in http://bazaar.launchpad.net/~jameinel/meliae/local

John Arbash Meinel john at arbash-meinel.com
Wed Jun 30 22:55:11 BST 2010


At http://bazaar.launchpad.net/~jameinel/meliae/local

------------------------------------------------------------
revno: 147
revision-id: john at arbash-meinel.com-20100630215451-olpfvnakqwehax11
parent: john at arbash-meinel.com-20100630214455-2mpjbggxot4vly80
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: local
timestamp: Wed 2010-06-30 16:54:51 -0500
message:
  Start expermienting with a memory perf counter for Linux.
-------------- next part --------------
=== modified file 'meliae/perf_counter.py'
--- a/meliae/perf_counter.py	2009-10-27 16:18:10 +0000
+++ b/meliae/perf_counter.py	2010-06-30 21:54:51 +0000
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 Canonical Ltd
+# Copyright (C) 2009, 2010 Canonical Ltd
 # 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License version 3 as
@@ -16,6 +16,7 @@
 
 import ctypes
 import math
+import re
 import sys
 import time
 
@@ -99,6 +100,21 @@
         # This returns wall-clock time
         return time.time
 
+    def get_memory(self, process):
+        pid = process.pid
+        try:
+            f = open('/proc/%s/status', 'rb')
+        except (IOError, OSError):
+            return None
+        try:
+            content = f.read()
+        finally:
+            f.close()
+        m = re.search(r'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
+        if m is None:
+            return None
+        return int(m.group('val')) * 1024
+
 
 class _Win32PerformanceCounter(PerformanceCounter):
 



More information about the bazaar-commits mailing list