| 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 Number of known instrumented objects or None if it is not available. |
| 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 Number of known instrumented objects that are not allocated by tcmalloc, |
| 751 None if it is not available. |
| 752 """ |
| 753 memory_block = self.FindMemoryBlock(['ProcessPrivateMemory', |
| 754 'InstrumentedButNotAllocatedObjectsCount']) |
| 755 if not memory_block is None: |
| 756 return memory_block['size'] |
| 757 return None |
| 758 |
| 729 def FindMemoryBlock(self, path): | 759 def FindMemoryBlock(self, path): |
| 730 """Find memory block with given path. | 760 """Find memory block with given path. |
| 731 | 761 |
| 732 Args: | 762 Args: |
| 733 path: Array of block names, first element is the root block | 763 path: Array of block names, first element is the root block |
| 734 name, last one is the name of the block to find. | 764 name, last one is the name of the block to find. |
| 735 | 765 |
| 736 Returns: | 766 Returns: |
| 737 Memory block with given path or None. | 767 Memory block with given path or None. |
| 738 """ | 768 """ |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1152 | 1182 |
| 1153 Returns: | 1183 Returns: |
| 1154 A human-readable string representation of the given number of bytes. | 1184 A human-readable string representation of the given number of bytes. |
| 1155 """ | 1185 """ |
| 1156 if num_bytes < 1024: | 1186 if num_bytes < 1024: |
| 1157 return '%d B' % num_bytes | 1187 return '%d B' % num_bytes |
| 1158 elif num_bytes < 1048576: | 1188 elif num_bytes < 1048576: |
| 1159 return '%.2f KB' % (num_bytes / 1024.0) | 1189 return '%.2f KB' % (num_bytes / 1024.0) |
| 1160 else: | 1190 else: |
| 1161 return '%.2f MB' % (num_bytes / 1048576.0) | 1191 return '%.2f MB' % (num_bytes / 1048576.0) |
| OLD | NEW |