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
=== modified file 'meliae/perf_counter.py'
--- meliae/perf_counter.py 2010-07-12 20:10:34 +0000
+++ meliae/perf_counter.py 2020-02-05 12:04:11 +0000
@@ -110,14 +110,14 @@
110 content = f.read()110 content = f.read()
111 finally:111 finally:
112 f.close()112 f.close()
113 m = re.search(r'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)113 m = re.search(br'(?i)vmpeak:\s*(?P<peak>\d+) kB', content)
114 peak = current = None114 peak = current = None
115 if m is not None:115 if m is not None:
116 peak = int(m.group('peak')) * 1024116 peak = int(m.group('peak')) * 1024
117 m = re.search(r'(?i)vmsize:\s*(?P<current>\d+) kB', content)117 m = re.search(br'(?i)vmsize:\s*(?P<current>\d+) kB', content)
118 if m is not None:118 if m is not None:
119 current = int(m.group('current')) * 1024119 current = int(m.group('current')) * 1024
120 return current, peak120 return current, peak
121121
122122
123class _Win32PerformanceCounter(PerformanceCounter):123class _Win32PerformanceCounter(PerformanceCounter):
124124
=== modified file 'meliae/tests/test_perf_counter.py'
--- meliae/tests/test_perf_counter.py 2020-01-30 12:10:58 +0000
+++ meliae/tests/test_perf_counter.py 2020-02-05 12:04:11 +0000
@@ -77,23 +77,23 @@
77 # value is accurate, but we can at least try77 # value is accurate, but we can at least try
78 # Create a very large string, and then delete it.78 # Create a very large string, and then delete it.
79 p = subprocess.Popen([sys.executable, '-c',79 p = subprocess.Popen([sys.executable, '-c',
80 'x = "abcd"*(10*1000*1000); del x;'80 'x = b"abcd"*(10*1000*1000); del x;'
81 'import sys;'81 'import sys;'
82 'sys.stdout.write(sys.stdin.read(3));'82 'sys.stdout.write(sys.stdin.read(3));'
83 'sys.stdout.flush();'83 'sys.stdout.flush();'
84 'sys.stdout.write(sys.stdin.read(4));'84 'sys.stdout.write(sys.stdin.read(4));'
85 'sys.stdout.flush(); sys.stdout.close()'],85 'sys.stdout.flush(); sys.stdout.close()'],
86 stdin=subprocess.PIPE, stdout=subprocess.PIPE)86 stdin=subprocess.PIPE, stdout=subprocess.PIPE)
87 p.stdin.write('pre')87 p.stdin.write(b'pre')
88 p.stdin.flush()88 p.stdin.flush()
89 p.stdout.read(3)89 p.stdout.read(3)
90 cur_mem, peak_mem = perf_counter.perf_counter.get_memory(p)90 cur_mem, peak_mem = perf_counter.perf_counter.get_memory(p)
91 if cur_mem is None or peak_mem is None:91 if cur_mem is None or peak_mem is None:
92 # fail gracefully, though we may want a stronger assertion here92 # fail gracefully, though we may want a stronger assertion here
93 return93 return
94 self.assertTrue(isinstance(cur_mem, six.integer_types))94 self.assertTrue(isinstance(cur_mem, six.integer_types))
95 self.assertTrue(isinstance(peak_mem, six.integer_types))95 self.assertTrue(isinstance(peak_mem, six.integer_types))
96 p.stdin.write('post')96 p.stdin.write(b'post')
97 p.stdin.flush()97 p.stdin.flush()
98 p.stdout.read()98 p.stdout.read()
99 self.assertEqual(0, p.wait())99 self.assertEqual(0, p.wait())

Subscribers

People subscribed via source and target branches

to all changes: