Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: trace_processor/experimental/mappers/trace_stats.html

Issue 2162963002: [polymer] Merge of master into polymer10-migration (Closed) Base URL: git@github.com:catapult-project/catapult.git@polymer10-migration
Patch Set: Merge polymer10-migration int polymer10-merge Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright 2015 The Chromium Authors. All rights reserved. 3 Copyright 2015 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="import" href="/perf_insights/mre/function_handle.html"> 8 <link rel="import" href="/perf_insights/mre/function_handle.html">
9 <link rel="import" href="/tracing/base/range.html"> 9 <link rel="import" href="/tracing/base/range.html">
10 <link rel="import" href="/tracing/value/numeric.html"> 10 <link rel="import" href="/tracing/value/numeric.html">
11 <link rel="import" href="/tracing/value/unit.html"> 11 <link rel="import" href="/tracing/value/unit.html">
12 12
13 <script> 13 <script>
14 'use strict'; 14 'use strict';
15 15
16 tr.exportTo('pi.m', function() { 16 tr.exportTo('pi.m', function() {
17 var COUNT_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear( 17 var COUNT_NUMERIC_BUILDER = tr.v.NumericBuilder.createLinear(
18 tr.v.Unit.byName.unitlessNumber, tr.b.Range.fromExplicitRange(0, 50000), 18 tr.v.Unit.byName.unitlessNumber, tr.b.Range.fromExplicitRange(0, 50000),
19 20); 19 20);
20 20
21 function traceStatsFunction(result, model) { 21 function traceStatsFunction(result, model) {
22 var canonicalUrl = model.canonicalUrl; 22 var canonicalUrl = model.canonicalUrl;
23 var eventCount = 0; 23 var eventCount = 0;
24 var firstTime = Number.MAX_VALUE; 24 var firstTime = Number.MAX_VALUE;
25 var lastTime = 0; 25 var lastTime = 0;
26 var categories = {}; 26 var categories = {};
27 27
28 var seconds_counts = {}; 28 var seconds_counts = {};
29 model.iterateAllEvents(function(event) { 29 for (var event of model.getDescendantEvents()) {
30 eventCount += 1; 30 eventCount += 1;
31 if (event.start < firstTime) 31 if (event.start < firstTime)
32 firstTime = event.start; 32 firstTime = event.start;
33 33
34 var eventEnd = event.start + event.duration; 34 var eventEnd = event.start + event.duration;
35 if (eventEnd > lastTime) 35 if (eventEnd > lastTime)
36 lastTime = eventEnd; 36 lastTime = eventEnd;
37 37
38 if (categories[event.category] === undefined) 38 if (categories[event.category] === undefined)
39 categories[event.category] = 0; 39 categories[event.category] = 0;
40 40
41 categories[event.category]++; 41 categories[event.category]++;
42 42
43 var second = Math.round(event.start / 1000); 43 var second = Math.round(event.start / 1000);
44 if (seconds_counts[second] === undefined) 44 if (seconds_counts[second] === undefined)
45 seconds_counts[second] = 0; 45 seconds_counts[second] = 0;
46 46
47 seconds_counts[second]++; 47 seconds_counts[second]++;
48 }); 48 }
49 49
50 var histogram = COUNT_NUMERIC_BUILDER.build(); 50 var histogram = COUNT_NUMERIC_BUILDER.build();
51 51
52 for (var second in seconds_counts) 52 for (var second in seconds_counts)
53 histogram.add(seconds_counts[second]); 53 histogram.add(seconds_counts[second]);
54 54
55 var stats = { 55 var stats = {
56 totalEvents: eventCount, 56 totalEvents: eventCount,
57 firstTimeInMS: firstTime, 57 firstTimeInMS: firstTime,
58 lastTimeInMS: lastTime, 58 lastTimeInMS: lastTime,
59 durationInMS: lastTime - firstTime, 59 durationInMS: lastTime - firstTime,
60 eventsPerSecond: eventCount / (lastTime - firstTime) * 1000, 60 eventsPerSecond: eventCount / (lastTime - firstTime) * 1000,
61 categories: categories, 61 categories: categories,
62 events_seconds: histogram.asDict() 62 events_seconds: histogram.asDict()
63 }; 63 };
64 64
65 result.addPair('stats', stats); 65 result.addPair('stats', stats);
66 } 66 }
67 67
68 pi.FunctionRegistry.register(traceStatsFunction); 68 pi.FunctionRegistry.register(traceStatsFunction);
69 69
70 //Exporting for tests. 70 //Exporting for tests.
71 return { 71 return {
72 traceStatsFunctionForTest: traceStatsFunction 72 traceStatsFunctionForTest: traceStatsFunction
73 }; 73 };
74 }); 74 });
75 </script> 75 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698