8b1fe6f1a3256767cf5d7ff49aa2646e6983b0e0
[platform/framework/web/crosswalk.git] / src / tools / perf / record_android_profile.py
1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 import os
7 import sys
8 import tempfile
9
10 sys.path.append(os.path.join(
11   os.path.dirname(os.path.realpath(__file__)), os.pardir, 'telemetry'))
12
13 from telemetry.core import browser_finder
14 from telemetry.core import browser_options
15
16
17 def _RunPrebuilt(options):
18   browser_to_create = browser_finder.FindBrowser(options)
19   with browser_to_create.Create() as browser:
20     browser.Start()
21     output_file = os.path.join(tempfile.mkdtemp(), options.profiler)
22     raw_input('Press enter to start profiling...')
23     print '>> Starting profiler', options.profiler
24     browser.StartProfiling(options.profiler, output_file)
25     print 'Press enter or CTRL+C to stop'
26     try:
27       raw_input()
28     except KeyboardInterrupt:
29       pass
30     finally:
31       browser.StopProfiling()
32     print '<< Stopped profiler ', options.profiler
33
34
35 if __name__ == '__main__':
36   browser_finder_options = browser_options.BrowserFinderOptions()
37   parser = browser_finder_options.CreateParser('')
38   profiler_options, _ = parser.parse_args()
39   sys.exit(_RunPrebuilt(profiler_options))