Merge lp:~cjwatson/meliae/py3-perf-counter into lp:meliae

Proposed by Colin Watson
Status: Merged
Merged at revision: 222
Proposed branch: lp:~cjwatson/meliae/py3-perf-counter
Merge into: lp:meliae
Diff against target: 60 lines (+14/-14)
2 files modified
meliae/perf_counter.py (+8/-8)
meliae/tests/test_perf_counter.py (+6/-6)
To merge this branch: bzr merge lp:~cjwatson/meliae/py3-perf-counter
Reviewer Review Type Date Requested Status
John A Meinel Approve
Review via email: mp+378584@code.launchpad.net

Commit message

Port performance counters to Python 3.

Description of the change

/proc/<pid>/status is opened in binary mode, so we need to parse it using bytes-like regexes.

TestPerformanceCounter.test_get_memory needs similar minor adjustments to use bytes where appropriate.

There were various combinations of tabs and spaces which Python 3 now complains about.

To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'meliae/perf_counter.py'
2--- meliae/perf_counter.py 2010-07-12 20:10:34 +0000
3+++ meliae/perf_counter.py 2020-02-05 12:04:11 +0000
4@@ -110,14 +110,14 @@
5 content = f.read()
6 finally:
7 f.close()
8- m = re.search(r'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
9- peak = current = None
10- if m is not None:
11- peak = int(m.group('peak')) * 1024
12- m = re.search(r'(?i)vmsize:\s*(?P<current>\d+) kB', content)
13- if m is not None:
14- current = int(m.group('current')) * 1024
15- return current, peak
16+ m = re.search(br'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
17+ peak = current = None
18+ if m is not None:
19+ peak = int(m.group('peak')) * 1024
20+ m = re.search(br'(?i)vmsize:\s*(?P<current>\d+) kB', content)
21+ if m is not None:
22+ current = int(m.group('current')) * 1024
23+ return current, peak
24
25
26 class _Win32PerformanceCounter(PerformanceCounter):
27
28=== modified file 'meliae/tests/test_perf_counter.py'
29--- meliae/tests/test_perf_counter.py 2020-01-30 12:10:58 +0000
30+++ meliae/tests/test_perf_counter.py 2020-02-05 12:04:11 +0000
31@@ -77,23 +77,23 @@
32 # value is accurate, but we can at least try
33 # Create a very large string, and then delete it.
34 p = subprocess.Popen([sys.executable, '-c',
35- 'x = "abcd"*(10*1000*1000); del x;'
36+ 'x = b"abcd"*(10*1000*1000); del x;'
37 'import sys;'
38 'sys.stdout.write(sys.stdin.read(3));'
39 'sys.stdout.flush();'
40 'sys.stdout.write(sys.stdin.read(4));'
41 'sys.stdout.flush(); sys.stdout.close()'],
42 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
43- p.stdin.write('pre')
44+ p.stdin.write(b'pre')
45 p.stdin.flush()
46 p.stdout.read(3)
47 cur_mem, peak_mem = perf_counter.perf_counter.get_memory(p)
48- if cur_mem is None or peak_mem is None:
49- # fail gracefully, though we may want a stronger assertion here
50- return
51+ if cur_mem is None or peak_mem is None:
52+ # fail gracefully, though we may want a stronger assertion here
53+ return
54 self.assertTrue(isinstance(cur_mem, six.integer_types))
55 self.assertTrue(isinstance(peak_mem, six.integer_types))
56- p.stdin.write('post')
57+ p.stdin.write(b'post')
58 p.stdin.flush()
59 p.stdout.read()
60 self.assertEqual(0, p.wait())

Subscribers

People subscribed via source and target branches

to all changes: