perf_profiler_unittest.py revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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. 4import os 5import logging 6import unittest 7 8from telemetry.core import util 9from telemetry.core.platform.profiler import perf_profiler 10from telemetry.unittest import options_for_unittests 11from telemetry.unittest import simple_mock 12 13class 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') 18 return 19 20 profile_file = os.path.join( 21 util.GetUnittestDataDir(), 'perf_report_output.txt') 22 perf_report_output = open(profile_file, 'r').read() 23 24 mock_popen = simple_mock.MockObject() 25 mock_popen.ExpectCall('communicate').WillReturn([perf_report_output]) 26 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()) 31 32 real_subprocess = perf_profiler.subprocess 33 perf_profiler.subprocess = mock_subprocess 34 try: 35 self.assertEqual( 36 perf_profiler.PerfProfiler.GetTopSamples(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 47 }) 48 finally: 49 perf_profiler.subprocess = real_subprocess 50