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 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 Args: | 844 Args: |
845 reply_dict: A dictionary object representing the reply message received | 845 reply_dict: A dictionary object representing the reply message received |
846 from the remote inspector. | 846 from the remote inspector. |
847 """ | 847 """ |
848 if 'result' in reply_dict: | 848 if 'result' in reply_dict: |
849 # This is the result message associated with a previously-sent request. | 849 # This is the result message associated with a previously-sent request. |
850 request = self._remote_inspector_thread.GetRequestWithId( | 850 request = self._remote_inspector_thread.GetRequestWithId( |
851 reply_dict['id']) | 851 reply_dict['id']) |
852 if 'frameTree' in reply_dict['result']: | 852 if 'frameTree' in reply_dict['result']: |
853 self._url = reply_dict['result']['frameTree']['frame']['url'] | 853 self._url = reply_dict['result']['frameTree']['frame']['url'] |
854 elif 'method' in reply_dict: | 854 elif request.method == self._agent_name + '.getHeapSnapshot': |
855 # This is an auxiliary message sent from the remote Chrome instance. | |
856 if reply_dict['method'] == self._agent_name + '.addProfileHeader': | |
857 snapshot_req = ( | |
858 self._remote_inspector_thread.GetFirstUnfulfilledRequest( | |
859 self._agent_name + '.takeHeapSnapshot')) | |
860 if snapshot_req: | |
861 snapshot_req.results['uid'] = reply_dict['params']['header']['uid'] | |
862 elif reply_dict['method'] == self._agent_name + '.addHeapSnapshotChunk': | |
863 self._current_heap_snapshot.append(reply_dict['params']['chunk']) | |
864 elif reply_dict['method'] == self._agent_name + '.finishHeapSnapshot': | |
865 # A heap snapshot has been completed. Analyze and output the data. | 855 # A heap snapshot has been completed. Analyze and output the data. |
866 self._logger.debug('Heap snapshot taken: %s', self._url) | 856 self._logger.debug('Heap snapshot taken: %s', self._url) |
867 # TODO(dennisjeffrey): Parse the heap snapshot on-the-fly as the data | 857 # TODO(dennisjeffrey): Parse the heap snapshot on-the-fly as the data |
868 # is coming in over the wire, so we can avoid storing the entire | 858 # is coming in over the wire, so we can avoid storing the entire |
869 # snapshot string in memory. | 859 # snapshot string in memory. |
870 raw_snapshot_data = ''.join(self._current_heap_snapshot) | 860 raw_snapshot_data = ''.join(self._current_heap_snapshot) |
871 self._collected_heap_snapshot_data = { | 861 self._collected_heap_snapshot_data = { |
872 'url': self._url, | 862 'url': self._url, |
873 'raw_data': raw_snapshot_data} | 863 'raw_data': raw_snapshot_data} |
874 if include_summary: | 864 if include_summary: |
875 self._logger.debug('Now analyzing heap snapshot...') | 865 self._logger.debug('Now analyzing heap snapshot...') |
876 parser = _V8HeapSnapshotParser() | 866 parser = _V8HeapSnapshotParser() |
877 time_start = time.time() | 867 time_start = time.time() |
878 self._logger.debug('Raw snapshot data size: %.2f MB', | 868 self._logger.debug('Raw snapshot data size: %.2f MB', |
879 len(raw_snapshot_data) / (1024.0 * 1024.0)) | 869 len(raw_snapshot_data) / (1024.0 * 1024.0)) |
880 result = parser.ParseSnapshotData(raw_snapshot_data) | 870 result = parser.ParseSnapshotData(raw_snapshot_data) |
881 self._logger.debug('Time to parse data: %.2f sec', | 871 self._logger.debug('Time to parse data: %.2f sec', |
882 time.time() - time_start) | 872 time.time() - time_start) |
883 count = result['total_v8_node_count'] | 873 count = result['total_v8_node_count'] |
884 self._collected_heap_snapshot_data['total_v8_node_count'] = count | 874 self._collected_heap_snapshot_data['total_v8_node_count'] = count |
885 total_size = result['total_shallow_size'] | 875 total_size = result['total_shallow_size'] |
886 self._collected_heap_snapshot_data['total_heap_size'] = total_size | 876 self._collected_heap_snapshot_data['total_heap_size'] = total_size |
887 | 877 |
888 done_condition.acquire() | 878 done_condition.acquire() |
889 done_condition.notify() | 879 done_condition.notify() |
890 done_condition.release() | 880 done_condition.release() |
| 881 elif 'method' in reply_dict: |
| 882 # This is an auxiliary message sent from the remote Chrome instance. |
| 883 if reply_dict['method'] == self._agent_name + '.addProfileHeader': |
| 884 snapshot_req = ( |
| 885 self._remote_inspector_thread.GetFirstUnfulfilledRequest( |
| 886 self._agent_name + '.takeHeapSnapshot')) |
| 887 if snapshot_req: |
| 888 snapshot_req.results['uid'] = reply_dict['params']['header']['uid'] |
| 889 elif reply_dict['method'] == self._agent_name + '.addHeapSnapshotChunk': |
| 890 self._current_heap_snapshot.append(reply_dict['params']['chunk']) |
891 | 891 |
892 # Tell the remote inspector to take a v8 heap snapshot, then wait until | 892 # Tell the remote inspector to take a v8 heap snapshot, then wait until |
893 # the snapshot information is available to return. | 893 # the snapshot information is available to return. |
894 self._remote_inspector_thread.PerformAction(HEAP_SNAPSHOT_MESSAGES, | 894 self._remote_inspector_thread.PerformAction(HEAP_SNAPSHOT_MESSAGES, |
895 HandleReply) | 895 HandleReply) |
896 | 896 |
897 done_condition.acquire() | 897 done_condition.acquire() |
898 done_condition.wait() | 898 done_condition.wait() |
899 done_condition.release() | 899 done_condition.release() |
900 | 900 |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1202 False otherwise. | 1202 False otherwise. |
1203 | 1203 |
1204 Raises: | 1204 Raises: |
1205 RuntimeError: If remote Chromium version hasn't been fetched yet. | 1205 RuntimeError: If remote Chromium version hasn't been fetched yet. |
1206 """ | 1206 """ |
1207 if not hasattr(self, '_version'): | 1207 if not hasattr(self, '_version'): |
1208 raise RuntimeError('Browser revision has not been fetched yet.') | 1208 raise RuntimeError('Browser revision has not been fetched yet.') |
1209 version = self._version['browser'] | 1209 version = self._version['browser'] |
1210 | 1210 |
1211 return version['day'] > day_number | 1211 return version['day'] > day_number |
OLD | NEW |