blob: 895a64738c49f597b9ef710be87668d396993a12 [file] [log] [blame]
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01001/*
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"
28
29#include <memory>
30#include <ostream>
31#include <string>
32
33namespace arm_compute
34{
35namespace test
36{
37namespace framework
38{
39/** Interface for classes that can be used to measure performance. */
40class Instrument
41{
42public:
43 /** Helper function to create an instrument of the given type.
44 *
45 * @return Instance of an instrument of the given type.
46 */
47 template <typename T>
48 static std::unique_ptr<Instrument> make_instrument();
49
50 /** Struct representing measurement consisting of value and unit. */
51 struct Measurement final
52 {
53 Measurement(double value, std::string unit)
54 : value{ value }, unit{ std::move(unit) }
55 {
56 }
57
58 friend std::ostream &operator<<(std::ostream &os, const Measurement &measurement);
59
60 double value;
61 std::string unit;
62 };
63
64 Instrument() = default;
65 Instrument(const Instrument &) = default;
66 Instrument(Instrument &&) = default;
67 Instrument &operator=(const Instrument &) = default;
68 Instrument &operator=(Instrument &&) = default;
69 virtual ~Instrument() = default;
70
71 /** Identifier for the instrument */
72 virtual std::string id() const = 0;
73
74 /** Start measuring. */
75 virtual void start() = 0;
76
77 /** Stop measuring. */
78 virtual void stop() = 0;
79
80 /** Return the latest measurement. */
81 virtual Measurement measurement() const = 0;
82};
83
84inline std::ostream &operator<<(std::ostream &os, const Instrument::Measurement &measurement)
85{
86 os << measurement.value << measurement.unit;
87 return os;
88}
89
90template <typename T>
91inline std::unique_ptr<Instrument> Instrument::make_instrument()
92{
93 return support::cpp14::make_unique<T>();
94}
95} // namespace framework
96} // namespace test
97} // namespace arm_compute
98#endif /* ARM_COMPUTE_TEST_INSTRUMENT */