Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 ARM Limited. |
| 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 | |
| 27 | #include "../Utils.h" |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 28 | #include "Measurement.h" |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 29 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 30 | #include <map> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 31 | #include <memory> |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 32 | #include <string> |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | namespace test |
| 37 | { |
| 38 | namespace framework |
| 39 | { |
| 40 | /** Interface for classes that can be used to measure performance. */ |
| 41 | class Instrument |
| 42 | { |
| 43 | public: |
| 44 | /** Helper function to create an instrument of the given type. |
| 45 | * |
| 46 | * @return Instance of an instrument of the given type. |
| 47 | */ |
| 48 | template <typename T> |
| 49 | static std::unique_ptr<Instrument> make_instrument(); |
| 50 | |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 51 | Instrument() = default; |
| 52 | Instrument(const Instrument &) = default; |
| 53 | Instrument(Instrument &&) = default; |
| 54 | Instrument &operator=(const Instrument &) = default; |
| 55 | Instrument &operator=(Instrument &&) = default; |
| 56 | virtual ~Instrument() = default; |
| 57 | |
| 58 | /** Identifier for the instrument */ |
| 59 | virtual std::string id() const = 0; |
| 60 | |
| 61 | /** Start measuring. */ |
| 62 | virtual void start() = 0; |
| 63 | |
| 64 | /** Stop measuring. */ |
| 65 | virtual void stop() = 0; |
| 66 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 67 | using MeasurementsMap = std::map<std::string, Measurement>; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 68 | |
Moritz Pflanzer | 09e4f98 | 2017-08-30 12:47:06 +0100 | [diff] [blame] | 69 | /** Return the latest measurement. */ |
| 70 | virtual MeasurementsMap measurements() const = 0; |
| 71 | }; |
Moritz Pflanzer | a4f711b | 2017-07-05 11:02:23 +0100 | [diff] [blame] | 72 | |
| 73 | template <typename T> |
| 74 | inline std::unique_ptr<Instrument> Instrument::make_instrument() |
| 75 | { |
| 76 | return support::cpp14::make_unique<T>(); |
| 77 | } |
| 78 | } // namespace framework |
| 79 | } // namespace test |
| 80 | } // namespace arm_compute |
| 81 | #endif /* ARM_COMPUTE_TEST_INSTRUMENT */ |