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, AVG_DURATION }; | 28 enum class MeasurementType { TIME_UNTIL, TIME_BETWEEN, AVG_DURATION }; |
29 | 29 |
30 // Represents a single measurement to be performed on the collected trace. | 30 // Represents a single measurement to be performed on the collected trace. |
31 struct Measurement { | 31 struct Measurement { |
32 MeasurementType type; | 32 MeasurementType type; |
33 EventSpec target_event; | 33 EventSpec target_event; |
| 34 // Second event targeted by the measurement, meaningful only for binary |
| 35 // measurement types (TIME_BETWEEN). |
| 36 EventSpec second_event; |
34 // Optional string from which this measurement was parsed. Can be used for | 37 // Optional string from which this measurement was parsed. Can be used for |
35 // presentation purposes. | 38 // presentation purposes. |
36 std::string spec; | 39 std::string spec; |
37 | 40 |
38 Measurement(); | 41 Measurement(); |
| 42 Measurement(MeasurementType type, EventSpec target_event); |
39 Measurement(MeasurementType type, | 43 Measurement(MeasurementType type, |
40 std::string target_name, | 44 EventSpec target_event, |
41 std::string target_categories); | 45 EventSpec second_event); |
42 ~Measurement(); | 46 ~Measurement(); |
43 }; | 47 }; |
44 | 48 |
45 class Measurements { | 49 class Measurements { |
46 public: | 50 public: |
47 Measurements(std::vector<Event> events, base::TimeTicks time_origin); | 51 Measurements(std::vector<Event> events, base::TimeTicks time_origin); |
48 ~Measurements(); | 52 ~Measurements(); |
49 | 53 |
50 // Performs the given measurement. Returns the result in milliseconds or -1.0 | 54 // Performs the given measurement. Returns the result in milliseconds or -1.0 |
51 // if the measurement failed, e.g. because no events were matched. | 55 // if the measurement failed, e.g. because no events were matched. |
52 double Measure(const Measurement& measurement); | 56 double Measure(const Measurement& measurement); |
53 | 57 |
54 private: | 58 private: |
| 59 bool EarliestOccurence(const EventSpec& event_spec, |
| 60 base::TimeTicks* earliest); |
55 double TimeUntil(const EventSpec& event_spec); | 61 double TimeUntil(const EventSpec& event_spec); |
| 62 double TimeBetween(const EventSpec& first_event_spec, |
| 63 const EventSpec& second_event_spec); |
56 double AvgDuration(const EventSpec& event_spec); | 64 double AvgDuration(const EventSpec& event_spec); |
57 | 65 |
58 std::vector<Event> events_; | 66 std::vector<Event> events_; |
59 base::TimeTicks time_origin_; | 67 base::TimeTicks time_origin_; |
60 DISALLOW_COPY_AND_ASSIGN(Measurements); | 68 DISALLOW_COPY_AND_ASSIGN(Measurements); |
61 }; | 69 }; |
62 | 70 |
63 } // namespace benchmark | 71 } // namespace benchmark |
64 | 72 |
65 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ | 73 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ |
OLD | NEW |