gem5  v21.1.0.2
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 
37 namespace 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 
78 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
79 namespace statistics
80 {
81 
113 GEM5_DEPRECATED_NAMESPACE(Units, units);
114 namespace units
115 {
116 
122 class Base
123 {
124  public:
125  virtual std::string getUnitString() const = 0;
126 };
127 
128 class Cycle : public Base
129 {
130  private:
131  Cycle() {}
132  public:
133  Cycle(Cycle const&) = delete;
134  void operator=(Cycle const&) = delete;
135  static Cycle*
136  get()
137  {
138  static Cycle instance;
139  return &instance;
140  }
141  static std::string toString() { return "Cycle"; }
142  std::string getUnitString() const override { return Cycle::toString(); }
143 };
144 
145 class Tick : public Base
146 {
147  private:
148  Tick() {}
149  public:
150  Tick(Tick const&) = delete;
151  void operator=(Tick const&) = delete;
152  static Tick*
153  get()
154  {
155  static Tick instance;
156  return &instance;
157  }
158  static std::string toString() { return "Tick"; }
159  std::string getUnitString() const override { return Tick::toString(); }
160 };
161 
162 class Second : public Base
163 {
164  private:
165  Second() {}
166  public:
167  Second(Second const&) = delete;
168  void operator=(Second const&) = delete;
169  static Second*
170  get()
171  {
172  static Second instance;
173  return &instance;
174  }
175  static std::string toString() { return "Second"; }
176  std::string getUnitString() const override { return Second::toString(); }
177 };
178 
179 class Bit : public Base
180 {
181  private:
182  Bit() {}
183  public:
184  Bit(Bit const&) = delete;
185  void operator=(Bit const&) = delete;
186  static Bit*
187  get()
188  {
189  static Bit instance;
190  return &instance;
191  }
192  static std::string toString() { return "Bit"; }
193  std::string getUnitString() const override { return Bit::toString(); }
194 };
195 
196 class Byte : public Base
197 {
198  private:
199  Byte() {}
200  public:
201  Byte(Byte const&) = delete;
202  void operator=(Byte const&) = delete;
203  static Byte*
204  get()
205  {
206  static Byte instance;
207  return &instance;
208  }
209  static std::string toString() { return "Byte"; }
210  std::string getUnitString() const override { return Byte::toString(); }
211 };
212 
213 class Watt : public Base
214 {
215  private:
216  Watt() {}
217  public:
218  Watt(Watt const&) = delete;
219  void operator=(Watt const&) = delete;
220  static Watt*
221  get()
222  {
223  static Watt instance;
224  return &instance;
225  }
226  static std::string toString() { return "Watt"; }
227  std::string getUnitString() const override { return Watt::toString(); }
228 };
229 
230 
231 class Joule : public Base
232 {
233  private:
234  Joule() {}
235  public:
236  Joule(Joule const&) = delete;
237  void operator=(Joule const&) = delete;
238  static Joule*
239  get()
240  {
241  static Joule instance;
242  return &instance;
243  }
244  static std::string toString() { return "Joule"; }
245  std::string getUnitString() const override { return Joule::toString(); }
246 };
247 
248 class Volt : public Base
249 {
250  private:
251  Volt() {}
252  public:
253  Volt(Volt const&) = delete;
254  void operator=(Volt const&) = delete;
255  static Volt*
256  get()
257  {
258  static Volt instance;
259  return &instance;
260  }
261  static std::string toString() { return "Volt"; }
262  std::string getUnitString() const override { return Volt::toString(); }
263 };
264 
265 class DegreeCelsius : public Base
266 {
267  private:
269  public:
270  DegreeCelsius(DegreeCelsius const&) = delete;
271  void operator=(DegreeCelsius const&) = delete;
272  static DegreeCelsius*
273  get()
274  {
275  static DegreeCelsius instance;
276  return &instance;
277  }
278  static std::string toString() { return "Celsius"; }
279  std::string
280  getUnitString() const override
281  {
282  return DegreeCelsius::toString();
283  }
284 };
285 
286 
287 class Count : public Base
288 {
289  private:
290  Count() {}
291  public:
292  Count(Count const&) = delete;
293  void operator=(Count const&) = delete;
294  static Count*
295  get()
296  {
297  static Count instance;
298  return &instance;
299  }
300  static std::string toString() { return "Count"; }
301  std::string getUnitString() const override { return Count::toString(); }
302 };
303 
304 class Ratio : public Base
305 {
306  private:
307  Ratio() {}
308  public:
309  Ratio(Ratio const&) = delete;
310  void operator=(Ratio const&) = delete;
311  static Ratio*
312  get()
313  {
314  static Ratio instance;
315  return &instance;
316  }
317  static std::string toString() { return "Ratio"; }
318  std::string getUnitString() const override { return Ratio::toString(); }
319 };
320 
321 class Unspecified : public Base
322 {
323  private:
325  public:
326  Unspecified(Unspecified const&) = delete;
327  void operator=(Unspecified const&) = delete;
328  static Unspecified*
329  get()
330  {
331  static Unspecified instance;
332  return &instance;
333  }
334  static std::string toString() { return "Unspecified"; }
335  std::string
336  getUnitString() const override
337  {
338  return Unspecified::toString();
339  }
340 };
341 
342 template <typename T1, typename T2>
343 class Rate : public Base
344 {
345  static_assert(std::is_base_of<Base, T1>::value, "Rate(T1,T2) must have "
346  "T1 and T2 derived from statistics::units::Base");
347  static_assert(std::is_base_of<Base, T2>::value, "Rate(T1,T2) must have "
348  "T1 and T2 derived from statistics::units::Base");
349  static_assert(!std::is_same<T1, T2>::value ||
350  std::is_same<T1, Count>::value || std::is_same<T1, Unspecified>::value,
351  "Rate(T1,T2) must have T1 and T2 of different types; "
352  "otherwise, it would be a Ratio");
353 
354  private:
356  public:
357  Rate<T1,T2>(Rate<T1,T2> const&) = delete;
358  void operator=(Rate<T1,T2> const&) = delete;
359  static Rate<T1,T2>*
360  get()
361  {
362  static Rate<T1,T2> instance;
363  return &instance;
364  }
365  static std::string
367  {
368  return csprintf("(%s/%s)", T1::toString(), T2::toString());
369  }
370  std::string
371  getUnitString() const override
372  {
373  return Rate<T1,T2>::toString();
374  }
375 };
376 
377 } // namespace units
378 } // namespace statistics
379 } // namespace gem5
380 
381 #endif // __BASE_STATS_UNITS_HH__
gem5::statistics::units::Byte::Byte
Byte()
Definition: units.hh:199
gem5::statistics::units::Volt::Volt
Volt()
Definition: units.hh:251
gem5::statistics::units::Second::get
static Second * get()
Definition: units.hh:170
gem5::statistics::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(Units, units)
Units for Stats.
gem5::statistics::units::Base::getUnitString
virtual std::string getUnitString() const =0
gem5::statistics::units::Base
The Base class is the parent class of all unit classes.
Definition: units.hh:122
gem5::statistics::units::DegreeCelsius::toString
static std::string toString()
Definition: units.hh:278
gem5::statistics::units::Byte::toString
static std::string toString()
Definition: units.hh:209
gem5::statistics::units::Rate::getUnitString
std::string getUnitString() const override
Definition: units.hh:371
gem5::statistics::units::Bit::Bit
Bit()
Definition: units.hh:182
gem5::statistics::units::Joule::toString
static std::string toString()
Definition: units.hh:244
gem5::statistics::units::Unspecified::toString
static std::string toString()
Definition: units.hh:334
gem5::statistics::units::DegreeCelsius
Definition: units.hh:265
gem5::statistics::units::DegreeCelsius::getUnitString
std::string getUnitString() const override
Definition: units.hh:280
gem5::statistics::units::Unspecified::getUnitString
std::string getUnitString() const override
Definition: units.hh:336
gem5::statistics::units::Second::Second
Second()
Definition: units.hh:165
gem5::statistics::units::Rate::get
static Rate< T1, T2 > * get()
Definition: units.hh:360
gem5::statistics::units::Cycle::get
static Cycle * get()
Definition: units.hh:136
gem5::statistics::units::Bit::operator=
void operator=(Bit const &)=delete
gem5::csprintf
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
gem5::statistics::units::Count
Definition: units.hh:287
gem5::statistics::units::Tick::operator=
void operator=(Tick const &)=delete
gem5::statistics::units::Unspecified::get
static Unspecified * get()
Definition: units.hh:329
gem5::statistics::units::Volt::operator=
void operator=(Volt const &)=delete
gem5::statistics::units::Second
Definition: units.hh:162
gem5::statistics::units::Volt::getUnitString
std::string getUnitString() const override
Definition: units.hh:262
gem5::statistics::units::Tick::toString
static std::string toString()
Definition: units.hh:158
gem5::statistics::units::Watt::toString
static std::string toString()
Definition: units.hh:226
gem5::statistics::units::Count::get
static Count * get()
Definition: units.hh:295
gem5::statistics::units::Joule::operator=
void operator=(Joule const &)=delete
gem5::statistics::units::Ratio::get
static Ratio * get()
Definition: units.hh:312
gem5::statistics::units::Volt
Definition: units.hh:248
gem5::statistics::units::Unspecified::Unspecified
Unspecified()
Definition: units.hh:324
gem5::statistics::units::Ratio::toString
static std::string toString()
Definition: units.hh:317
gem5::statistics::units::Joule::Joule
Joule()
Definition: units.hh:234
gem5::statistics::units::Volt::toString
static std::string toString()
Definition: units.hh:261
gem5::statistics::units::Joule::get
static Joule * get()
Definition: units.hh:239
gem5::statistics::units::Ratio::Ratio
Ratio()
Definition: units.hh:307
gem5::statistics::units::Joule
Definition: units.hh:231
gem5::statistics::units::Second::operator=
void operator=(Second const &)=delete
gem5::statistics::units::Tick::getUnitString
std::string getUnitString() const override
Definition: units.hh:159
gem5::statistics::units::Unspecified
Definition: units.hh:321
gem5::statistics::units::Watt::getUnitString
std::string getUnitString() const override
Definition: units.hh:227
gem5::statistics::units::Tick::Tick
Tick()
Definition: units.hh:148
gem5::statistics::units::Second::toString
static std::string toString()
Definition: units.hh:175
gem5::statistics::units::Count::Count
Count()
Definition: units.hh:290
cprintf.hh
compiler.hh
gem5::statistics::units::Byte
Definition: units.hh:196
gem5::statistics::units::Cycle::getUnitString
std::string getUnitString() const override
Definition: units.hh:142
gem5::statistics::units::Count::getUnitString
std::string getUnitString() const override
Definition: units.hh:301
gem5::statistics::units::Watt::operator=
void operator=(Watt const &)=delete
gem5::statistics::units::Bit
Definition: units.hh:179
gem5::statistics::units::Cycle
Definition: units.hh:128
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::statistics::units::Second::getUnitString
std::string getUnitString() const override
Definition: units.hh:176
gem5::statistics::units::Ratio
Definition: units.hh:304
gem5::statistics::units::DegreeCelsius::operator=
void operator=(DegreeCelsius const &)=delete
gem5::statistics::units::Byte::getUnitString
std::string getUnitString() const override
Definition: units.hh:210
gem5::statistics::units::Cycle::operator=
void operator=(Cycle const &)=delete
gem5::statistics::units::Bit::get
static Bit * get()
Definition: units.hh:187
gem5::statistics::units::Byte::operator=
void operator=(Byte const &)=delete
gem5::statistics::units::Count::toString
static std::string toString()
Definition: units.hh:300
gem5::statistics::units::Rate::operator=
void operator=(Rate< T1, T2 > const &)=delete
gem5::statistics::units::DegreeCelsius::DegreeCelsius
DegreeCelsius()
Definition: units.hh:268
gem5::statistics::units::Watt::Watt
Watt()
Definition: units.hh:216
gem5::statistics::units::Ratio::operator=
void operator=(Ratio const &)=delete
gem5::statistics::units::Volt::get
static Volt * get()
Definition: units.hh:256
gem5::statistics::units::Ratio::getUnitString
std::string getUnitString() const override
Definition: units.hh:318
gem5::statistics::units::Tick::get
static Tick * get()
Definition: units.hh:153
gem5::statistics::units::Count::operator=
void operator=(Count const &)=delete
gem5::statistics::units::Rate
Definition: units.hh:343
gem5::statistics::units::DegreeCelsius::get
static DegreeCelsius * get()
Definition: units.hh:273
gem5::statistics::units::Watt::get
static Watt * get()
Definition: units.hh:221
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::statistics::units::Rate::toString
static std::string toString()
Definition: units.hh:366
gem5::statistics::units::Byte::get
static Byte * get()
Definition: units.hh:204
gem5::statistics::units::Unspecified::operator=
void operator=(Unspecified const &)=delete
gem5::statistics::units::Bit::toString
static std::string toString()
Definition: units.hh:192
gem5::statistics::units::Joule::getUnitString
std::string getUnitString() const override
Definition: units.hh:245
gem5::statistics::units::Cycle::Cycle
Cycle()
Definition: units.hh:131
gem5::statistics::units::Tick
Definition: units.hh:145
gem5::statistics::units::Watt
Definition: units.hh:213
gem5::statistics::units::Cycle::toString
static std::string toString()
Definition: units.hh:141
gem5::statistics::units::Bit::getUnitString
std::string getUnitString() const override
Definition: units.hh:193

Generated on Tue Sep 21 2021 12:25:00 for gem5 by doxygen 1.8.17