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.
8 from telemetry.core import util
9 from telemetry.core.platform.profiler import perf_profiler
10 from telemetry.unittest import options_for_unittests
11 from telemetry.unittest import simple_mock
13 class TestPerfProfiler(unittest.TestCase):
14 def testPerfProfiler(self):
15 options = options_for_unittests.GetCopy()
16 if not perf_profiler.PerfProfiler.is_supported(options.browser_type):
17 logging.warning('PerfProfiler is not supported. Skipping test')
20 profile_file = os.path.join(
21 util.GetUnittestDataDir(), 'perf_report_output.txt')
22 with open(profile_file) as f:
23 perf_report_output = f.read()
25 mock_popen = simple_mock.MockObject()
26 mock_popen.ExpectCall('communicate').WillReturn([perf_report_output])
28 mock_subprocess = simple_mock.MockObject()
29 mock_subprocess.ExpectCall(
30 'Popen').WithArgs(simple_mock.DONT_CARE).WillReturn(mock_popen)
31 setattr(mock_subprocess, 'PIPE', simple_mock.MockObject())
33 real_subprocess = perf_profiler.subprocess
34 perf_profiler.subprocess = mock_subprocess
37 perf_profiler.PerfProfiler.GetTopSamples(profile_file, 10),
38 { 'v8::internal::StaticMarkingVisitor::MarkMapContents': 63615201,
39 'v8::internal::RelocIterator::next': 38271931,
40 'v8::internal::LAllocator::MeetConstraintsBetween': 42913933,
41 'v8::internal::FlexibleBodyVisitor::Visit': 31909537,
42 'v8::internal::LiveRange::CreateAssignedOperand': 42913933,
43 'void v8::internal::RelocInfo::Visit': 96878864,
44 'WebCore::HTMLTokenizer::nextToken': 48240439,
45 'v8::internal::Scanner::ScanIdentifierOrKeyword': 46054550,
46 'sk_memset32_SSE2': 45121317,
47 'v8::internal::HeapObject::Size': 39786862
50 perf_profiler.subprocess = real_subprocess