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 """Performance snapshot utility for pyauto tests. | 6 """Performance snapshot utility for pyauto tests. |
7 | 7 |
8 Wrapper around Chrome DevTools (mimics the front-end) to collect profiling info | 8 Wrapper around Chrome DevTools (mimics the front-end) to collect profiling info |
9 associated with a Chrome tab. This script collects snapshots of the v8 | 9 associated with a Chrome tab. This script collects snapshots of the v8 |
10 (Javascript engine) heap associated with the Chrome tab. | 10 (Javascript engine) heap associated with the Chrome tab. |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 # Create a DevToolsSocket client and wait for it to complete the remote | 435 # Create a DevToolsSocket client and wait for it to complete the remote |
436 # debugging protocol handshake with the remote Chrome instance. | 436 # debugging protocol handshake with the remote Chrome instance. |
437 result = self._IdentifyDevToolsSocketConnectionInfo(tab_index) | 437 result = self._IdentifyDevToolsSocketConnectionInfo(tab_index) |
438 self._client = _DevToolsSocketClient( | 438 self._client = _DevToolsSocketClient( |
439 verbose, show_socket_messages, result['host'], result['port'], | 439 verbose, show_socket_messages, result['host'], result['port'], |
440 result['path']) | 440 result['path']) |
441 self._client.inspector_thread = self | 441 self._client.inspector_thread = self |
442 while asyncore.socket_map: | 442 while asyncore.socket_map: |
443 if self._client.handshake_done or self._killed: | 443 if self._client.handshake_done or self._killed: |
444 break | 444 break |
445 asyncore.loop(timeout=1, count=1) | 445 asyncore.loop(timeout=1, count=1, use_poll=True) |
446 | 446 |
447 def NotifySocketClientException(self): | 447 def NotifySocketClientException(self): |
448 """Notifies that the _DevToolsSocketClient encountered an exception.""" | 448 """Notifies that the _DevToolsSocketClient encountered an exception.""" |
449 self._killed = True | 449 self._killed = True |
450 | 450 |
451 def NotifyReply(self, msg): | 451 def NotifyReply(self, msg): |
452 """Notifies of a reply message received from the remote Chrome instance. | 452 """Notifies of a reply message received from the remote Chrome instance. |
453 | 453 |
454 Args: | 454 Args: |
455 msg: A string reply message received from the remote Chrome instance; | 455 msg: A string reply message received from the remote Chrome instance; |
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 } | 952 } |
953 """ | 953 """ |
954 snapshotter_thread = _PerformanceSnapshotterThread( | 954 snapshotter_thread = _PerformanceSnapshotterThread( |
955 self._tab_index, self._output_file, self._interval, self._num_snapshots, | 955 self._tab_index, self._output_file, self._interval, self._num_snapshots, |
956 self._verbose, self._show_socket_messages, self._interactive_mode) | 956 self._verbose, self._show_socket_messages, self._interactive_mode) |
957 snapshotter_thread.start() | 957 snapshotter_thread.start() |
958 try: | 958 try: |
959 while asyncore.socket_map: | 959 while asyncore.socket_map: |
960 if not snapshotter_thread.is_alive(): | 960 if not snapshotter_thread.is_alive(): |
961 break | 961 break |
962 asyncore.loop(timeout=1, count=1) | 962 asyncore.loop(timeout=1, count=1, use_poll=True) |
963 except KeyboardInterrupt: | 963 except KeyboardInterrupt: |
964 pass | 964 pass |
965 self._logger.debug('Waiting for snapshotter thread to die...') | 965 self._logger.debug('Waiting for snapshotter thread to die...') |
966 snapshotter_thread.join() | 966 snapshotter_thread.join() |
967 self._logger.debug('Done taking snapshots.') | 967 self._logger.debug('Done taking snapshots.') |
968 return snapshotter_thread.collected_heap_snapshot_data | 968 return snapshotter_thread.collected_heap_snapshot_data |
969 | 969 |
970 def GarbageCollect(self): | 970 def GarbageCollect(self): |
971 """Forces a garbage collection.""" | 971 """Forces a garbage collection.""" |
972 gc_thread = _GarbageCollectThread(self._tab_index, self._verbose, | 972 gc_thread = _GarbageCollectThread(self._tab_index, self._verbose, |
973 self._show_socket_messages) | 973 self._show_socket_messages) |
974 gc_thread.start() | 974 gc_thread.start() |
975 try: | 975 try: |
976 while asyncore.socket_map: | 976 while asyncore.socket_map: |
977 if not gc_thread.is_alive(): | 977 if not gc_thread.is_alive(): |
978 break | 978 break |
979 asyncore.loop(timeout=1, count=1) | 979 asyncore.loop(timeout=1, count=1, use_poll=True) |
980 except KeyboardInterrupt: | 980 except KeyboardInterrupt: |
981 pass | 981 pass |
982 gc_thread.join() | 982 gc_thread.join() |
983 | 983 |
984 def GetMemoryObjectCounts(self): | 984 def GetMemoryObjectCounts(self): |
985 """Retrieves memory object count information. | 985 """Retrieves memory object count information. |
986 | 986 |
987 Returns: | 987 Returns: |
988 A dictionary containing the memory object count information: | 988 A dictionary containing the memory object count information: |
989 { | 989 { |
990 'DOMNodeCount': integer, # Total number of DOM nodes. | 990 'DOMNodeCount': integer, # Total number of DOM nodes. |
991 'EventListenerCount': integer, # Total number of event listeners. | 991 'EventListenerCount': integer, # Total number of event listeners. |
992 } | 992 } |
993 """ | 993 """ |
994 mem_count_thread = _MemoryCountThread(self._tab_index, self._verbose, | 994 mem_count_thread = _MemoryCountThread(self._tab_index, self._verbose, |
995 self._show_socket_messages) | 995 self._show_socket_messages) |
996 mem_count_thread.start() | 996 mem_count_thread.start() |
997 try: | 997 try: |
998 while asyncore.socket_map: | 998 while asyncore.socket_map: |
999 if not mem_count_thread.is_alive(): | 999 if not mem_count_thread.is_alive(): |
1000 break | 1000 break |
1001 asyncore.loop(timeout=1, count=1) | 1001 asyncore.loop(timeout=1, count=1, use_poll=True) |
1002 except KeyboardInterrupt: | 1002 except KeyboardInterrupt: |
1003 pass | 1003 pass |
1004 mem_count_thread.join() | 1004 mem_count_thread.join() |
1005 result = { | 1005 result = { |
1006 'DOMNodeCount': mem_count_thread.dom_node_count, | 1006 'DOMNodeCount': mem_count_thread.dom_node_count, |
1007 'EventListenerCount': mem_count_thread.event_listener_count, | 1007 'EventListenerCount': mem_count_thread.event_listener_count, |
1008 } | 1008 } |
1009 return result | 1009 return result |
1010 | 1010 |
1011 def SetInteractiveMode(self): | 1011 def SetInteractiveMode(self): |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 | 1059 |
1060 if options.interactive_mode: | 1060 if options.interactive_mode: |
1061 snapshotter.SetInteractiveMode() | 1061 snapshotter.SetInteractiveMode() |
1062 | 1062 |
1063 snapshotter.HeapSnapshot() | 1063 snapshotter.HeapSnapshot() |
1064 return 0 | 1064 return 0 |
1065 | 1065 |
1066 | 1066 |
1067 if __name__ == '__main__': | 1067 if __name__ == '__main__': |
1068 sys.exit(main()) | 1068 sys.exit(main()) |
OLD | NEW |