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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: apps/benchmark/measurements.cc
diff --git a/apps/benchmark/measurements.cc b/apps/benchmark/measurements.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c8d63ab51beb9582579f87f208449d4f3a7210b4
--- /dev/null
+++ b/apps/benchmark/measurements.cc
@@ -0,0 +1,74 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "apps/benchmark/measurements.h"
+
+namespace benchmark {
+
+bool Match(const Event& event, const EventSpec& spec) {
+ return event.name == spec.name && event.category == spec.category;
+}
+
+Measurements::Measurements(std::vector<Event> events, EventSpec reference_spec)
+ : events_(events), reference_spec_(reference_spec) {}
+
+Measurements::~Measurements() {}
+
+double Measurements::Measure(const Measurement& measurement) {
+ switch (measurement.type) {
+ case Measurement::TIME_UNTIL:
+ return TimeUntil(measurement.target_event);
+ case Measurement::AVG_DURATION:
+ return AvgDuration(measurement.target_event);
+ default:
+ return -1.0;
+ }
+}
+
+double Measurements::TimeUntil(const EventSpec& event_spec) {
+ base::TimeTicks target = FindEarliest(event_spec);
+ base::TimeTicks reference = FindEarliest(reference_spec_);
+ return (target - reference).InMillisecondsF();
+}
+
+double Measurements::AvgDuration(const EventSpec& event_spec) {
+ double sum = 0.0;
+ int count = 0;
+ for (const Event& event : events_) {
+ if (event.category == "__metadata")
+ continue;
+
+ if (!Match(event, event_spec))
+ continue;
+
+ sum += event.duration.InMillisecondsF();
+ count += 1;
+ }
+
+ if (!count)
+ return -1.0;
+ return sum / count;
+}
+
+base::TimeTicks Measurements::FindEarliest(const EventSpec& spec) {
+ base::TimeTicks earliest;
+ bool found = false;
+ for (const Event& event : events_) {
+ if (event.category == "__metadata")
+ continue;
+
+ if (!Match(event, spec))
+ continue;
+
+ if (found) {
+ earliest = std::min(earliest, event.timestamp);
+ } else {
+ earliest = event.timestamp;
+ found = true;
+ }
+ }
+ return earliest;
+}
+
+} // namespace benchmark

Powered by Google App Engine
This is Rietveld 408576698