gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
52namespace gem5
53{
54
55namespace statistics
56{
57
58std::string Info::separatorString = "::";
59
60int Info::id_count = 0;
61
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
83StorageParams const*
85{
86 return storageParams.get();
87}
88
89void
91{
92 return storageParams.reset(params);
93}
94
95bool
96validateStatName(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
126void
127Info::setName(const std::string &name, bool old_style)
128{
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
145bool
146Info::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
171bool
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
191void
193{
194}
195
196void
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
206void
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
216void
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
void setName(const std::string &name, bool old_style=true)
Set the name of this statistic.
Definition info.cc:127
std::unique_ptr< const StorageParams > storageParams
Definition info.hh:104
virtual ~Info()
Definition info.cc:79
Flags flags
The formatting flags.
Definition info.hh:91
StorageParams const * getStorageParams() const
Getter for the storage params.
Definition info.cc:84
virtual void enable()
Enable the stat for use.
Definition info.cc:192
void setStorageParams(const StorageParams *const params)
Setter for the storage params.
Definition info.cc:90
std::string name
The name of the stat.
Definition info.hh:83
static int id_count
A unique stat ID for each stat in the simulator.
Definition info.hh:100
static std::string separatorString
The separator string used for vectors, dist, etc.
Definition info.hh:85
bool baseCheck() const
Definition info.cc:172
static bool less(Info *stat1, Info *stat2)
Checks if the first stat's name is alphabetically less than the second.
Definition info.cc:146
void enable()
Enable the stat for use.
Definition info.cc:217
std::vector< std::string > subdescs
Definition info.hh:230
std::vector< std::string > y_subnames
Definition info.hh:231
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition info.hh:229
virtual size_type size() const =0
void enable()
Enable the stat for use.
Definition info.cc:207
std::vector< std::string > subdescs
Definition info.hh:214
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition info.hh:213
void enable()
Enable the stat for use.
Definition info.cc:197
virtual size_type size() const =0
std::vector< std::string > subdescs
Definition info.hh:188
std::vector< std::string > subnames
Names and descriptions of subfields.
Definition info.hh:187
STL vector class.
Definition stl.hh:37
#define panic(...)
This implements a cprintf based panic() function.
Definition logging.hh:188
#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
uint8_t flags
Definition helpers.cc:87
Bitfield< 4 > s
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 0 > p
Bitfield< 25 > vec
Definition misc.hh:113
void breakpoint()
Definition debug.cc:64
unsigned int size_type
Definition types.hh:59
const FlagsType init
This Stat is Initialized.
Definition info.hh:55
NameMapType & nameMap()
Definition info.cc:65
int debug_break_id
Definition info.cc:62
std::map< std::string, Info * > NameMapType
Definition info.hh:257
unsigned int off_type
Definition types.hh:60
const FlagsType display
Print this stat.
Definition info.hh:57
bool validateStatName(const std::string &name)
Definition info.cc:96
const FlagsType none
Nothing extra to print.
Definition info.hh:53
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
void tokenize(std::vector< std::string > &v, const std::string &s, char token, bool ignore)
Definition str.cc:68
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:01 for gem5 by doxygen 1.11.0