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

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

Issue 2771723003: [tracing] Move math utilities from base into their own subdirectory (attempt 2) (Closed)
Patch Set: rebase Created 3 years, 9 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="/tracing/base/range.html"> 8 <link rel="import" href="/tracing/base/math/range.html">
9 <link rel="import" href="/tracing/base/unit.html"> 9 <link rel="import" href="/tracing/base/unit.html">
10 <link rel="import" href="/tracing/mre/function_handle.html"> 10 <link rel="import" href="/tracing/mre/function_handle.html">
11 <link rel="import" href="/tracing/value/histogram.html"> 11 <link rel="import" href="/tracing/value/histogram.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_BOUNDARIES = tr.v.HistogramBinBoundaries.createLinear(0, 5e4, 20); 17 var COUNT_BOUNDARIES = tr.v.HistogramBinBoundaries.createLinear(0, 5e4, 20);
18 18
19 function traceStatsFunction(result, model) { 19 function traceStatsFunction(result, model) {
20 var canonicalUrl = model.canonicalUrl; 20 var canonicalUrl = model.canonicalUrl;
21 var eventCount = 0; 21 var eventCount = 0;
22 var firstTime = Number.MAX_VALUE; 22 var firstTime = Number.MAX_VALUE;
23 var lastTime = 0; 23 var lastTime = 0;
24 var categories = {}; 24 var categories = {};
25 25
26 var seconds_counts = {}; 26 var secondsCounts = {};
27 for (var event of model.getDescendantEvents()) { 27 for (var event of model.getDescendantEvents()) {
28 eventCount += 1; 28 eventCount += 1;
29 if (event.start < firstTime) 29 if (event.start < firstTime)
30 firstTime = event.start; 30 firstTime = event.start;
31 31
32 var eventEnd = event.start + event.duration; 32 var eventEnd = event.start + event.duration;
33 if (eventEnd > lastTime) 33 if (eventEnd > lastTime)
34 lastTime = eventEnd; 34 lastTime = eventEnd;
35 35
36 if (categories[event.category] === undefined) 36 if (categories[event.category] === undefined)
37 categories[event.category] = 0; 37 categories[event.category] = 0;
38 38
39 categories[event.category]++; 39 categories[event.category]++;
40 40
41 var second = Math.round(event.start / 1000); 41 var second = Math.round(event.start / 1000);
42 if (seconds_counts[second] === undefined) 42 if (secondsCounts[second] === undefined)
43 seconds_counts[second] = 0; 43 secondsCounts[second] = 0;
44 44
45 seconds_counts[second]++; 45 secondsCounts[second]++;
46 } 46 }
47 47
48 var histogram = new tr.v.Histogram( 48 var histogram = new tr.v.Histogram(
49 tr.b.Unit.byName.count, COUNT_BOUNDARIES); 49 tr.b.Unit.byName.count, COUNT_BOUNDARIES);
50 50
51 for (var second in seconds_counts) 51 for (var second in secondsCounts)
52 histogram.add(seconds_counts[second]); 52 histogram.add(secondsCounts[second]);
53 53
54 var stats = { 54 var stats = {
55 totalEvents: eventCount, 55 totalEvents: eventCount,
56 firstTimeInMS: firstTime, 56 firstTimeInMS: firstTime,
57 lastTimeInMS: lastTime, 57 lastTimeInMS: lastTime,
58 durationInMS: lastTime - firstTime, 58 durationInMS: lastTime - firstTime,
59 eventsPerSecond: eventCount / (lastTime - firstTime) * 1000, 59 eventsPerSecond: eventCount / (lastTime - firstTime) * 1000,
60 categories: categories, 60 categories: categories,
61 events_seconds: histogram.asDict() 61 events_seconds: histogram.asDict()
62 }; 62 };
63 63
64 result.addPair('stats', stats); 64 result.addPair('stats', stats);
65 } 65 }
66 66
67 tr.mre.FunctionRegistry.register(traceStatsFunction); 67 tr.mre.FunctionRegistry.register(traceStatsFunction);
68 68
69 //Exporting for tests. 69 // Exporting for tests.
70 return { 70 return {
71 traceStatsFunctionForTest: traceStatsFunction 71 traceStatsFunctionForTest: traceStatsFunction
72 }; 72 };
73 }); 73 });
74 </script> 74 </script>
OLDNEW
« no previous file with comments | « trace_processor/experimental/mappers/slice_cost.html ('k') | trace_processor/experimental/mappers/v8_map_function.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698