OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 """Android-specific implementation of the core backend interfaces. | 5 """Android-specific implementation of the core backend interfaces. |
6 | 6 |
7 See core/backends.py for more docs. | 7 See core/backends.py for more docs. |
8 """ | 8 """ |
9 | 9 |
10 import datetime | 10 import datetime |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 def DumpNativeHeap(self): | 321 def DumpNativeHeap(self): |
322 """Grabs and parses malloc traces through am dumpheap -n.""" | 322 """Grabs and parses malloc traces through am dumpheap -n.""" |
323 # TODO(primiano): grab also mmap bt (depends on pending framework change). | 323 # TODO(primiano): grab also mmap bt (depends on pending framework change). |
324 dump_file_path = _DUMPHEAP_OUT_FILE_PATH % self.pid | 324 dump_file_path = _DUMPHEAP_OUT_FILE_PATH % self.pid |
325 cmd = 'am dumpheap -n %d %s' % (self.pid, dump_file_path) | 325 cmd = 'am dumpheap -n %d %s' % (self.pid, dump_file_path) |
326 self.device.underlying_device.RunShellCommand(cmd) | 326 self.device.underlying_device.RunShellCommand(cmd) |
327 # TODO(primiano): Some pre-KK versions of Android might need a sleep here | 327 # TODO(primiano): Some pre-KK versions of Android might need a sleep here |
328 # as, IIRC, 'am dumpheap' did not wait for the dump to be completed before | 328 # as, IIRC, 'am dumpheap' did not wait for the dump to be completed before |
329 # returning. Double check this and either add a sleep or remove this TODO. | 329 # returning. Double check this and either add a sleep or remove this TODO. |
330 dump_out = self.device.underlying_device.old_interface.GetFileContents( | 330 dump_out = self.device.underlying_device.ReadFile(dump_file_path) |
331 dump_file_path) | |
332 self.device.underlying_device.RunShellCommand('rm %s' % dump_file_path) | 331 self.device.underlying_device.RunShellCommand('rm %s' % dump_file_path) |
333 return dumpheap_native_parser.Parse(dump_out) | 332 return dumpheap_native_parser.Parse(dump_out) |
334 | 333 |
335 def GetStats(self): | 334 def GetStats(self): |
336 """Calculate process CPU/VM stats (CPU stats are relative to last call).""" | 335 """Calculate process CPU/VM stats (CPU stats are relative to last call).""" |
337 # Process must retain its own copy of _last_sys_stats because CPU times | 336 # Process must retain its own copy of _last_sys_stats because CPU times |
338 # are calculated relatively to the last GetStats() call (for the process). | 337 # are calculated relatively to the last GetStats() call (for the process). |
339 cur_sys_stats = self.device.UpdateAndGetSystemStats() | 338 cur_sys_stats = self.device.UpdateAndGetSystemStats() |
340 old_sys_stats = self._last_sys_stats or cur_sys_stats | 339 old_sys_stats = self._last_sys_stats or cur_sys_stats |
341 cur_proc_stats = cur_sys_stats['processes'].get(str(self.pid)) | 340 cur_proc_stats = cur_sys_stats['processes'].get(str(self.pid)) |
(...skipping 14 matching lines...) Expand all Loading... |
356 proc_stats = backends.ProcessStats( | 355 proc_stats = backends.ProcessStats( |
357 threads=cur_proc_stats['n_threads'], | 356 threads=cur_proc_stats['n_threads'], |
358 run_time=run_time, | 357 run_time=run_time, |
359 cpu_usage=cpu_usage, | 358 cpu_usage=cpu_usage, |
360 vm_rss=cur_proc_stats['vm_rss'], | 359 vm_rss=cur_proc_stats['vm_rss'], |
361 page_faults=( | 360 page_faults=( |
362 (cur_proc_stats['maj_faults'] + cur_proc_stats['min_faults']) - | 361 (cur_proc_stats['maj_faults'] + cur_proc_stats['min_faults']) - |
363 (old_proc_stats['maj_faults'] + old_proc_stats['min_faults']))) | 362 (old_proc_stats['maj_faults'] + old_proc_stats['min_faults']))) |
364 self._last_sys_stats = cur_sys_stats | 363 self._last_sys_stats = cur_sys_stats |
365 return proc_stats | 364 return proc_stats |
OLD | NEW |