gem5  v21.1.0.2
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 GEM5_DEPRECATED_NAMESPACE(Stats, statistics);
56 namespace statistics
57 {
58 
59 std::string Info::separatorString = "::";
60 
61 int Info::id_count = 0;
62 
63 int debug_break_id = -1;
64 
67 {
68  static NameMapType the_map;
69  return the_map;
70 }
71 
73  : flags(none), precision(-1), prereq(0), storageParams()
74 {
75  id = id_count++;
76  if (debug_break_id >= 0 and debug_break_id == id)
78 }
79 
81 {
82 }
83 
84 StorageParams const*
86 {
87  return storageParams.get();
88 }
89 
90 void
92 {
93  return storageParams.reset(params);
94 }
95 
96 bool
97 validateStatName(const std::string &name)
98 {
99  if (name.empty())
100  return false;
101 
103  tokenize(vec, name, '.', false);
105  while (item != vec.end()) {
106  if (item->empty())
107  return false;
108 
109  std::string::const_iterator c = item->begin();
110 
111  // The first character is different
112  if (!isalpha(*c) && *c != '_')
113  return false;
114 
115  // The rest of the characters have different rules.
116  while (++c != item->end()) {
117  if (!isalnum(*c) && *c != '_')
118  return false;
119  }
120 
121  ++item;
122  }
123 
124  return true;
125 }
126 
127 void
128 Info::setName(const std::string &name, bool old_style)
129 {
130  if (!validateStatName(name))
131  panic("invalid stat name '%s'", name);
132 
133  // We only register the stat with the nameMap() if we are using
134  // old-style stats without a parent group. New-style stats should
135  // be unique since their names should correspond to a member
136  // variable.
137  if (old_style) {
138  auto p = nameMap().insert(make_pair(name, this));
139 
140  panic_if(!p.second, "same statistic name used twice! name=%s\n", name);
141  }
142 
143  this->name = name;
144 }
145 
146 bool
147 Info::less(Info *stat1, Info *stat2)
148 {
149  const std::string &name1 = stat1->name;
150  const std::string &name2 = stat2->name;
151 
154 
155  tokenize(v1, name1, '.');
156  tokenize(v2, name2, '.');
157 
158  size_type last = std::min(v1.size(), v2.size()) - 1;
159  for (off_type i = 0; i < last; ++i)
160  if (v1[i] != v2[i])
161  return v1[i] < v2[i];
162 
163  // Special compare for last element.
164  if (v1[last] == v2[last])
165  return v1.size() < v2.size();
166  else
167  return v1[last] < v2[last];
168 
169  return false;
170 }
171 
172 bool
174 {
175  if (!(flags & statistics::init)) {
176 #ifdef DEBUG
177  cprintf("this is stat number %d\n", id);
178 #endif
179  panic("Not all stats have been initialized.\n"
180  "You may need to add <ParentClass>::regStats() to a"
181  " new SimObject's regStats() function. Name: %s",
182  name);
183  return false;
184  }
185 
186  if ((flags & display) && name.empty()) {
187  panic("all printable stats must be named");
188  return false;
189  }
190 
191  return true;
192 }
193 
194 void
196 {
197 }
198 
199 void
201 {
202  size_type s = size();
203  if (subnames.size() < s)
204  subnames.resize(s);
205  if (subdescs.size() < s)
206  subdescs.resize(s);
207 }
208 
209 void
211 {
212  size_type s = size();
213  if (subnames.size() < s)
214  subnames.resize(s);
215  if (subdescs.size() < s)
216  subdescs.resize(s);
217 }
218 
219 void
221 {
222  if (subnames.size() < x)
223  subnames.resize(x);
224  if (subdescs.size() < x)
225  subdescs.resize(x);
226  if (y_subnames.size() < y)
227  y_subnames.resize(y);
228 }
229 
230 } // namespace statistics
231 } // namespace gem5
gem5::statistics::VectorInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:189
gem5::statistics::Info::enable
virtual void enable()
Enable the stat for use.
Definition: info.cc:195
gem5::cprintf
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
gem5::statistics::VectorDistInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:214
gem5::statistics::VectorDistInfo::size
virtual size_type size() const =0
gem5::statistics::Vector2dInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:220
gem5::statistics::VectorInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:200
gem5::debug::breakpoint
void breakpoint()
Definition: debug.cc:65
gem5::statistics::Vector2dInfo::y_subnames
std::vector< std::string > y_subnames
Definition: info.hh:232
gem5::statistics::Info::storageParams
std::unique_ptr< const StorageParams > storageParams
Definition: info.hh:105
std::vector< std::string >
gem5::ArmISA::i
Bitfield< 7 > i
Definition: misc_types.hh:66
gem5::statistics::Vector2dInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:231
gem5::statistics::none
const FlagsType none
Nothing extra to print.
Definition: info.hh:54
gem5::statistics::Info::flags
Flags flags
The formatting flags.
Definition: info.hh:92
storage.hh
str.hh
gem5::statistics::Info::baseCheck
bool baseCheck() const
Definition: info.cc:173
info.hh
gem5::statistics::off_type
unsigned int off_type
Definition: types.hh:61
gem5::statistics::Info::id_count
static int id_count
A unique stat ID for each stat in the simulator.
Definition: info.hh:101
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::ArmISA::s
Bitfield< 4 > s
Definition: misc_types.hh:561
gem5::statistics::display
const FlagsType display
Print this stat.
Definition: info.hh:58
debug.hh
cprintf.hh
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
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:60
gem5::GEM5_DEPRECATED_NAMESPACE
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
gem5::statistics::Vector2dInfo::y
size_type y
Definition: info.hh:235
name
const std::string & name()
Definition: trace.cc:49
gem5::statistics::debug_break_id
int debug_break_id
Definition: info.cc:63
gem5::statistics::NameMapType
std::map< std::string, Info * > NameMapType
Definition: info.hh:258
gem5::statistics::Info::setName
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
Definition: info.cc:128
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:203
gem5::statistics::VectorDistInfo::subdescs
std::vector< std::string > subdescs
Definition: info.hh:215
gem5::statistics::nameMap
NameMapType & nameMap()
Definition: info.cc:66
gem5::statistics::StorageParams
Definition: storage.hh:49
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:147
gem5::PowerISA::vec
Bitfield< 25 > vec
Definition: misc.hh:108
gem5::statistics::Vector2dInfo::x
size_type x
Definition: info.hh:234
logging.hh
gem5::statistics::VectorDistInfo::enable
void enable()
Enable the stat for use.
Definition: info.cc:210
gem5::statistics::Info::setStorageParams
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition: info.cc:91
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:56
gem5::statistics::validateStatName
bool validateStatName(const std::string &name)
Definition: info.cc:97
gem5::statistics::Info::separatorString
static std::string separatorString
The separator string used for vectors, dist, etc.
Definition: info.hh:86
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::statistics::Info::getStorageParams
StorageParams const * getStorageParams() const
Getter for the storage params.
Definition: info.cc:85
gem5::statistics::Vector2dInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:230
gem5::statistics::VectorInfo::subnames
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:188
gem5::statistics::Info::Info
Info()
Definition: info.cc:72
gem5::statistics::Info::name
std::string name
The name of the stat.
Definition: info.hh:84
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:177
gem5::statistics::Info
Definition: info.hh:80
gem5::statistics::Info::~Info
virtual ~Info()
Definition: info.cc:80

Generated on Tue Sep 21 2021 12:24:58 for gem5 by doxygen 1.8.17