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

Side by Side Diff: apps/benchmark/measurements.cc

Issue 1316163003: Support duration events in `benchmark.mojo`. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 3 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
« no previous file with comments | « apps/benchmark/measurements.h ('k') | apps/benchmark/measurements_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/benchmark/measurements.h" 5 #include "apps/benchmark/measurements.h"
6 6
7 namespace benchmark { 7 namespace benchmark {
8 namespace { 8 namespace {
9 9
10 bool Match(const Event& event, const EventSpec& spec) { 10 bool Match(const Event& event, const EventSpec& spec) {
11 return event.name == spec.name && event.category == spec.category; 11 return event.name == spec.name && event.categories == spec.categories;
12 } 12 }
13 13
14 } // namespace 14 } // namespace
15 15
16 EventSpec::EventSpec() {} 16 EventSpec::EventSpec() {}
17 17
18 EventSpec::EventSpec(std::string name, std::string category) 18 EventSpec::EventSpec(std::string name, std::string categories)
19 : name(name), category(category) {} 19 : name(name), categories(categories) {}
20 20
21 EventSpec::~EventSpec() {} 21 EventSpec::~EventSpec() {}
22 22
23 Measurement::Measurement() {} 23 Measurement::Measurement() {}
24 24
25 Measurement::Measurement(MeasurementType type, 25 Measurement::Measurement(MeasurementType type,
26 std::string target_name, 26 std::string target_name,
27 std::string target_category) 27 std::string target_categories)
28 : type(type), target_event(target_name, target_category) {} 28 : type(type), target_event(target_name, target_categories) {}
29 29
30 Measurement::~Measurement() {} 30 Measurement::~Measurement() {}
31 31
32 Measurements::Measurements(std::vector<Event> events, 32 Measurements::Measurements(std::vector<Event> events,
33 base::TimeTicks time_origin) 33 base::TimeTicks time_origin)
34 : events_(events), time_origin_(time_origin) {} 34 : events_(events), time_origin_(time_origin) {}
35 35
36 Measurements::~Measurements() {} 36 Measurements::~Measurements() {}
37 37
38 double Measurements::Measure(const Measurement& measurement) { 38 double Measurements::Measure(const Measurement& measurement) {
39 switch (measurement.type) { 39 switch (measurement.type) {
40 case MeasurementType::TIME_UNTIL: 40 case MeasurementType::TIME_UNTIL:
41 return TimeUntil(measurement.target_event); 41 return TimeUntil(measurement.target_event);
42 case MeasurementType::AVG_DURATION: 42 case MeasurementType::AVG_DURATION:
43 return AvgDuration(measurement.target_event); 43 return AvgDuration(measurement.target_event);
44 default: 44 default:
45 NOTREACHED(); 45 NOTREACHED();
46 return double(); 46 return double();
47 } 47 }
48 } 48 }
49 49
50 double Measurements::TimeUntil(const EventSpec& event_spec) { 50 double Measurements::TimeUntil(const EventSpec& event_spec) {
51 base::TimeTicks earliest; 51 base::TimeTicks earliest;
52 bool found = false; 52 bool found = false;
53 for (const Event& event : events_) { 53 for (const Event& event : events_) {
54 if (event.category == "__metadata")
55 continue;
56
57 if (!Match(event, event_spec)) 54 if (!Match(event, event_spec))
58 continue; 55 continue;
59 56
60 if (found) { 57 if (found) {
61 earliest = std::min(earliest, event.timestamp); 58 earliest = std::min(earliest, event.timestamp);
62 } else { 59 } else {
63 earliest = event.timestamp; 60 earliest = event.timestamp;
64 found = true; 61 found = true;
65 } 62 }
66 } 63 }
67 if (!found) 64 if (!found)
68 return -1.0; 65 return -1.0;
69 return (earliest - time_origin_).InMillisecondsF(); 66 return (earliest - time_origin_).InMillisecondsF();
70 } 67 }
71 68
72 double Measurements::AvgDuration(const EventSpec& event_spec) { 69 double Measurements::AvgDuration(const EventSpec& event_spec) {
73 double sum = 0.0; 70 double sum = 0.0;
74 int count = 0; 71 int count = 0;
75 for (const Event& event : events_) { 72 for (const Event& event : events_) {
76 if (event.category == "__metadata") 73 if (event.type != EventType::COMPLETE)
77 continue; 74 continue;
78 75
79 if (!Match(event, event_spec)) 76 if (!Match(event, event_spec))
80 continue; 77 continue;
81 78
82 sum += event.duration.InMillisecondsF(); 79 sum += event.duration.InMillisecondsF();
83 count += 1; 80 count += 1;
84 } 81 }
85 82
86 if (!count) 83 if (!count)
87 return -1.0; 84 return -1.0;
88 return sum / count; 85 return sum / count;
89 } 86 }
90 87
91 } // namespace benchmark 88 } // namespace benchmark
OLDNEW
« no previous file with comments | « apps/benchmark/measurements.h ('k') | apps/benchmark/measurements_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698