gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
info.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 Daniel R. Carvalho
3  * Copyright (c) 2019 Arm Limited
4  * All rights reserved.
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Copyright (c) 2003-2005 The Regents of The University of Michigan
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
42 #include "base/stats/info.hh"
43 
44 #include <cctype>
45 
46 #include "base/cprintf.hh"
47 #include "base/debug.hh"
48 #include "base/logging.hh"
49 #include "base/stats/storage.hh"
50 #include "base/str.hh"
51 
52 namespace gem5
53 {
54 
55 namespace statistics
56 {
57 
58 std::string Info::separatorString = "::";
59 
60 int Info::id_count = 0;
61 
62 int debug_break_id = -1;
63 
66 {
67  static NameMapType the_map;
68  return the_map;
69 }
70 
72  : flags(none), precision(-1), prereq(0), storageParams()
73 {
74  id = id_count++;
75  if (debug_break_id >= 0 and debug_break_id == id)
77 }
78 
80 {
81 }
82 
83 StorageParams const*
85 {
86  return storageParams.get();
87 }
88 
89 void
91 {
92  return storageParams.reset(params);
93 }
94 
95 bool
96 validateStatName(const std::string &name)
97 {
98  if (name.empty())
99  return false;
100 
102  tokenize(vec, name, '.', false);
104  while (item != vec.end()) {
105  if (item->empty())
106  return false;
107 
108  std::string::const_iterator c = item->begin();
109 
110  // The first character is different
111  if (!isalpha(*c) && *c != '_')
112  return false;
113 
114  // The rest of the characters have different rules.
115  while (++c != item->end()) {
116  if (!isalnum(*c) && *c != '_')
117  return false;
118  }
119 
120  ++item;
121  }
122 
123  return true;
124 }
125 
126 void
127 Info::setName(const std::string &name, bool old_style)
128 {
129  if (!validateStatName(name))
130  panic("invalid stat name '%s'", name);
131 
132  // We only register the stat with the nameMap() if we are using
133  // old-style stats without a parent group. New-style stats should
134  // be unique since their names should correspond to a member
135  // variable.
136  if (old_style) {
137  auto p = nameMap().insert(make_pair(name, this));
138 
139  panic_if(!p.second, "same statistic name used twice! name=%s\n", name);
140  }
141 
142  this->name = name;
143 }
144 
145 bool
146 Info::less(Info *stat1, Info *stat2)
147 {
148  const std::string &name1 = stat1->name;
149  const std::string &name2 = stat2->name;
150 
153 
154  tokenize(v1, name1, '.');
155  tokenize(v2, name2, '.');
156 
157  size_type last = std::min(v1.size(), v2.size()) - 1;
158  for (off_type i = 0; i < last; ++i)
159  if (v1[i] != v2[i])
160  return v1[i] < v2[i];
161 
162  // Special compare for last element.
163  if (v1[last] == v2[last])
164  return v1.size() < v2.size();
165  else
166  return v1[last] < v2[last];
167 
168  return false;
169 }
170 
171 bool
173 {
174  if (!(flags & statistics::init)) {
175  panic("this is stat number %d\n"
176  "Not all stats have been initialized.\n"
177  "You may need to add <ParentClass>::regStats() to a"
178  " new SimObject's regStats() function. Name: %s",
179  id, name);
180  return false;
181  }
182 
183  if ((flags & display) && name.empty()) {
184  panic("all printable stats must be named");
185  return false;
186  }
187 
188  return true;
189 }
190 
191 void
193 {
194 }
195 
196 void
198 {
199  size_type s = size();
200  if (subnames.size() < s)
201  subnames.resize(s);
202  if (subdescs.size() < s)
203  subdescs.resize(s);
204 }
205 
206 void
208 {
209  size_type s = size();
210  if (subnames.size() < s)
211  subnames.resize(s);
212  if (subdescs.size() < s)
213  subdescs.resize(s);
214 }
215 
216 void
218 {
219  if (subnames.size() < x)
220  subnames.resize(x);
221  if (subdescs.size() < x)
222  subdescs.resize(x);
223  if (y_subnames.size() < y)
224  y_subnames.resize(y);
225 }
226 
227 } // namespace statistics
228 } // namespace gem5
gem5::VegaISA::s
Bitfield< 1 > s
Definition: pagetable.hh:64
gem5::statistics::VectorInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:188
gem5::statistics::Info::enable
virtual void enable()
Enable the stat for use.
Definition: info.cc:192
gem5::statistics::VectorDistInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:213
gem5::statistics::VectorDistInfo::size
virtual size_type size() const =0
gem5::statistics::Vector2dInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:217
gem5::statistics::VectorInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:197
gem5::debug::breakpoint
void breakpoint()
Definition: debug.cc:64
gem5::statistics::Vector2dInfo::y_subnames
std::vector< std::string > y_subnames
Definition: info.hh:231
gem5::statistics::Info::storageParams
std::unique_ptr< const StorageParams > storageParams
Definition: info.hh:104
std::vector< std::string >
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:67
gem5::statistics::Vector2dInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:230
gem5::statistics::none
const FlagsType none
Nothing extra to print.
Definition: info.hh:53
gem5::statistics::Info::flags
Flags flags
The formatting flags.
Definition: info.hh:91
storage.hh
str.hh
gem5::statistics::Info::baseCheck
bool baseCheck() const
Definition: info.cc:172
gem5::VegaISA::c
Bitfield< 2 > c
Definition: pagetable.hh:63
info.hh
gem5::statistics::off_type
unsigned int off_type
Definition: types.hh:60
gem5::statistics::Info::id_count
static int id_count
A unique stat ID for each stat in the simulator.
Definition: info.hh:100
gem5::VegaISA::p
Bitfield< 54 > p
Definition: pagetable.hh:70
gem5::statistics::display
const FlagsType display
Print this stat.
Definition: info.hh:57
debug.hh
cprintf.hh
flags
uint8_t flags
Definition: helpers.cc:66
gem5::tokenize
void tokenize(std::vector< std::string > &v, const std::string &s, char token, bool ignore)
Definition: str.cc:68
gem5::statistics::size_type
unsigned int size_type
Definition: types.hh:59
gem5::statistics::Vector2dInfo::y
size_type y
Definition: info.hh:234
name
const std::string & name()
Definition: trace.cc:48
gem5::statistics::debug_break_id
int debug_break_id
Definition: info.cc:62
gem5::statistics::NameMapType
std::map< std::string, Info * > NameMapType
Definition: info.hh:257
gem5::statistics::Info::setName
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
Definition: info.cc:127
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:214
gem5::statistics::VectorDistInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:214
gem5::statistics::nameMap
NameMapType & nameMap()
Definition: info.cc:65
gem5::statistics::StorageParams
Definition: storage.hh:48
gem5::statistics::VectorInfo::size
virtual size_type size() const =0
gem5::statistics::Info::less
static bool less(Info *stat1, Info *stat2)
Checks if the first stat's name is alphabetically less than the second.
Definition: info.cc:146
gem5::PowerISA::vec
Bitfield< 25 > vec
Definition: misc.hh:113
gem5::statistics::Vector2dInfo::x
size_type x
Definition: info.hh:233
logging.hh
gem5::statistics::VectorDistInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:207
gem5::statistics::Info::setStorageParams
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition: info.cc:90
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:55
gem5::statistics::validateStatName
bool validateStatName(const std::string &name)
Definition: info.cc:96
gem5::statistics::Info::separatorString
static std::string separatorString
The separator string used for vectors, dist, etc.
Definition: info.hh:85
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::statistics::Info::getStorageParams
StorageParams const * getStorageParams() const
Getter for the storage params.
Definition: info.cc:84
gem5::statistics::Vector2dInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:229
gem5::statistics::VectorInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:187
gem5::statistics::Info::Info
Info()
Definition: info.cc:71
gem5::statistics::Info::name
std::string name
The name of the stat.
Definition: info.hh:83
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
gem5::statistics::Info
Definition: info.hh:79
gem5::statistics::Info::~Info
virtual ~Info()
Definition: info.cc:79

Generated on Sun Jul 30 2023 01:56:51 for gem5 by doxygen 1.8.17