Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 1 | /* |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2017-2020 ARM Limited. |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all |
| 14 | * copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | * SOFTWARE. |
| 23 | */ |
| 24 | #ifndef ARM_COMPUTE_TEST_INSTRUMENT |
| 25 | #define ARM_COMPUTE_TEST_INSTRUMENT |
| 26 | |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame^] | 27 | #include "support/MemorySupport.h" |
| 28 | |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 29 | #include "../Utils.h" |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 30 | #include "Measurement.h" |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 31 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 32 | #include <map> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 33 | #include <memory> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 34 | #include <string> |
| 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | namespace test |
| 39 | { |
| 40 | namespace framework |
| 41 | { |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 42 | enum class ScaleFactor : unsigned int |
| 43 | { |
| 44 | NONE, /* Default scale */ |
| 45 | SCALE_1K, /* 1000 */ |
| 46 | SCALE_1M, /* 1 000 000 */ |
| 47 | TIME_US, /* Microseconds */ |
| 48 | TIME_MS, /* Milliseconds */ |
| 49 | TIME_S, /* Seconds */ |
| 50 | }; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 51 | /** Interface for classes that can be used to measure performance. */ |
| 52 | class Instrument |
| 53 | { |
| 54 | public: |
| 55 | /** Helper function to create an instrument of the given type. |
| 56 | * |
| 57 | * @return Instance of an instrument of the given type. |
| 58 | */ |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 59 | template <typename T, ScaleFactor scale> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 60 | static std::unique_ptr<Instrument> make_instrument(); |
| 61 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 62 | /** Default constructor. */ |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 63 | Instrument() = default; |
| 64 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 65 | /** Allow instances of this class to be copy constructed */ |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 66 | Instrument(const Instrument &) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 67 | /** Allow instances of this class to be move constructed */ |
| 68 | Instrument(Instrument &&) = default; |
| 69 | /** Allow instances of this class to be copied */ |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 70 | Instrument &operator=(const Instrument &) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 71 | /** Allow instances of this class to be moved */ |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 72 | Instrument &operator=(Instrument &&) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 73 | /** Default destructor. */ |
| 74 | virtual ~Instrument() = default; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 75 | |
| 76 | /** Identifier for the instrument */ |
| 77 | virtual std::string id() const = 0; |
| 78 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 79 | /** Start of the test |
| 80 | * |
| 81 | * Called before the test set up starts |
| 82 | */ |
| 83 | virtual void test_start() |
| 84 | { |
| 85 | } |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 86 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 87 | /** Start measuring. |
| 88 | * |
| 89 | * Called just before the run of the test starts |
| 90 | */ |
| 91 | virtual void start() |
| 92 | { |
| 93 | } |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 94 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 95 | /** Stop measuring. |
| 96 | * |
| 97 | * Called just after the run of the test ends |
| 98 | */ |
| 99 | virtual void stop() |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | /** End of the test |
| 104 | * |
| 105 | * Called after the test teardown ended |
| 106 | */ |
| 107 | virtual void test_stop() |
| 108 | { |
| 109 | } |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 110 | /** Map of measurements */ |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 111 | using MeasurementsMap = std::map<std::string, Measurement>; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 112 | |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 113 | /** Return the latest measurements. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 114 | * |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 115 | * @return the latest measurements. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 116 | */ |
Anthony Barbier | 9fb0cac | 2018-04-20 15:46:21 +0100 | [diff] [blame] | 117 | virtual MeasurementsMap measurements() const |
| 118 | { |
| 119 | return MeasurementsMap(); |
| 120 | } |
| 121 | |
| 122 | /** Return the latest test measurements. |
| 123 | * |
| 124 | * @return the latest test measurements. |
| 125 | */ |
| 126 | virtual MeasurementsMap test_measurements() const |
| 127 | { |
| 128 | return MeasurementsMap(); |
| 129 | } |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 130 | |
| 131 | protected: |
| 132 | std::string _unit{}; |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 133 | }; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 134 | |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 135 | template <typename T, ScaleFactor scale> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 136 | inline std::unique_ptr<Instrument> Instrument::make_instrument() |
| 137 | { |
Giorgio Arena | ce58a9f | 2017-10-31 17:59:17 +0000 | [diff] [blame] | 138 | return support::cpp14::make_unique<T>(scale); |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 139 | } |
Anthony Barbier | c9afce5 | 2018-01-26 16:07:50 +0000 | [diff] [blame] | 140 | |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 141 | } // namespace framework |
| 142 | } // namespace test |
| 143 | } // namespace arm_compute |
| 144 | #endif /* ARM_COMPUTE_TEST_INSTRUMENT */ |