blob: ae4644b2003e5b4277242a6f746290a695b2acf4 [file] [log] [blame]
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01001/*
Anthony Barbierc9afce52018-01-26 16:07:50 +00002 * Copyright (c) 2017-2018 ARM Limited.
Moritz Pflanzera4f711b2017-07-05 11:02:23 +01003 *
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 Pflanzer09e4f982017-08-30 12:47:06 +010028#include "Measurement.h"
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010029
Moritz Pflanzer09e4f982017-08-30 12:47:06 +010030#include <map>
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010031#include <memory>
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010032#include <string>
33
34namespace arm_compute
35{
36namespace test
37{
38namespace framework
39{
Giorgio Arenace58a9f2017-10-31 17:59:17 +000040enum class ScaleFactor : unsigned int
41{
42 NONE, /* Default scale */
43 SCALE_1K, /* 1000 */
44 SCALE_1M, /* 1 000 000 */
45 TIME_US, /* Microseconds */
46 TIME_MS, /* Milliseconds */
47 TIME_S, /* Seconds */
48};
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010049/** Interface for classes that can be used to measure performance. */
50class Instrument
51{
52public:
53 /** Helper function to create an instrument of the given type.
54 *
55 * @return Instance of an instrument of the given type.
56 */
Giorgio Arenace58a9f2017-10-31 17:59:17 +000057 template <typename T, ScaleFactor scale>
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010058 static std::unique_ptr<Instrument> make_instrument();
59
Alex Gildayc357c472018-03-21 13:54:09 +000060 /** Default constructor. */
Giorgio Arenace58a9f2017-10-31 17:59:17 +000061 Instrument() = default;
62
Alex Gildayc357c472018-03-21 13:54:09 +000063 /** Allow instances of this class to be copy constructed */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010064 Instrument(const Instrument &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000065 /** Allow instances of this class to be move constructed */
66 Instrument(Instrument &&) = default;
67 /** Allow instances of this class to be copied */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010068 Instrument &operator=(const Instrument &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000069 /** Allow instances of this class to be moved */
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010070 Instrument &operator=(Instrument &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +000071 /** Default destructor. */
72 virtual ~Instrument() = default;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010073
74 /** Identifier for the instrument */
75 virtual std::string id() const = 0;
76
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010077 /** Start of the test
78 *
79 * Called before the test set up starts
80 */
81 virtual void test_start()
82 {
83 }
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010084
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010085 /** Start measuring.
86 *
87 * Called just before the run of the test starts
88 */
89 virtual void start()
90 {
91 }
Moritz Pflanzera4f711b2017-07-05 11:02:23 +010092
Anthony Barbier9fb0cac2018-04-20 15:46:21 +010093 /** Stop measuring.
94 *
95 * Called just after the run of the test ends
96 */
97 virtual void stop()
98 {
99 }
100
101 /** End of the test
102 *
103 * Called after the test teardown ended
104 */
105 virtual void test_stop()
106 {
107 }
Alex Gildayc357c472018-03-21 13:54:09 +0000108 /** Map of measurements */
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100109 using MeasurementsMap = std::map<std::string, Measurement>;
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100110
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100111 /** Return the latest measurements.
Alex Gildayc357c472018-03-21 13:54:09 +0000112 *
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100113 * @return the latest measurements.
Alex Gildayc357c472018-03-21 13:54:09 +0000114 */
Anthony Barbier9fb0cac2018-04-20 15:46:21 +0100115 virtual MeasurementsMap measurements() const
116 {
117 return MeasurementsMap();
118 }
119
120 /** Return the latest test measurements.
121 *
122 * @return the latest test measurements.
123 */
124 virtual MeasurementsMap test_measurements() const
125 {
126 return MeasurementsMap();
127 }
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000128
129protected:
130 std::string _unit{};
Moritz Pflanzer09e4f982017-08-30 12:47:06 +0100131};
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100132
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000133template <typename T, ScaleFactor scale>
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100134inline std::unique_ptr<Instrument> Instrument::make_instrument()
135{
Giorgio Arenace58a9f2017-10-31 17:59:17 +0000136 return support::cpp14::make_unique<T>(scale);
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100137}
Anthony Barbierc9afce52018-01-26 16:07:50 +0000138
Moritz Pflanzera4f711b2017-07-05 11:02:23 +0100139} // namespace framework
140} // namespace test
141} // namespace arm_compute
142#endif /* ARM_COMPUTE_TEST_INSTRUMENT */