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

Unified Diff: apps/benchmark/measurements.cc

Issue 1394963002: Adds a couple more measures to the benchmarking app (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 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
index 96be8bfcb031f90cc8f618d315dfa9d7583bc282..2c5153e5527331ea4d3003c6a1ba87e623834f26 100644
--- a/apps/benchmark/measurements.cc
+++ b/apps/benchmark/measurements.cc
@@ -4,10 +4,12 @@
#include "apps/benchmark/measurements.h"
+#include <algorithm>
+
namespace benchmark {
namespace {
-bool Match(const Event& event, const EventSpec& spec) {
+static bool Match(const Event& event, const EventSpec& spec) {
return event.name == spec.name && event.categories == spec.categories;
}
@@ -38,7 +40,7 @@ Measurements::Measurements(std::vector<Event> events,
Measurements::~Measurements() {}
-double Measurements::Measure(const Measurement& measurement) {
+double Measurements::Measure(const Measurement& measurement) const {
switch (measurement.type) {
case MeasurementType::TIME_UNTIL:
return TimeUntil(measurement.target_event);
@@ -46,6 +48,8 @@ double Measurements::Measure(const Measurement& measurement) {
return TimeBetween(measurement.target_event, measurement.second_event);
case MeasurementType::AVG_DURATION:
return AvgDuration(measurement.target_event);
+ case MeasurementType::PERCENTILE_DURATION:
+ return Percentile(measurement.target_event, measurement.param);
default:
NOTREACHED();
return double();
@@ -53,7 +57,7 @@ double Measurements::Measure(const Measurement& measurement) {
}
bool Measurements::EarliestOccurence(const EventSpec& event_spec,
- base::TimeTicks* earliest) {
+ base::TimeTicks* earliest) const {
base::TimeTicks result;
bool found = false;
for (const Event& event : events_) {
@@ -73,7 +77,7 @@ bool Measurements::EarliestOccurence(const EventSpec& event_spec,
return true;
}
-double Measurements::TimeUntil(const EventSpec& event_spec) {
+double Measurements::TimeUntil(const EventSpec& event_spec) const {
base::TimeTicks earliest;
if (!EarliestOccurence(event_spec, &earliest))
return -1.0;
@@ -81,7 +85,7 @@ double Measurements::TimeUntil(const EventSpec& event_spec) {
}
double Measurements::TimeBetween(const EventSpec& first_event_spec,
- const EventSpec& second_event_spec) {
+ const EventSpec& second_event_spec) const {
base::TimeTicks earliest_first_event;
if (!EarliestOccurence(first_event_spec, &earliest_first_event))
return -1.0;
@@ -93,7 +97,7 @@ double Measurements::TimeBetween(const EventSpec& first_event_spec,
return (earliest_second_event - earliest_first_event).InMillisecondsF();
}
-double Measurements::AvgDuration(const EventSpec& event_spec) {
+double Measurements::AvgDuration(const EventSpec& event_spec) const {
double sum = 0.0;
int count = 0;
for (const Event& event : events_) {
@@ -112,4 +116,35 @@ double Measurements::AvgDuration(const EventSpec& event_spec) {
return sum / count;
}
+double Measurements::Percentile(const EventSpec& event_spec,
+ double percentile) const {
+ DCHECK_GE(percentile, 0.0);
+ DCHECK_LE(percentile, 1.0);
+ std::vector<double> durations;
+
+ for (const Event& event : events_) {
+ if (event.type != EventType::COMPLETE)
+ continue;
+
+ if (!Match(event, event_spec))
+ continue;
+
+ durations.push_back(event.duration.InMillisecondsF());
+ }
+ if (durations.size() == 0) {
+ return -1.0;
+ }
+
+ size_t index;
+ if (percentile == 0.0) {
ppi 2015/10/12 23:15:20 This probably does what we want, but I'd suggest t
zra 2015/10/13 03:35:39 Good idea. Reorganized instead to use max(1, rank)
+ index = 0;
+ } else {
+ double ordinal = ceil(static_cast<double>(durations.size()) * percentile);
+ index = static_cast<size_t>(ordinal) - 1;
+ }
+ std::nth_element(durations.begin(), durations.begin() + index,
+ durations.end());
+ return durations[index];
+}
+
} // namespace benchmark

Powered by Google App Engine
This is Rietveld 408576698