OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef APPS_BENCHMARK_MEASUREMENTS_HH_ |
| 6 #define APPS_BENCHMARK_MEASUREMENTS_HH_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "apps/benchmark/event.h" |
| 11 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time/time.h" |
| 14 #include "base/values.h" |
| 15 |
| 16 namespace benchmark { |
| 17 |
| 18 // Describes a trace event to match. |
| 19 struct EventSpec { |
| 20 std::string name; |
| 21 std::string category; |
| 22 |
| 23 EventSpec(); |
| 24 EventSpec(std::string name, std::string category); |
| 25 ~EventSpec(); |
| 26 }; |
| 27 |
| 28 enum class MeasurementType { TIME_UNTIL, AVG_DURATION }; |
| 29 |
| 30 // Represents a single measurement to be performed on the collected trace. |
| 31 struct Measurement { |
| 32 MeasurementType type; |
| 33 EventSpec target_event; |
| 34 // Optional string from which this measurement was parsed. Can be used for |
| 35 // presentation purposes. |
| 36 std::string spec; |
| 37 |
| 38 Measurement(); |
| 39 Measurement(MeasurementType type, |
| 40 std::string target_name, |
| 41 std::string target_category); |
| 42 ~Measurement(); |
| 43 }; |
| 44 |
| 45 class Measurements { |
| 46 public: |
| 47 Measurements(std::vector<Event> events, base::TimeTicks time_origin); |
| 48 ~Measurements(); |
| 49 |
| 50 // Performs the given measurement. Returns the result in milliseconds or -1.0 |
| 51 // if the measurement failed, e.g. because no events were matched. |
| 52 double Measure(const Measurement& measurement); |
| 53 |
| 54 private: |
| 55 double TimeUntil(const EventSpec& event_spec); |
| 56 double AvgDuration(const EventSpec& event_spec); |
| 57 |
| 58 std::vector<Event> events_; |
| 59 base::TimeTicks time_origin_; |
| 60 DISALLOW_COPY_AND_ASSIGN(Measurements); |
| 61 }; |
| 62 |
| 63 } // namespace benchmark |
| 64 |
| 65 #endif // APPS_BENCHMARK_MEASUREMENTS_HH_ |
OLD | NEW |