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

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: Further address Etienne's comments. 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
« no previous file with comments | « apps/benchmark/measurements.h ('k') | apps/benchmark/measurements_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: apps/benchmark/measurements.cc
diff --git a/apps/benchmark/measurements.cc b/apps/benchmark/measurements.cc
new file mode 100644
index 0000000000000000000000000000000000000000..187d8114275f2237a931c89fee792dd024a52986
--- /dev/null
+++ b/apps/benchmark/measurements.cc
@@ -0,0 +1,91 @@
+// 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 {
+namespace {
+
+bool Match(const Event& event, const EventSpec& spec) {
+ return event.name == spec.name && event.category == spec.category;
+}
+
+} // namespace
+
+EventSpec::EventSpec() {}
+
+EventSpec::EventSpec(std::string name, std::string category)
+ : name(name), category(category) {}
+
+EventSpec::~EventSpec() {}
+
+Measurement::Measurement() {}
+
+Measurement::Measurement(MeasurementType type,
+ std::string target_name,
+ std::string target_category)
+ : type(type), target_event(target_name, target_category) {}
+
+Measurement::~Measurement() {}
+
+Measurements::Measurements(std::vector<Event> events,
+ base::TimeTicks time_origin)
+ : events_(events), time_origin_(time_origin) {}
+
+Measurements::~Measurements() {}
+
+double Measurements::Measure(const Measurement& measurement) {
+ switch (measurement.type) {
+ case MeasurementType::TIME_UNTIL:
+ return TimeUntil(measurement.target_event);
+ case MeasurementType::AVG_DURATION:
+ return AvgDuration(measurement.target_event);
+ default:
+ NOTREACHED();
+ return double();
+ }
+}
+
+double Measurements::TimeUntil(const EventSpec& event_spec) {
+ base::TimeTicks earliest;
+ bool found = false;
+ for (const Event& event : events_) {
+ if (event.category == "__metadata")
+ continue;
+
+ if (!Match(event, event_spec))
+ continue;
+
+ if (found) {
+ earliest = std::min(earliest, event.timestamp);
+ } else {
+ earliest = event.timestamp;
+ found = true;
+ }
+ }
+ if (!found)
+ return -1.0;
+ return (earliest - time_origin_).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;
+}
+
+} // namespace benchmark
« 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