gem5 [DEVELOP-FOR-25.1]
Loading...
Searching...
No Matches
units.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __BASE_STATS_UNITS_HH__
30#define __BASE_STATS_UNITS_HH__
31
32#include <type_traits>
33
34#include "base/compiler.hh"
35#include "base/cprintf.hh"
36
37namespace gem5
38{
39
43#define UNIT_CYCLE GEM5_DEPRECATED_MACRO( \
44 UNIT_CYCLE, statistics::units::Cycle::get(), \
45 "Use statistics::units::Cycle::get()")
46#define UNIT_TICK GEM5_DEPRECATED_MACRO( \
47 UNIT_TICK, statistics::units::Tick::get(), "Use statistics::units::Tick::get()")
48#define UNIT_SECOND GEM5_DEPRECATED_MACRO( \
49 UNIT_SECOND, statistics::units::Second::get(), \
50 "Use statistics::units::Second::get()")
51#define UNIT_BIT GEM5_DEPRECATED_MACRO( \
52 UNIT_BIT, statistics::units::Bit::get(), "Use statistics::units::Bit::get()")
53#define UNIT_BYTE GEM5_DEPRECATED_MACRO( \
54 UNIT_BYTE, statistics::units::Byte::get(), "Use statistics::units::Byte::get()")
55#define UNIT_JOULE GEM5_DEPRECATED_MACRO( \
56 UNIT_JOULE, statistics::units::Joule::get(), \
57 "Use statistics::units::Joule::get()")
58#define UNIT_VOLT GEM5_DEPRECATED_MACRO( \
59 UNIT_VOLD, statistics::units::Volt::get(), "Use statistics::units::Volt::get()")
60#define UNIT_CELSIUS GEM5_DEPRECATED_MACRO( \
61 UNIT_CELSIUS, statistics::units::DegreeCelsius::get(), \
62 "Use statistics::units::DegreeCelsius::get()")
63#define UNIT_RATE(T1, T2) GEM5_DEPRECATED_MACRO( \
64 UNIT_RATE, (statistics::units::Rate<T1, T2>::get()), \
65 "Use statistics::units::Rate<T1, T2>::get()")
66#define UNIT_RATIO GEM5_DEPRECATED_MACRO( \
67 UNIT_RATIO, statistics::units::Ratio::get(), \
68 "Use statistics::units::Ratio::get()")
69#define UNIT_COUNT GEM5_DEPRECATED_MACRO( \
70 UNIT_COUNT, statistics::units::Count::get(), \
71 "Use statistics::units::Count::get()")
72#define UNIT_WATT GEM5_DEPRECATED_MACRO( \
73 UNIT_WATT, statistics::units::Watt::get(), "Use statistics::units::Watt::get()")
74#define UNIT_UNSPECIFIED GEM5_DEPRECATED_MACRO( \
75 UNIT_UNSPECIFIED, statistics::units::Unspecified::get(), \
76 "Use statistics::units::Unspecified::get()")
77
78namespace statistics
79{
80
112namespace units
113{
114
120class Base
121{
122 public:
123 virtual ~Base() = default;
124 virtual std::string getUnitString() const = 0;
125};
126
127class Cycle : public Base
128{
129 private:
130 Cycle() {}
131 public:
132 Cycle(Cycle const&) = delete;
133 void operator=(Cycle const&) = delete;
134 static Cycle*
136 {
137 static Cycle instance;
138 return &instance;
139 }
140 static std::string toString() { return "Cycle"; }
141 std::string getUnitString() const override { return Cycle::toString(); }
142};
143
144class Tick : public Base
145{
146 private:
147 Tick() {}
148 public:
149 Tick(Tick const&) = delete;
150 void operator=(Tick const&) = delete;
151 static Tick*
153 {
154 static Tick instance;
155 return &instance;
156 }
157 static std::string toString() { return "Tick"; }
158 std::string getUnitString() const override { return Tick::toString(); }
159};
160
161class Second : public Base
162{
163 private:
165 public:
166 Second(Second const&) = delete;
167 void operator=(Second const&) = delete;
168 static Second*
170 {
171 static Second instance;
172 return &instance;
173 }
174 static std::string toString() { return "Second"; }
175 std::string getUnitString() const override { return Second::toString(); }
176};
177
178class Bit : public Base
179{
180 private:
181 Bit() {}
182 public:
183 Bit(Bit const&) = delete;
184 void operator=(Bit const&) = delete;
185 static Bit*
187 {
188 static Bit instance;
189 return &instance;
190 }
191 static std::string toString() { return "Bit"; }
192 std::string getUnitString() const override { return Bit::toString(); }
193};
194
195class Byte : public Base
196{
197 private:
198 Byte() {}
199 public:
200 Byte(Byte const&) = delete;
201 void operator=(Byte const&) = delete;
202 static Byte*
204 {
205 static Byte instance;
206 return &instance;
207 }
208 static std::string toString() { return "Byte"; }
209 std::string getUnitString() const override { return Byte::toString(); }
210};
211
212class Watt : public Base
213{
214 private:
215 Watt() {}
216 public:
217 Watt(Watt const&) = delete;
218 void operator=(Watt const&) = delete;
219 static Watt*
221 {
222 static Watt instance;
223 return &instance;
224 }
225 static std::string toString() { return "Watt"; }
226 std::string getUnitString() const override { return Watt::toString(); }
227};
228
229
230class Joule : public Base
231{
232 private:
233 Joule() {}
234 public:
235 Joule(Joule const&) = delete;
236 void operator=(Joule const&) = delete;
237 static Joule*
239 {
240 static Joule instance;
241 return &instance;
242 }
243 static std::string toString() { return "Joule"; }
244 std::string getUnitString() const override { return Joule::toString(); }
245};
246
247class Volt : public Base
248{
249 private:
250 Volt() {}
251 public:
252 Volt(Volt const&) = delete;
253 void operator=(Volt const&) = delete;
254 static Volt*
256 {
257 static Volt instance;
258 return &instance;
259 }
260 static std::string toString() { return "Volt"; }
261 std::string getUnitString() const override { return Volt::toString(); }
262};
263
264class DegreeCelsius : public Base
265{
266 private:
268 public:
269 DegreeCelsius(DegreeCelsius const&) = delete;
270 void operator=(DegreeCelsius const&) = delete;
271 static DegreeCelsius*
273 {
274 static DegreeCelsius instance;
275 return &instance;
276 }
277 static std::string toString() { return "Celsius"; }
278 std::string
279 getUnitString() const override
280 {
282 }
283};
284
285
286class Count : public Base
287{
288 private:
289 Count() {}
290 public:
291 Count(Count const&) = delete;
292 void operator=(Count const&) = delete;
293 static Count*
295 {
296 static Count instance;
297 return &instance;
298 }
299 static std::string toString() { return "Count"; }
300 std::string getUnitString() const override { return Count::toString(); }
301};
302
303class Ratio : public Base
304{
305 private:
306 Ratio() {}
307 public:
308 Ratio(Ratio const&) = delete;
309 void operator=(Ratio const&) = delete;
310 static Ratio*
312 {
313 static Ratio instance;
314 return &instance;
315 }
316 static std::string toString() { return "Ratio"; }
317 std::string getUnitString() const override { return Ratio::toString(); }
318};
319
320class Unspecified : public Base
321{
322 private:
324 public:
325 Unspecified(Unspecified const&) = delete;
326 void operator=(Unspecified const&) = delete;
327 static Unspecified*
329 {
330 static Unspecified instance;
331 return &instance;
332 }
333 static std::string toString() { return "Unspecified"; }
334 std::string
335 getUnitString() const override
336 {
337 return Unspecified::toString();
338 }
339};
340
341template <typename T1, typename T2>
342class Rate : public Base
343{
344 static_assert(std::is_base_of_v<Base, T1>, "Rate(T1,T2) must have "
345 "T1 and T2 derived from statistics::units::Base");
346 static_assert(std::is_base_of_v<Base, T2>, "Rate(T1,T2) must have "
347 "T1 and T2 derived from statistics::units::Base");
348 static_assert(!std::is_same_v<T1, T2> || std::is_same_v<T1, Count> ||
349 std::is_same_v<T1, Unspecified>,
350 "Rate(T1,T2) must have T1 and T2 of different types; "
351 "otherwise, it would be a Ratio");
352
353 private:
354 Rate() {}
355 public:
356 Rate(Rate const&) = delete;
357 void operator=(Rate<T1,T2> const&) = delete;
358 static Rate<T1,T2>*
360 {
361 static Rate<T1,T2> instance;
362 return &instance;
363 }
364 static std::string
366 {
367 return csprintf("(%s/%s)", T1::toString(), T2::toString());
368 }
369 std::string
370 getUnitString() const override
371 {
372 return Rate<T1,T2>::toString();
373 }
374};
375
376} // namespace units
377} // namespace statistics
378} // namespace gem5
379
380#endif // __BASE_STATS_UNITS_HH__
The Base class is the parent class of all unit classes.
Definition units.hh:121
virtual std::string getUnitString() const =0
void operator=(Bit const &)=delete
static std::string toString()
Definition units.hh:191
std::string getUnitString() const override
Definition units.hh:192
Bit(Bit const &)=delete
std::string getUnitString() const override
Definition units.hh:209
Byte(Byte const &)=delete
static std::string toString()
Definition units.hh:208
void operator=(Byte const &)=delete
Count(Count const &)=delete
std::string getUnitString() const override
Definition units.hh:300
void operator=(Count const &)=delete
static std::string toString()
Definition units.hh:299
static std::string toString()
Definition units.hh:140
void operator=(Cycle const &)=delete
std::string getUnitString() const override
Definition units.hh:141
Cycle(Cycle const &)=delete
std::string getUnitString() const override
Definition units.hh:279
DegreeCelsius(DegreeCelsius const &)=delete
void operator=(DegreeCelsius const &)=delete
static DegreeCelsius * get()
Definition units.hh:272
static std::string toString()
Definition units.hh:277
std::string getUnitString() const override
Definition units.hh:244
void operator=(Joule const &)=delete
Joule(Joule const &)=delete
static std::string toString()
Definition units.hh:243
static std::string toString()
Definition units.hh:365
Rate(Rate const &)=delete
static Rate< T1, T2 > * get()
Definition units.hh:359
void operator=(Rate< T1, T2 > const &)=delete
std::string getUnitString() const override
Definition units.hh:370
void operator=(Ratio const &)=delete
static std::string toString()
Definition units.hh:316
Ratio(Ratio const &)=delete
std::string getUnitString() const override
Definition units.hh:317
std::string getUnitString() const override
Definition units.hh:175
void operator=(Second const &)=delete
Second(Second const &)=delete
static std::string toString()
Definition units.hh:174
static Second * get()
Definition units.hh:169
static std::string toString()
Definition units.hh:157
Tick(Tick const &)=delete
std::string getUnitString() const override
Definition units.hh:158
void operator=(Tick const &)=delete
static std::string toString()
Definition units.hh:333
std::string getUnitString() const override
Definition units.hh:335
void operator=(Unspecified const &)=delete
static Unspecified * get()
Definition units.hh:328
Unspecified(Unspecified const &)=delete
Volt(Volt const &)=delete
void operator=(Volt const &)=delete
std::string getUnitString() const override
Definition units.hh:261
static std::string toString()
Definition units.hh:260
void operator=(Watt const &)=delete
static std::string toString()
Definition units.hh:225
std::string getUnitString() const override
Definition units.hh:226
Watt(Watt const &)=delete
Units for Stats.
Definition units.hh:113
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
std::string csprintf(const char *format, const Args &...args)
Definition cprintf.hh:161

Generated on Mon Oct 27 2025 04:13:00 for gem5 by doxygen 1.14.0