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

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

Issue 1305193002: Trace-based benchmarking via a mojo app. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "apps/benchmark/measurements.h"
6
7 namespace benchmark {
8
9 bool Match(const Event& event, const EventSpec& spec) {
10 return event.name == spec.name && event.category == spec.category;
11 }
12
13 Measurements::Measurements(std::vector<Event> events, EventSpec reference_spec)
14 : events_(events), reference_spec_(reference_spec) {}
15
16 Measurements::~Measurements() {}
17
18 double Measurements::Measure(const Measurement& measurement) {
19 switch (measurement.type) {
20 case Measurement::TIME_UNTIL:
21 return TimeUntil(measurement.target_event);
22 case Measurement::AVG_DURATION:
23 return AvgDuration(measurement.target_event);
24 default:
25 return -1.0;
26 }
27 }
28
29 double Measurements::TimeUntil(const EventSpec& event_spec) {
30 base::TimeTicks target = FindEarliest(event_spec);
31 base::TimeTicks reference = FindEarliest(reference_spec_);
32 return (target - reference).InMillisecondsF();
33 }
34
35 double Measurements::AvgDuration(const EventSpec& event_spec) {
36 double sum = 0.0;
37 int count = 0;
38 for (const Event& event : events_) {
39 if (event.category == "__metadata")
40 continue;
41
42 if (!Match(event, event_spec))
43 continue;
44
45 sum += event.duration.InMillisecondsF();
46 count += 1;
47 }
48
49 if (!count)
50 return -1.0;
51 return sum / count;
52 }
53
54 base::TimeTicks Measurements::FindEarliest(const EventSpec& spec) {
55 base::TimeTicks earliest;
56 bool found = false;
57 for (const Event& event : events_) {
58 if (event.category == "__metadata")
59 continue;
60
61 if (!Match(event, spec))
62 continue;
63
64 if (found) {
65 earliest = std::min(earliest, event.timestamp);
66 } else {
67 earliest = event.timestamp;
68 found = true;
69 }
70 }
71 return earliest;
72 }
73
74 } // namespace benchmark
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698