OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Provides an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
6 | 6 |
7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
8 """ | 8 """ |
9 | 9 |
10 import collections | 10 import collections |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 | 312 |
313 logging.info('>>> $' + install_command) | 313 logging.info('>>> $' + install_command) |
314 return self._adb.SendCommand(install_command, timeout_time=2*60) | 314 return self._adb.SendCommand(install_command, timeout_time=2*60) |
315 | 315 |
316 def MakeSystemFolderWritable(self): | 316 def MakeSystemFolderWritable(self): |
317 """Remounts the /system folder rw. """ | 317 """Remounts the /system folder rw. """ |
318 out = self._adb.SendCommand('remount') | 318 out = self._adb.SendCommand('remount') |
319 if out.strip() != 'remount succeeded': | 319 if out.strip() != 'remount succeeded': |
320 raise errors.MsgException('Remount failed: %s' % out) | 320 raise errors.MsgException('Remount failed: %s' % out) |
321 | 321 |
322 def WaitForSdCardReady(self, timeout_time=20): | |
bulach
2012/07/12 07:39:10
nit: please, avoid using default params... it's a
Wei James(wistoch)
2012/07/12 08:03:32
fixed. thanks
| |
323 """Wait for the SD card ready before pushing data into it""" | |
bulach
2012/07/12 07:39:10
nit: end this sentence with a period.
Wei James(wistoch)
2012/07/12 08:03:32
fixed. thanks
| |
324 logging.info("Waiting for SD card ready...") | |
bulach
2012/07/12 07:39:10
nit: use single quotes here.
Wei James(wistoch)
2012/07/12 08:03:32
fixed. thanks
| |
325 sdcard_ready = False | |
326 attempts = 0 | |
327 wait_period = 5 | |
328 while not sdcard_ready and (attempts*wait_period) < timeout_time: | |
bulach
2012/07/12 07:39:10
nit: spaces around *, and I think the parenthesis
Wei James(wistoch)
2012/07/12 08:03:32
fixed. thanks
| |
329 output = self.RunShellCommand("ls /sdcard/") | |
bulach
2012/07/12 07:39:10
nit: single quote.
Wei James(wistoch)
2012/07/12 08:03:32
fixed. thanks
| |
330 if len(output) > 0: | |
bulach
2012/07/12 07:39:10
is this condition right? I think ls nonexistingdir
Wei James(wistoch)
2012/07/12 08:03:32
ths /sdcard/ is a symbolic link to /mnt/sdcard and
| |
331 sdcard_ready = True | |
332 else: | |
333 time.sleep(wait_period) | |
334 attempts += 1 | |
335 if not sdcard_ready: | |
336 raise errors.WaitForResponseTimedOutError( | |
337 "SD card not ready after %s seconds" %timeout_time) | |
338 | |
322 # It is tempting to turn this function into a generator, however this is not | 339 # It is tempting to turn this function into a generator, however this is not |
323 # possible without using a private (local) adb_shell instance (to ensure no | 340 # possible without using a private (local) adb_shell instance (to ensure no |
324 # other command interleaves usage of it), which would defeat the main aim of | 341 # other command interleaves usage of it), which would defeat the main aim of |
325 # being able to reuse the adb shell instance across commands. | 342 # being able to reuse the adb shell instance across commands. |
326 def RunShellCommand(self, command, timeout_time=20, log_result=True): | 343 def RunShellCommand(self, command, timeout_time=20, log_result=True): |
327 """Send a command to the adb shell and return the result. | 344 """Send a command to the adb shell and return the result. |
328 | 345 |
329 Args: | 346 Args: |
330 command: String containing the shell command to send. Must not include | 347 command: String containing the shell command to send. Must not include |
331 the single quotes as we use them to escape the whole command. | 348 the single quotes as we use them to escape the whole command. |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
832 pid_list = self.ExtractPid(package) | 849 pid_list = self.ExtractPid(package) |
833 smaps = collections.defaultdict(dict) | 850 smaps = collections.defaultdict(dict) |
834 | 851 |
835 for pid in pid_list: | 852 for pid in pid_list: |
836 usage_dict_per_pid, smaps_per_pid = self.GetMemoryUsageForPid(pid) | 853 usage_dict_per_pid, smaps_per_pid = self.GetMemoryUsageForPid(pid) |
837 smaps[pid] = smaps_per_pid | 854 smaps[pid] = smaps_per_pid |
838 for (key, value) in usage_dict_per_pid.items(): | 855 for (key, value) in usage_dict_per_pid.items(): |
839 usage_dict[key] += value | 856 usage_dict[key] += value |
840 | 857 |
841 return usage_dict, smaps | 858 return usage_dict, smaps |
OLD | NEW |