Skip to content

Commit

Permalink
migrate cpu-usage-over-time.py to python 3
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pietroalbini committed Jul 6, 2021
1 parent d04ec47 commit 0b3653b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/ci/cpu-usage-over-time.py
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# ignore-tidy-linelength

# This is a small script that we use on CI to collect CPU usage statistics of
Expand Down Expand Up @@ -37,7 +37,10 @@
import sys
import time

if sys.platform == 'linux2':
# Python 3.3 changed the value of `sys.platform` on Linux from "linux2" to just
# "linux". We check here with `.startswith` to keep compatibility with older
# Python versions (especially Python 2.7).
if sys.platform.startswith('linux'):
class State:
def __init__(self):
with open('/proc/stat', 'r') as file:
Expand Down
2 changes: 1 addition & 1 deletion src/ci/scripts/collect-cpu-stats.sh
Expand Up @@ -6,4 +6,4 @@
set -euo pipefail
IFS=$'\n\t'

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

0 comments on commit 0b3653b

Please sign in to comment.