Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Chrome remote inspector utility for pyauto tests. | 6 """Chrome remote inspector utility for pyauto tests. |
| 7 | 7 |
| 8 This script provides a python interface that acts as a front-end for Chrome's | 8 This script provides a python interface that acts as a front-end for Chrome's |
| 9 remote inspector module, communicating via sockets to interact with Chrome in | 9 remote inspector module, communicating via sockets to interact with Chrome in |
| 10 the same way that the Developer Tools does. This -- in theory -- should allow | 10 the same way that the Developer Tools does. This -- in theory -- should allow |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 class NativeMemorySnapshot(object): | 704 class NativeMemorySnapshot(object): |
| 705 """Class representing native memory snapshot captured by Chromium DevTools. | 705 """Class representing native memory snapshot captured by Chromium DevTools. |
| 706 | 706 |
| 707 It is just a convenient wrapper around the snapshot structure returned over | 707 It is just a convenient wrapper around the snapshot structure returned over |
| 708 the remote debugging protocol. The raw snapshot structure is defined in | 708 the remote debugging protocol. The raw snapshot structure is defined in |
| 709 WebKit/Source/WebCore/inspector/Inspector.json | 709 WebKit/Source/WebCore/inspector/Inspector.json |
| 710 | 710 |
| 711 Public Methods: | 711 Public Methods: |
| 712 GetProcessPrivateMemorySize: The process total size. | 712 GetProcessPrivateMemorySize: The process total size. |
| 713 GetUnknownSize: Size of not instrumented parts. | 713 GetUnknownSize: Size of not instrumented parts. |
| 714 GetInstrumentedObjectsCount: Number of instrumented objects traversed by | |
| 715 DevTools memory instrumentation. | |
| 716 GetNumberOfInstrumentedObjectsNotInHeap: Number of instrumented objects | |
| 717 visited by DevTools memory instrumentation that haven't been allocated | |
| 718 by tcmalloc. | |
| 714 FindMemoryBlock: Given an array of memory block names return the block. | 719 FindMemoryBlock: Given an array of memory block names return the block. |
| 715 """ | 720 """ |
| 716 def __init__(self, root_block): | 721 def __init__(self, root_block): |
| 717 self._root = root_block | 722 self._root = root_block |
| 718 | 723 |
| 719 def GetProcessPrivateMemorySize(self): | 724 def GetProcessPrivateMemorySize(self): |
| 720 return self._root['size'] | 725 return self._root['size'] |
| 721 | 726 |
| 722 def GetUnknownSize(self): | 727 def GetUnknownSize(self): |
| 723 """Size of the memory whose owner is unknown to DevTools.""" | 728 """Size of the memory whose owner is unknown to DevTools.""" |
| 724 known_size = 0 | 729 known_size = 0 |
| 725 for child in self._root['children']: | 730 for child in self._root['children']: |
| 726 known_size += child['size'] | 731 known_size += child['size'] |
| 727 return self.GetProcessPrivateMemorySize() - known_size | 732 return self.GetProcessPrivateMemorySize() - known_size |
| 728 | 733 |
| 734 def GetInstrumentedObjectsCount(self): | |
| 735 """Returns number of objects visited by DevTools memory instrumentation. | |
| 736 | |
| 737 Returns: | |
| 738 None if the number is not available. | |
|
dennis_jeffrey
2012/10/04 22:02:57
nit: I'd prefer the "Returns:" section to fully de
yurys
2012/10/05 07:34:53
Done. Changed the text to "Number of known instrum
| |
| 739 """ | |
| 740 memory_block = self.FindMemoryBlock(['ProcessPrivateMemory', | |
| 741 'InstrumentedObjectsCount']) | |
| 742 if not memory_block is None: | |
| 743 return memory_block['size'] | |
| 744 return None | |
| 745 | |
| 746 def GetNumberOfInstrumentedObjectsNotInHeap(self): | |
| 747 """Returns number of instrumented objects unknown to tcmalloc. | |
| 748 | |
| 749 Returns: | |
| 750 None if the number is not available. | |
| 751 """ | |
| 752 memory_block = self.FindMemoryBlock(['ProcessPrivateMemory', | |
| 753 'InstrumentedButNotAllocatedObjectsCount']) | |
| 754 if not memory_block is None: | |
| 755 return memory_block['size'] | |
| 756 return None | |
| 757 | |
| 729 def FindMemoryBlock(self, path): | 758 def FindMemoryBlock(self, path): |
| 730 """Find memory block with given path. | 759 """Find memory block with given path. |
| 731 | 760 |
| 732 Args: | 761 Args: |
| 733 path: Array of block names, first element is the root block | 762 path: Array of block names, first element is the root block |
| 734 name, last one is the name of the block to find. | 763 name, last one is the name of the block to find. |
| 735 | 764 |
| 736 Returns: | 765 Returns: |
| 737 Memory block with given path or None. | 766 Memory block with given path or None. |
| 738 """ | 767 """ |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 | 1181 |
| 1153 Returns: | 1182 Returns: |
| 1154 A human-readable string representation of the given number of bytes. | 1183 A human-readable string representation of the given number of bytes. |
| 1155 """ | 1184 """ |
| 1156 if num_bytes < 1024: | 1185 if num_bytes < 1024: |
| 1157 return '%d B' % num_bytes | 1186 return '%d B' % num_bytes |
| 1158 elif num_bytes < 1048576: | 1187 elif num_bytes < 1048576: |
| 1159 return '%.2f KB' % (num_bytes / 1024.0) | 1188 return '%.2f KB' % (num_bytes / 1024.0) |
| 1160 else: | 1189 else: |
| 1161 return '%.2f MB' % (num_bytes / 1048576.0) | 1190 return '%.2f MB' % (num_bytes / 1048576.0) |
| OLD | NEW |