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 PERCENTILE_DURATION, | |
33 }; | |
29 | 34 |
30 // Represents a single measurement to be performed on the collected trace. | 35 // Represents a single measurement to be performed on the collected trace. |
31 struct Measurement { | 36 struct Measurement { |
32 MeasurementType type; | 37 MeasurementType type; |
33 EventSpec target_event; | 38 EventSpec target_event; |
34 // Second event targeted by the measurement, meaningful only for binary | 39 // Second event targeted by the measurement, meaningful only for binary |
35 // measurement types (TIME_BETWEEN). | 40 // measurement types (TIME_BETWEEN). |
36 EventSpec second_event; | 41 EventSpec second_event; |
37 // Optional string from which this measurement was parsed. Can be used for | 42 // Optional string from which this measurement was parsed. Can be used for |
38 // presentation purposes. | 43 // presentation purposes. |
39 std::string spec; | 44 std::string spec; |
45 // Optional parameter to the measurement. | |
46 double param; | |
ppi
2015/10/12 19:19:19
nit: move this before std::string spec; , as it lo
zra
2015/10/12 20:38:19
Done.
| |
40 | 47 |
41 Measurement(); | 48 Measurement(); |
42 Measurement(MeasurementType type, EventSpec target_event); | 49 Measurement(MeasurementType type, EventSpec target_event); |
43 Measurement(MeasurementType type, | 50 Measurement(MeasurementType type, |
44 EventSpec target_event, | 51 EventSpec target_event, |
45 EventSpec second_event); | 52 EventSpec second_event); |
46 ~Measurement(); | 53 ~Measurement(); |
47 }; | 54 }; |
48 | 55 |
49 class Measurements { | 56 class Measurements { |
50 public: | 57 public: |
51 Measurements(std::vector<Event> events, base::TimeTicks time_origin); | 58 Measurements(std::vector<Event> events, base::TimeTicks time_origin); |
52 ~Measurements(); | 59 ~Measurements(); |
53 | 60 |
54 // Performs the given measurement. Returns the result in milliseconds or -1.0 | 61 // Performs the given measurement. Returns the result in milliseconds or -1.0 |
55 // if the measurement failed, e.g. because no events were matched. | 62 // if the measurement failed, e.g. because no events were matched. |
56 double Measure(const Measurement& measurement); | 63 double Measure(const Measurement& measurement) 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 double Percentile(const EventSpec& event_spec, double percentile) const; | |
65 | 73 |
66 std::vector<Event> events_; | 74 std::vector<Event> events_; |
67 base::TimeTicks time_origin_; | 75 base::TimeTicks time_origin_; |
68 DISALLOW_COPY_AND_ASSIGN(Measurements); | 76 DISALLOW_COPY_AND_ASSIGN(Measurements); |
69 }; | 77 }; |
70 | 78 |
71 } // namespace benchmark | 79 } // namespace benchmark |
72 | 80 |
73 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ | 81 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ |
OLD | NEW |