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

Unified Diff: apps/benchmark/measurements.cc

Issue 1380023005: benchmark.mojo: add time_between measurement type. (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 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
index 59014b1313ac4571089b4c8e10be50a476851d70..96be8bfcb031f90cc8f618d315dfa9d7583bc282 100644
--- a/apps/benchmark/measurements.cc
+++ b/apps/benchmark/measurements.cc
@@ -22,10 +22,13 @@ EventSpec::~EventSpec() {}
Measurement::Measurement() {}
+Measurement::Measurement(MeasurementType type, EventSpec target_event)
+ : type(type), target_event(target_event) {}
+
Measurement::Measurement(MeasurementType type,
- std::string target_name,
- std::string target_categories)
- : type(type), target_event(target_name, target_categories) {}
+ EventSpec target_event,
+ EventSpec second_event)
+ : type(type), target_event(target_event), second_event(second_event) {}
Measurement::~Measurement() {}
@@ -39,6 +42,8 @@ double Measurements::Measure(const Measurement& measurement) {
switch (measurement.type) {
case MeasurementType::TIME_UNTIL:
return TimeUntil(measurement.target_event);
+ case MeasurementType::TIME_BETWEEN:
+ return TimeBetween(measurement.target_event, measurement.second_event);
case MeasurementType::AVG_DURATION:
return AvgDuration(measurement.target_event);
default:
@@ -47,25 +52,47 @@ double Measurements::Measure(const Measurement& measurement) {
}
}
-double Measurements::TimeUntil(const EventSpec& event_spec) {
- base::TimeTicks earliest;
+bool Measurements::EarliestOccurence(const EventSpec& event_spec,
+ base::TimeTicks* earliest) {
+ base::TimeTicks result;
bool found = false;
for (const Event& event : events_) {
if (!Match(event, event_spec))
continue;
if (found) {
- earliest = std::min(earliest, event.timestamp);
+ result = std::min(result, event.timestamp);
} else {
- earliest = event.timestamp;
+ result = event.timestamp;
found = true;
}
}
if (!found)
+ return false;
+ *earliest = result;
+ return true;
+}
+
+double Measurements::TimeUntil(const EventSpec& event_spec) {
+ base::TimeTicks earliest;
+ if (!EarliestOccurence(event_spec, &earliest))
return -1.0;
return (earliest - time_origin_).InMillisecondsF();
}
+double Measurements::TimeBetween(const EventSpec& first_event_spec,
+ const EventSpec& second_event_spec) {
+ base::TimeTicks earliest_first_event;
+ if (!EarliestOccurence(first_event_spec, &earliest_first_event))
+ return -1.0;
+ base::TimeTicks earliest_second_event;
+ if (!EarliestOccurence(second_event_spec, &earliest_second_event))
+ return -1.0;
+ if (earliest_second_event < earliest_first_event)
+ return -1.0;
+ return (earliest_second_event - earliest_first_event).InMillisecondsF();
+}
+
double Measurements::AvgDuration(const EventSpec& event_spec) {
double sum = 0.0;
int count = 0;
« 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