Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef APPS_BENCHMARK_MEASUREMENTS_HH_ | 5 #ifndef APPS_BENCHMARK_MEASUREMENTS_HH_ |
| 6 #define APPS_BENCHMARK_MEASUREMENTS_HH_ | 6 #define APPS_BENCHMARK_MEASUREMENTS_HH_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "apps/benchmark/event.h" | 10 #include "apps/benchmark/event.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 | 15 |
| 16 namespace benchmark { | 16 namespace benchmark { |
| 17 | 17 |
| 18 // Describes a trace event to match. | 18 // Describes a trace event to match. |
| 19 struct EventSpec { | 19 struct EventSpec { |
| 20 std::string name; | 20 std::string name; |
| 21 std::string categories; | 21 std::string categories; |
| 22 | 22 |
| 23 EventSpec(); | 23 EventSpec(); |
| 24 EventSpec(std::string name, std::string categories); | 24 EventSpec(std::string name, std::string categories); |
| 25 ~EventSpec(); | 25 ~EventSpec(); |
| 26 }; | 26 }; |
| 27 | 27 |
| 28 enum class MeasurementType { TIME_UNTIL, TIME_BETWEEN, AVG_DURATION }; | 28 enum class MeasurementType { |
| 29 TIME_UNTIL, | |
| 30 TIME_BETWEEN, | |
| 31 AVG_DURATION, | |
| 32 MEDIAN_DURATION, | |
| 33 DIST_DURATION, | |
|
ppi
2015/10/08 22:29:47
I'd call this PERCENTILE_DURATION.
zra
2015/10/09 14:51:15
Done.
| |
| 34 }; | |
| 29 | 35 |
|
ppi
2015/10/08 22:29:47
Please also update the documentation in https://gi
zra
2015/10/09 14:51:15
Done.
| |
| 30 // Represents a single measurement to be performed on the collected trace. | 36 // Represents a single measurement to be performed on the collected trace. |
| 31 struct Measurement { | 37 struct Measurement { |
| 32 MeasurementType type; | 38 MeasurementType type; |
| 33 EventSpec target_event; | 39 EventSpec target_event; |
| 34 // Second event targeted by the measurement, meaningful only for binary | 40 // Second event targeted by the measurement, meaningful only for binary |
| 35 // measurement types (TIME_BETWEEN). | 41 // measurement types (TIME_BETWEEN). |
| 36 EventSpec second_event; | 42 EventSpec second_event; |
| 37 // Optional string from which this measurement was parsed. Can be used for | 43 // Optional string from which this measurement was parsed. Can be used for |
| 38 // presentation purposes. | 44 // presentation purposes. |
| 39 std::string spec; | 45 std::string spec; |
| 40 | 46 |
| 41 Measurement(); | 47 Measurement(); |
| 42 Measurement(MeasurementType type, EventSpec target_event); | 48 Measurement(MeasurementType type, EventSpec target_event); |
| 43 Measurement(MeasurementType type, | 49 Measurement(MeasurementType type, |
| 44 EventSpec target_event, | 50 EventSpec target_event, |
| 45 EventSpec second_event); | 51 EventSpec second_event); |
| 46 ~Measurement(); | 52 ~Measurement(); |
| 47 }; | 53 }; |
| 48 | 54 |
| 49 class Measurements { | 55 class Measurements { |
| 50 public: | 56 public: |
| 51 Measurements(std::vector<Event> events, base::TimeTicks time_origin); | 57 Measurements(std::vector<Event> events, base::TimeTicks time_origin); |
| 52 ~Measurements(); | 58 ~Measurements(); |
| 53 | 59 |
| 54 // Performs the given measurement. Returns the result in milliseconds or -1.0 | 60 // Performs the given measurement. Returns the result in milliseconds or -1.0 |
| 55 // if the measurement failed, e.g. because no events were matched. | 61 // if the measurement failed, e.g. because no events were matched. |
| 56 double Measure(const Measurement& measurement); | 62 void Measure(const Measurement& measurement, |
| 63 std::vector<double>* results) const; | |
| 57 | 64 |
| 58 private: | 65 private: |
| 59 bool EarliestOccurence(const EventSpec& event_spec, | 66 bool EarliestOccurence(const EventSpec& event_spec, |
| 60 base::TimeTicks* earliest); | 67 base::TimeTicks* earliest) const; |
| 61 double TimeUntil(const EventSpec& event_spec); | 68 double TimeUntil(const EventSpec& event_spec) const; |
| 62 double TimeBetween(const EventSpec& first_event_spec, | 69 double TimeBetween(const EventSpec& first_event_spec, |
| 63 const EventSpec& second_event_spec); | 70 const EventSpec& second_event_spec) const; |
| 64 double AvgDuration(const EventSpec& event_spec); | 71 double AvgDuration(const EventSpec& event_spec) const; |
| 72 bool Percentiles(const EventSpec& event_spec, | |
| 73 const std::vector<double>& percentiles, | |
| 74 std::vector<double>* result) const; | |
| 65 | 75 |
| 66 std::vector<Event> events_; | 76 std::vector<Event> events_; |
| 67 base::TimeTicks time_origin_; | 77 base::TimeTicks time_origin_; |
| 68 DISALLOW_COPY_AND_ASSIGN(Measurements); | 78 DISALLOW_COPY_AND_ASSIGN(Measurements); |
| 69 }; | 79 }; |
| 70 | 80 |
| 71 } // namespace benchmark | 81 } // namespace benchmark |
| 72 | 82 |
| 73 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ | 83 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ |
| OLD | NEW |