Skip to content

Commit 0b3653b

Browse files
committed
migrate cpu-usage-over-time.py to python 3
The only change here is a fix for `sys.platform` on Linux. Python 3.3 changed the API to return "linux" instead of "linux2"/"linux3", so this commit uses `.startswith("python")` to make the code work on Python 3 without breaking Python 2.
1 parent d04ec47 commit 0b3653b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/ci/cpu-usage-over-time.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# ignore-tidy-linelength
33

44
# This is a small script that we use on CI to collect CPU usage statistics of
@@ -37,7 +37,10 @@
3737
import sys
3838
import time
3939

40-
if sys.platform == 'linux2':
40+
# Python 3.3 changed the value of `sys.platform` on Linux from "linux2" to just
41+
# "linux". We check here with `.startswith` to keep compatibility with older
42+
# Python versions (especially Python 2.7).
43+
if sys.platform.startswith('linux'):
4144
class State:
4245
def __init__(self):
4346
with open('/proc/stat', 'r') as file:

src/ci/scripts/collect-cpu-stats.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
set -euo pipefail
77
IFS=$'\n\t'
88

9-
python src/ci/cpu-usage-over-time.py &> cpu-usage.csv &
9+
python3 src/ci/cpu-usage-over-time.py &> cpu-usage.csv &

0 commit comments

Comments
 (0)