~ubuntu-branches/debian/sid/meliae/sid

« back to all changes in this revision

Viewing changes to meliae/perf_counter.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2010-07-20 18:26:22 UTC
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20100720182622-b0ks0nu34mify1lj
Tags: upstream-0.2.1
ImportĀ upstreamĀ versionĀ 0.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
3
3
# This program is free software: you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License version 3 as
16
16
 
17
17
import ctypes
18
18
import math
 
19
import re
19
20
import sys
20
21
import time
21
22
 
99
100
        # This returns wall-clock time
100
101
        return time.time
101
102
 
 
103
    def get_memory(self, process):
 
104
        pid = process.pid
 
105
        try:
 
106
            f = open('/proc/%s/status' % (process.pid,), 'rb')
 
107
        except (IOError, OSError):
 
108
            return None, None
 
109
        try:
 
110
            content = f.read()
 
111
        finally:
 
112
            f.close()
 
113
        m = re.search(r'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
 
114
        peak = current = None
 
115
        if m is not None:
 
116
           peak = int(m.group('peak')) * 1024
 
117
        m = re.search(r'(?i)vmsize:\s*(?P<current>\d+) kB', content)
 
118
        if m is not None:
 
119
           current = int(m.group('current')) * 1024
 
120
        return current, peak
 
121
 
102
122
 
103
123
class _Win32PerformanceCounter(PerformanceCounter):
104
124