Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Unified Diff: tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py

Issue 539303002: [telemetry] Fix MSR power monitor when Python bitness doesn't match OS bitness. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/telemetry/bin/win/winring0.zip.sha1 ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py
diff --git a/tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py b/tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py
index 801607ad5663a05efa684bb1730f2c5b3c66b812..74224ee2bc4a18fc350c66f2fd73a11b452a73d5 100644
--- a/tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py
+++ b/tools/telemetry/telemetry/core/platform/power_monitor/msr_power_monitor.py
@@ -7,7 +7,6 @@ import ctypes
import os
import platform
import re
-import shutil
import sys
import zipfile
@@ -33,7 +32,7 @@ WINRING0_STATUS_MESSAGES = (
'Driver not found',
'Driver unloaded by other process',
'Driver not loaded because of executing on Network Drive',
- 'Unkown error',
+ 'Unknown error',
)
@@ -47,24 +46,30 @@ class WinRing0Error(OSError):
@decorators.Cache
def WinRing0Path():
- file_name = 'WinRing0x64' if sys.maxsize > 2 ** 32 else 'WinRing0'
- winring0_path = os.path.join(path.GetTelemetryDir(), 'bin', 'win', 'winring0')
- dll_path = os.path.join(winring0_path, file_name + '.dll')
- driver_path = os.path.join(winring0_path, file_name + '.sys')
+ python_is_64_bit = sys.maxsize > 2 ** 32
+ win_binary_dir = os.path.join(path.GetTelemetryDir(), 'bin', 'win')
+ dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll'
+ dll_path = os.path.join(win_binary_dir, dll_file_name)
+
+ os_is_64_bit = 'PROGRAMFILES(X86)' in os.environ
+ executable_dir = os.path.dirname(sys.executable)
+ driver_file_name = 'WinRing0x64.sys' if os_is_64_bit else 'WinRing0.sys'
+ driver_path = os.path.join(executable_dir, driver_file_name)
# Check for WinRing0 and download if needed.
if not (os.path.exists(dll_path) and os.path.exists(driver_path)):
- zip_path = os.path.join(path.GetTelemetryDir(),
- 'bin', 'win', 'winring0.zip')
+ zip_path = os.path.join(win_binary_dir, 'winring0.zip')
cloud_storage.GetIfChanged(zip_path, bucket=cloud_storage.PUBLIC_BUCKET)
- with zipfile.ZipFile(zip_path, 'r') as zip_file:
- zip_file.extractall(os.path.dirname(zip_path))
- os.remove(zip_path)
-
- # Copy kernel driver to the Python executable's path.
- executable_dir = os.path.dirname(sys.executable)
- if not os.path.exists(os.path.join(executable_dir, file_name + '.sys')):
- shutil.copy(driver_path, executable_dir)
+ try:
+ with zipfile.ZipFile(zip_path, 'r') as zip_file:
+ # Install DLL.
+ if not os.path.exists(dll_path):
+ zip_file.extract(dll_file_name, win_binary_dir)
+ # Install kernel driver.
+ if not os.path.exists(driver_path):
+ zip_file.extract(driver_file_name, executable_dir)
+ finally:
+ os.remove(zip_path)
return dll_path
« no previous file with comments | « tools/telemetry/bin/win/winring0.zip.sha1 ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698