Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / profiler / android_screen_recorder_profiler.py
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import os
6 import subprocess
7
8 from telemetry.core import util
9 from telemetry.core.backends.chrome import android_browser_finder
10 from telemetry.core.platform import profiler
11
12 class AndroidScreenRecordingProfiler(profiler.Profiler):
13   """Captures a screen recording on Android."""
14
15   def __init__(self, browser_backend, platform_backend, output_path, state):
16     super(AndroidScreenRecordingProfiler, self).__init__(
17         browser_backend, platform_backend, output_path, state)
18     self._output_path = output_path + '.mp4'
19     self._recorder = subprocess.Popen(
20         [os.path.join(util.GetChromiumSrcDir(), 'build', 'android',
21                       'screenshot.py'),
22          '--video',
23          '--file', self._output_path,
24          '--device', browser_backend.adb.device_serial()],
25         stdin=subprocess.PIPE, stdout=subprocess.PIPE)
26
27   @classmethod
28   def name(cls):
29     return 'android-screen-recorder'
30
31   @classmethod
32   def is_supported(cls, browser_type):
33     if browser_type == 'any':
34       return android_browser_finder.CanFindAvailableBrowsers()
35     return browser_type.startswith('android')
36
37   def CollectProfile(self):
38     self._recorder.communicate(input='\n')
39
40     print 'Screen recording saved as %s' % self._output_path
41     print 'To view, open in Chrome or a video player'
42     return [self._output_path]