| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 import base64 | 7 import base64 |
| 8 import gzip | 8 import gzip |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| 11 import os | 11 import os |
| 12 import re | 12 import re |
| 13 import select |
| 13 import shutil | 14 import shutil |
| 14 import sys | 15 import sys |
| 15 import threading | 16 import threading |
| 16 import time | 17 import time |
| 17 import webbrowser | 18 import webbrowser |
| 18 import zipfile | 19 import zipfile |
| 19 import zlib | 20 import zlib |
| 20 | 21 |
| 21 from pylib import android_commands | 22 from pylib import android_commands |
| 22 from pylib import cmd_helper | 23 from pylib import cmd_helper |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 for host_file in host_files: | 257 for host_file in host_files: |
| 257 z.write(host_file) | 258 z.write(host_file) |
| 258 os.unlink(host_file) | 259 os.unlink(host_file) |
| 259 | 260 |
| 260 | 261 |
| 261 def _PrintMessage(heading, eol='\n'): | 262 def _PrintMessage(heading, eol='\n'): |
| 262 sys.stdout.write('%s%s' % (heading, eol)) | 263 sys.stdout.write('%s%s' % (heading, eol)) |
| 263 sys.stdout.flush() | 264 sys.stdout.flush() |
| 264 | 265 |
| 265 | 266 |
| 267 def _WaitForEnter(timeout): |
| 268 select.select([sys.stdin], [], [], timeout) |
| 269 |
| 270 |
| 266 def _StartTracing(controllers, interval): | 271 def _StartTracing(controllers, interval): |
| 267 for controller in controllers: | 272 for controller in controllers: |
| 268 controller.StartTracing(interval) | 273 controller.StartTracing(interval) |
| 269 | 274 |
| 270 | 275 |
| 271 def _StopTracing(controllers): | 276 def _StopTracing(controllers): |
| 272 for controller in controllers: | 277 for controller in controllers: |
| 273 controller.StopTracing() | 278 controller.StopTracing() |
| 274 | 279 |
| 275 | 280 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 300 _PrintMessage('done') | 305 _PrintMessage('done') |
| 301 _PrintMessage('Trace written to %s' % os.path.abspath(result)) | 306 _PrintMessage('Trace written to %s' % os.path.abspath(result)) |
| 302 return result | 307 return result |
| 303 | 308 |
| 304 | 309 |
| 305 def _CaptureAndPullTrace(controllers, interval, output, compress, write_html): | 310 def _CaptureAndPullTrace(controllers, interval, output, compress, write_html): |
| 306 trace_type = ' + '.join(map(str, controllers)) | 311 trace_type = ' + '.join(map(str, controllers)) |
| 307 try: | 312 try: |
| 308 _StartTracing(controllers, interval) | 313 _StartTracing(controllers, interval) |
| 309 if interval: | 314 if interval: |
| 310 _PrintMessage('Capturing %d-second %s. Press Ctrl-C to stop early...' % \ | 315 _PrintMessage('Capturing %d-second %s. Press Enter to stop early...' % \ |
| 311 (interval, trace_type), eol='') | 316 (interval, trace_type), eol='') |
| 312 time.sleep(interval) | 317 _WaitForEnter(interval) |
| 313 else: | 318 else: |
| 314 _PrintMessage('Capturing %s. Press Enter to stop...' % trace_type, eol='') | 319 _PrintMessage('Capturing %s. Press Enter to stop...' % trace_type, eol='') |
| 315 raw_input() | 320 raw_input() |
| 316 except KeyboardInterrupt: | |
| 317 _PrintMessage('\nInterrupted...', eol='') | |
| 318 finally: | 321 finally: |
| 319 _StopTracing(controllers) | 322 _StopTracing(controllers) |
| 320 if interval: | 323 if interval: |
| 321 _PrintMessage('done') | 324 _PrintMessage('done') |
| 322 | 325 |
| 323 return _PullTraces(controllers, output, compress, write_html) | 326 return _PullTraces(controllers, output, compress, write_html) |
| 324 | 327 |
| 325 | 328 |
| 326 def _ComputeChromeCategories(options): | 329 def _ComputeChromeCategories(options): |
| 327 categories = [] | 330 categories = [] |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 options.time if not options.continuous else 0, | 444 options.time if not options.continuous else 0, |
| 442 options.output, | 445 options.output, |
| 443 options.compress, | 446 options.compress, |
| 444 options.html) | 447 options.html) |
| 445 if options.view: | 448 if options.view: |
| 446 webbrowser.open(result) | 449 webbrowser.open(result) |
| 447 | 450 |
| 448 | 451 |
| 449 if __name__ == '__main__': | 452 if __name__ == '__main__': |
| 450 sys.exit(main()) | 453 sys.exit(main()) |
| OLD | NEW |