Home | History | Annotate | Download | only in metrics
      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 import unittest
      5 
      6 from metrics import smoothness
      7 from metrics.gpu_rendering_stats import GpuRenderingStats
      8 from telemetry.page import page
      9 from telemetry.page.page_measurement_results import PageMeasurementResults
     10 
     11 class SmoothnessMetricsUnitTest(unittest.TestCase):
     12   def testCalcResultsRealRenderStats(self):
     13     mock_rendering_stats_deltas = {
     14         'totalTimeInSeconds': 1.0,
     15         'numFramesSentToScreen': 100,
     16         'droppedFrameCount': 20,
     17         'numImplThreadScrolls': 50,
     18         'numMainThreadScrolls': 50,
     19         'numLayersDrawn': 240,
     20         'numMissingTiles': 10,
     21         'textureUploadCount': 120,
     22         'totalTextureUploadTimeInSeconds': 1.2,
     23         'totalCommitCount': 130,
     24         'totalCommitTimeInSeconds': 1.3,
     25         'totalDeferredImageDecodeCount': 140,
     26         'totalDeferredImageDecodeTimeInSeconds': 1.4,
     27         'totalDeferredImageCacheHitCount': 30,
     28         'totalImageGatheringCount': 150,
     29         'totalImageGatheringTimeInSeconds': 1.5,
     30         'totalTilesAnalyzed': 160,
     31         'totalTileAnalysisTimeInSeconds': 1.6,
     32         'solidColorTilesAnalyzed': 40,
     33         'inputEventCount': 170,
     34         'totalInputLatency': 1.7,
     35         'touchUICount': 180,
     36         'totalTouchUILatency': 1.8,
     37         'touchAckedCount': 190,
     38         'totalTouchAckedLatency': 1.9,
     39         'scrollUpdateCount': 200,
     40         'totalScrollUpdateLatency': 2.0}
     41     stats = GpuRenderingStats(mock_rendering_stats_deltas)
     42 
     43     res = PageMeasurementResults()
     44     res.WillMeasurePage(page.Page('http://foo.com/', None))
     45     smoothness.CalcResults(stats, res)
     46     res.DidMeasurePage()
     47 
     48     # Scroll Results
     49     self.assertAlmostEquals(
     50         1.0 / 100.0 * 1000.0,
     51         res.page_results[0]['mean_frame_time'].value, 2)
     52     self.assertAlmostEquals(
     53         20.0 / 100.0 * 100.0,
     54         res.page_results[0]['dropped_percent'].value)
     55     self.assertAlmostEquals(
     56         50.0 / (50.0 + 50.0) * 100.0,
     57         res.page_results[0]['percent_impl_scrolled'].value)
     58     self.assertAlmostEquals(
     59         240.0 / 100.0,
     60         res.page_results[0]['average_num_layers_drawn'].value)
     61     self.assertAlmostEquals(
     62         10.0 / 100.0,
     63         res.page_results[0]['average_num_missing_tiles'].value)
     64 
     65     # Texture Upload Results
     66     self.assertAlmostEquals(
     67         1.3 / 130.0 * 1000.0,
     68         res.page_results[0]['average_commit_time'].value)
     69     self.assertEquals(
     70         120,
     71         res.page_results[0]['texture_upload_count'].value)
     72     self.assertEquals(
     73         1.2,
     74         res.page_results[0]['total_texture_upload_time'].value)
     75 
     76     # Image Decoding Results
     77     self.assertEquals(
     78         140,
     79         res.page_results[0]['total_deferred_image_decode_count'].value)
     80     self.assertEquals(
     81         30,
     82         res.page_results[0]['total_image_cache_hit_count'].value)
     83     self.assertAlmostEquals(
     84         1.5 / 150.0 * 1000.0,
     85         res.page_results[0]['average_image_gathering_time'].value)
     86     self.assertEquals(
     87         1.4,
     88         res.page_results[0]['total_deferred_image_decoding_time'].value)
     89 
     90     # Tile Analysis Results
     91     self.assertEquals(
     92         160,
     93         res.page_results[0]['total_tiles_analyzed'].value)
     94     self.assertEquals(
     95         40,
     96         res.page_results[0]['solid_color_tiles_analyzed'].value)
     97     self.assertAlmostEquals(
     98         1.6 / 160.0 * 1000.0,
     99         res.page_results[0]['average_tile_analysis_time'].value)
    100 
    101     # Latency Results
    102     self.assertAlmostEquals(
    103         1.7 / 170.0 * 1000.0,
    104         res.page_results[0]['average_latency'].value)
    105     self.assertAlmostEquals(
    106         1.8 / 180.0 * 1000.0,
    107         res.page_results[0]['average_touch_ui_latency'].value)
    108     self.assertAlmostEquals(
    109         1.9 / 190.0 * 1000.0,
    110         res.page_results[0]['average_touch_acked_latency'].value)
    111     self.assertAlmostEquals(
    112         2.0 / 200.0 * 1000.0,
    113         res.page_results[0]['average_scroll_update_latency'].value)
    114