Home | History | Annotate | Download | only in model
      1 <!DOCTYPE html>
      2 <!--
      3 Copyright (c) 2016 The Chromium Authors. All rights reserved.
      4 Use of this source code is governed by a BSD-style license that can be
      5 found in the LICENSE file.
      6 -->
      7 <link rel="import" href="/tracing/model/model_stats.html">
      8 
      9 <script>
     10 'use strict';
     11 
     12 tr.b.unittest.testSuite(function() {
     13   var ModelStats = tr.model.ModelStats;
     14 
     15   test('getTraceEventStatsByCategory', function() {
     16     var modelStats = new ModelStats();
     17     modelStats.willProcessBasicTraceEvent('X', 'cat1', 'title1');
     18     modelStats.willProcessBasicTraceEvent('X', 'cat1', 'title1');
     19     modelStats.willProcessBasicTraceEvent('X', 'cat2', 'title3');
     20 
     21     assert.equal(modelStats.allTraceEventStats.length, 2);
     22     assert.equal(
     23         modelStats.traceEventCountsByKey_.get('X/cat1/title1').numEvents,
     24         2);
     25     assert.equal(
     26         modelStats.traceEventCountsByKey_.get('X/cat2/title3').numEvents,
     27         1);
     28   });
     29 
     30   test('getTraceEventStatsInTimeIntervals', function() {
     31     var modelStats = new ModelStats();
     32     var timeIntervalSizeInUs = modelStats.TIME_INTERVAL_SIZE_IN_MS * 1000;
     33     modelStats.willProcessBasicTraceEvent('X', 'cat1', 'title1', 1, 1);
     34     modelStats.willProcessBasicTraceEvent(
     35         'X', 'cat1', 'title1', timeIntervalSizeInUs + 1, 2);
     36     modelStats.willProcessBasicTraceEvent(
     37         'X', 'cat1', 'title1', 2 * timeIntervalSizeInUs + 1, 3);
     38     modelStats.willProcessBasicTraceEvent(
     39         'X', 'cat2', 'title3', 2 * timeIntervalSizeInUs + 2, 4);
     40 
     41     assert.strictEqual(modelStats.allTraceEventStatsInTimeIntervals.length, 3);
     42     assert.strictEqual(
     43         modelStats.traceEventStatsInTimeIntervals_.get(0).numEvents, 1);
     44     assert.strictEqual(
     45         modelStats.traceEventStatsInTimeIntervals_.get(1).numEvents, 1);
     46     assert.strictEqual(
     47         modelStats.traceEventStatsInTimeIntervals_.get(2).numEvents, 2);
     48 
     49     assert.isTrue(modelStats.hasEventSizesinBytes);
     50     assert.strictEqual(
     51         modelStats.traceEventStatsInTimeIntervals_.get(0).totalEventSizeinBytes,
     52         1);
     53     assert.strictEqual(
     54         modelStats.traceEventStatsInTimeIntervals_.get(1).totalEventSizeinBytes,
     55         2);
     56     assert.strictEqual(
     57         modelStats.traceEventStatsInTimeIntervals_.get(2).totalEventSizeinBytes,
     58         7);
     59   });
     60 
     61 });
     62 </script>
     63