gem5  v22.1.0.0
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
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
Definition: info.cc:128
std::unique_ptr< const StorageParams > storageParams
Definition: info.hh:105
virtual ~Info()
Definition: info.cc:80
Flags flags
The formatting flags.
Definition: info.hh:92
StorageParams const * getStorageParams() const
Getter for the storage params.
Definition: info.cc:85
virtual void enable()
Enable the stat for use.
Definition: info.cc:195
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition: info.cc:91
std::string name
The name of the stat.
Definition: info.hh:84
static int id_count
A unique stat ID for each stat in the simulator.
Definition: info.hh:101
static std::string separatorString
The separator string used for vectors, dist, etc.
Definition: info.hh:86
bool baseCheck() const
Definition: info.cc:173
static bool less(Info *stat1, Info *stat2)
Checks if the first stat's name is alphabetically less than the second.
Definition: info.cc:147
void enable()
Enable the stat for use.
Definition: info.cc:220
std::vector< std::string > subdescs
Definition: info.hh:231
std::vector< std::string > y_subnames
Definition: info.hh:232
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:230
virtual size_type size() const =0
void enable()
Enable the stat for use.
Definition: info.cc:210
std::vector< std::string > subdescs
Definition: info.hh:215
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:214
void enable()
Enable the stat for use.
Definition: info.cc:200
virtual size_type size() const =0
std::vector< std::string > subdescs
Definition: info.hh:189
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition: info.hh:188
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:204
uint8_t flags
Definition: helpers.cc:66
Bitfield< 7 > i
Definition: misc_types.hh:67
Bitfield< 25 > vec
Definition: misc.hh:113
Bitfield< 1 > s
Definition: pagetable.hh:64
Bitfield< 2 > c
Definition: pagetable.hh:63
Bitfield< 54 > p
Definition: pagetable.hh:70
void breakpoint()
Definition: debug.cc:65
unsigned int size_type
Definition: types.hh:60
const FlagsType init
This Stat is Initialized.
Definition: info.hh:56
NameMapType & nameMap()
Definition: info.cc:66
int debug_break_id
Definition: info.cc:63
std::map< std::string, Info * > NameMapType
Definition: info.hh:258
unsigned int off_type
Definition: types.hh:61
const FlagsType display
Print this stat.
Definition: info.hh:58
bool validateStatName(const std::string &name)
Definition: info.cc:97
const FlagsType none
Nothing extra to print.
Definition: info.hh:54
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
void tokenize(std::vector< std::string > &v, const std::string &s, char token, bool ignore)
Definition: str.cc:68
void cprintf(const char *format, const Args &...args)
Definition: cprintf.hh:155
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
const std::string & name()
Definition: trace.cc:49

Generated on Wed Dec 21 2022 10:22:29 for gem5 by doxygen 1.9.1