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

Unified Diff: tools/skpbench/_adb.py

Issue 2360473002: Add hardware monitoring to skpbench (Closed)
Patch Set: Add hardware monitoring to skpbench Created 4 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 | « no previous file | tools/skpbench/_adb_path.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/skpbench/_adb.py
diff --git a/tools/skpbench/_adb.py b/tools/skpbench/_adb.py
index 6125c8d538fa8cc46ad338abd6d4ef1d1315080a..1769f58e5796d8edf2c2a74adad42914fc4e8933 100644
--- a/tools/skpbench/_adb.py
+++ b/tools/skpbench/_adb.py
@@ -3,17 +3,39 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import re
import subprocess
-def shell(cmd, device_serial=None):
- if device_serial is None:
- subprocess.call(['adb', 'shell', cmd])
- else:
- subprocess.call(['adb', '-s', device_serial, 'shell', cmd])
-
-def check(cmd, device_serial=None):
- if device_serial is None:
- out = subprocess.check_output(['adb', 'shell', cmd])
- else:
- out = subprocess.check_output(['adb', '-s', device_serial, 'shell', cmd])
- return out.rstrip()
+class Adb:
+ def __init__(self, device_serial=None):
+ self.__invocation = ['adb']
+ if device_serial:
+ self.__invocation.extend(['-s', device_serial])
+
+ def shell(self, cmd):
+ subprocess.call(self.__invocation + ['shell', cmd])
+
+ def check(self, cmd):
+ result = subprocess.check_output(self.__invocation + ['shell', cmd])
+ return result.rstrip()
+
+ def check_lines(self, cmd):
+ result = self.check(cmd)
+ return re.split('[\r\n]+', result)
+
+ def get_device_model(self):
+ result = self.check('getprop | grep ro.product.model')
+ result = re.match(r'\[ro.product.model\]:\s*\[(.*)\]', result)
+ return result.group(1) if result else 'unknown_product'
+
+ def is_root(self):
+ return self.check('echo $USER') == 'root'
+
+ def attempt_root(self):
+ if self.is_root():
+ return True
+ subprocess.call(self.__invocation + ['root'])
+ return self.is_root()
+
+ def remount(self):
+ subprocess.call(self.__invocation + ['remount'])
« no previous file with comments | « no previous file | tools/skpbench/_adb_path.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698