]> git.lizzy.rs Git - rust.git/commitdiff
migrate cpu-usage-over-time.py to python 3
authorPietro Albini <pietro@pietroalbini.org>
Tue, 6 Jul 2021 13:45:15 +0000 (15:45 +0200)
committerPietro Albini <pietro@pietroalbini.org>
Tue, 6 Jul 2021 14:34:51 +0000 (16:34 +0200)
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.

src/ci/cpu-usage-over-time.py
src/ci/scripts/collect-cpu-stats.sh

index 78ac060368193964fb3fb8420e63894810802863..267c3964d0d692d2e8e975fa5868943a547c00fc 100644 (file)
@@ -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
@@ -37,7 +37,10 @@ import datetime
 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:
index 08065431f981650e7b000281c288220e80f9d4c6..853b4628fab2f3d1c487afcc46db4018ec9ae988 100755 (executable)
@@ -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 &