Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / platform / profiler / android_memreport_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 AndroidMemReportProfiler(profiler.Profiler):
13   """Android-specific, collects 'memreport' graphs."""
14
15   def __init__(self, browser_backend, platform_backend, output_path, state):
16     super(AndroidMemReportProfiler, self).__init__(
17         browser_backend, platform_backend, output_path, state)
18     self._html_file = output_path + '.html'
19     self._memreport = subprocess.Popen(
20         [os.path.join(util.GetChromiumSrcDir(),
21                       'tools', 'android', 'memdump', 'memreport.py'),
22          '--manual-graph', '--package', browser_backend.package],
23          stdout=file(self._html_file, 'w'),
24          stdin=subprocess.PIPE)
25
26   @classmethod
27   def name(cls):
28     return 'android-memreport'
29
30   @classmethod
31   def is_supported(cls, browser_type):
32     if browser_type == 'any':
33       return android_browser_finder.CanFindAvailableBrowsers()
34     return browser_type.startswith('android')
35
36   def CollectProfile(self):
37     self._memreport.communicate(input='\n')
38     self._memreport.wait()
39     print 'To view the memory report, open:'
40     print self._html_file
41     return [self._html_file]