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 perf_report_output = open(profile_file, 'r').read()
24 mock_popen = simple_mock.MockObject()
25 mock_popen.ExpectCall('communicate').WillReturn([perf_report_output])
27 mock_subprocess = simple_mock.MockObject()
28 mock_subprocess.ExpectCall(
29 'Popen').WithArgs(simple_mock.DONT_CARE).WillReturn(mock_popen)
30 setattr(mock_subprocess, 'PIPE', simple_mock.MockObject())
32 real_subprocess = perf_profiler.subprocess
33 perf_profiler.subprocess = mock_subprocess
36 perf_profiler.PerfProfiler.GetTopSamples('linux', profile_file, 10),
37 { 'v8::internal::StaticMarkingVisitor::MarkMapContents': 63615201,
38 'v8::internal::RelocIterator::next': 38271931,
39 'v8::internal::LAllocator::MeetConstraintsBetween': 42913933,
40 'v8::internal::FlexibleBodyVisitor::Visit': 31909537,
41 'v8::internal::LiveRange::CreateAssignedOperand': 42913933,
42 'void v8::internal::RelocInfo::Visit': 96878864,
43 'WebCore::HTMLTokenizer::nextToken': 48240439,
44 'v8::internal::Scanner::ScanIdentifierOrKeyword': 46054550,
45 'sk_memset32_SSE2': 45121317,
46 'v8::internal::HeapObject::Size': 39786862
49 perf_profiler.subprocess = real_subprocess