2 * Copyright (c) 2021 Daniel R. Carvalho
3 * Copyright (c) 2019 Arm Limited
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.
15 * Copyright (c) 2003-2005 The Regents of The University of Michigan
16 * All rights reserved.
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.
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.
42 #include "base/stats/info.hh"
48 #include "base/cprintf.hh"
49 #include "base/debug.hh"
50 #include "base/logging.hh"
51 #include "base/str.hh"
55 std::string
Info::separatorString
= "::";
57 int Info::id_count
= 0;
59 int debug_break_id
= -1;
64 static NameMapType the_map
;
69 : flags(none
), precision(-1), prereq(0), storageParams(NULL
)
72 if (debug_break_id
>= 0 and debug_break_id
== id
)
81 validateStatName(const std::string
&name
)
86 std::vector
<std::string
> vec
;
87 tokenize(vec
, name
, '.');
88 std::vector
<std::string
>::const_iterator item
= vec
.begin();
89 while (item
!= vec
.end()) {
93 std::string::const_iterator c
= item
->begin();
95 // The first character is different
96 if (!isalpha(*c
) && *c
!= '_')
99 // The rest of the characters have different rules.
100 while (++c
!= item
->end()) {
101 if (!isalnum(*c
) && *c
!= '_')
112 Info::setName(const std::string
&name
)
114 setName(nullptr, name
);
118 Info::setName(const Group
*parent
, const std::string
&name
)
120 if (!validateStatName(name
))
121 panic("invalid stat name '%s'", name
);
123 // We only register the stat with the nameMap() if we are using
124 // old-style stats without a parent group. New-style stats should
125 // be unique since their names should correspond to a member
128 auto p
= nameMap().insert(make_pair(name
, this));
131 panic("same statistic name used twice! name=%s\n",
139 Info::less(Info
*stat1
, Info
*stat2
)
141 const std::string
&name1
= stat1
->name
;
142 const std::string
&name2
= stat2
->name
;
144 std::vector
<std::string
> v1
;
145 std::vector
<std::string
> v2
;
147 tokenize(v1
, name1
, '.');
148 tokenize(v2
, name2
, '.');
150 size_type last
= std::min(v1
.size(), v2
.size()) - 1;
151 for (off_type i
= 0; i
< last
; ++i
)
153 return v1
[i
] < v2
[i
];
155 // Special compare for last element.
156 if (v1
[last
] == v2
[last
])
157 return v1
.size() < v2
.size();
159 return v1
[last
] < v2
[last
];
165 Info::baseCheck() const
167 if (!(flags
& Stats::init
)) {
169 cprintf("this is stat number %d\n", id
);
171 panic("Not all stats have been initialized.\n"
172 "You may need to add <ParentClass>::regStats() to a"
173 " new SimObject's regStats() function. Name: %s",
178 if ((flags
& display
) && name
.empty()) {
179 panic("all printable stats must be named");
194 size_type s
= size();
195 if (subnames
.size() < s
)
197 if (subdescs
.size() < s
)
202 VectorDistInfo::enable()
204 size_type s
= size();
205 if (subnames
.size() < s
)
207 if (subdescs
.size() < s
)
212 Vector2dInfo::enable()
214 if (subnames
.size() < x
)
216 if (subdescs
.size() < x
)
218 if (y_subnames
.size() < y
)
219 y_subnames
.resize(y
);