• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 StringIO
6import unittest
7
8from measurements import loading_measurement_analyzer
9from telemetry.core import util
10
11class LoadingMeasurementAnalyzerUnitTest(unittest.TestCase):
12
13  # TODO(tonyg): Remove this backfill when we can assume python 2.7 everywhere.
14  def assertIn(self, first, second, _=None):
15    self.assertTrue(first in second,
16                    msg="'%s' not found in '%s'" % (first, second))
17
18  def testLoadingProfile(self):
19    output = StringIO.StringIO()
20    csv_path = os.path.join(
21        util.GetChromiumSrcDir(),
22        'tools', 'perf', 'measurements','test_data', 'loading_profile.csv')
23    loading_measurement_analyzer.main([csv_path], stdout=output)
24    output = output.getvalue()
25
26    # Get the summary right.
27    self.assertIn('Total URLs: 9', output)
28    self.assertIn('Total page load time: 51s', output)
29    self.assertIn('Average page load time: 5621ms', output)
30
31    # Spot check a few samples.
32    self.assertIn('WTF::IntHash::hash:  1359797948period  1.1%', output)
33    self.assertIn('WebCore::rangesIntersect:   648335678period  0.5%', output)
34    self.assertIn('v8::internal::Scanner::Scan:    19668346period  0.0', output)
35
36  def testLoadingTimeline(self):
37    output = StringIO.StringIO()
38    csv_path = os.path.join(
39        util.GetChromiumSrcDir(),
40        'tools', 'perf', 'measurements','test_data', 'loading_timeline.csv')
41    loading_measurement_analyzer.main([csv_path], stdout=output)
42    output = output.getvalue()
43
44    # Get the summary right.
45    self.assertIn('Total URLs: 9', output)
46    self.assertIn('Total page load time: 4s', output)
47    self.assertIn('Average page load time: 422ms', output)
48    self.assertIn('Total CPU time: 4s', output)
49    self.assertIn('Average CPU time: 430ms', output)
50
51    # Spot check a few samples.
52    self.assertIn('EvaluateScript:           0s  19.0%', output)
53    self.assertIn('ParseHTML:           0s  9.4%', output)
54    self.assertIn('GCEvent:           0s  3.7%', output)
55