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 FindMemoryBlock: Given an array of memory block names return the block. | 714 FindMemoryBlock: Given an array of memory block names return the block. |
dennis_jeffrey
2012/10/04 01:16:33
Add the two new public methods to the docstring he
yurys
2012/10/04 15:07:47
Done.
| |
715 """ | 715 """ |
716 def __init__(self, root_block): | 716 def __init__(self, root_block): |
717 self._root = root_block | 717 self._root = root_block |
718 | 718 |
719 def GetProcessPrivateMemorySize(self): | 719 def GetProcessPrivateMemorySize(self): |
720 return self._root['size'] | 720 return self._root['size'] |
721 | 721 |
722 def GetUnknownSize(self): | 722 def GetUnknownSize(self): |
723 """Size of the memory whose owner is unknown to DevTools.""" | 723 """Size of the memory whose owner is unknown to DevTools.""" |
724 known_size = 0 | 724 known_size = 0 |
725 for child in self._root['children']: | 725 for child in self._root['children']: |
726 known_size += child['size'] | 726 known_size += child['size'] |
727 return self.GetProcessPrivateMemorySize() - known_size | 727 return self.GetProcessPrivateMemorySize() - known_size |
728 | 728 |
729 def GetInstrumentedObjectsCount(self): | |
dennis_jeffrey
2012/10/04 01:16:33
add a docstring and mention what is returned if th
yurys
2012/10/04 15:07:47
Done.
| |
730 memory_block = self.FindMemoryBlock(['ProcessPrivateMemory', | |
731 'InstrumentedObjectsCount']) | |
732 if not memory_block is None: | |
733 return memory_block['size'] | |
734 return -1 | |
dennis_jeffrey
2012/10/04 01:16:33
would returning None be preferable to a -1? That
yurys
2012/10/04 15:07:47
Good idea, fixed!
| |
735 | |
736 def GetNumberOfInstrumentedObjectsNotInHeap(self): | |
dennis_jeffrey
2012/10/04 01:16:33
add a docstring and mention what is returned if th
yurys
2012/10/04 15:07:47
Done.
| |
737 memory_block = self.FindMemoryBlock(['ProcessPrivateMemory', | |
738 'InstrumentedButNotAllocatedObjectsCount']) | |
739 if not memory_block is None: | |
740 return memory_block['size'] | |
741 return -1 | |
dennis_jeffrey
2012/10/04 01:16:33
same comment as line 734 above
yurys
2012/10/04 15:07:47
Done.
| |
742 | |
729 def FindMemoryBlock(self, path): | 743 def FindMemoryBlock(self, path): |
730 """Find memory block with given path. | 744 """Find memory block with given path. |
731 | 745 |
732 Args: | 746 Args: |
733 path: Array of block names, first element is the root block | 747 path: Array of block names, first element is the root block |
734 name, last one is the name of the block to find. | 748 name, last one is the name of the block to find. |
735 | 749 |
736 Returns: | 750 Returns: |
737 Memory block with given path or None. | 751 Memory block with given path or None. |
738 """ | 752 """ |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1152 | 1166 |
1153 Returns: | 1167 Returns: |
1154 A human-readable string representation of the given number of bytes. | 1168 A human-readable string representation of the given number of bytes. |
1155 """ | 1169 """ |
1156 if num_bytes < 1024: | 1170 if num_bytes < 1024: |
1157 return '%d B' % num_bytes | 1171 return '%d B' % num_bytes |
1158 elif num_bytes < 1048576: | 1172 elif num_bytes < 1048576: |
1159 return '%.2f KB' % (num_bytes / 1024.0) | 1173 return '%.2f KB' % (num_bytes / 1024.0) |
1160 else: | 1174 else: |
1161 return '%.2f MB' % (num_bytes / 1048576.0) | 1175 return '%.2f MB' % (num_bytes / 1048576.0) |
OLD | NEW |