2 * Copyright (c) 2019-2020 Arm Limited
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
14 * Copyright (c) 2003-2005 The Regents of The University of Michigan
15 * All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include "base/statistics.hh"
49 #include "base/callback.hh"
50 #include "base/logging.hh"
51 #include "sim/root.hh"
55 // We wrap these in a function to make sure they're built in time.
59 static std::list
<Info
*> the_list
;
66 static MapType the_map
;
71 InfoAccess::setInfo(Group
*parent
, Info
*info
)
73 panic_if(statsMap().find(this) != statsMap().end() ||
75 "shouldn't register stat twice!");
77 // New-style stats are reachable through the hierarchy and
78 // shouldn't be added to the global lists.
84 statsList().push_back(info
);
87 std::pair
<MapType::iterator
, bool> result
=
89 statsMap().insert(std::make_pair(this, info
));
90 assert(result
.second
&& "this should never fail");
91 assert(statsMap().find(this) != statsMap().end());
95 InfoAccess::setParams(const StorageParams
*params
)
97 info()->storageParams
= params
;
101 InfoAccess::setInit()
103 info()->flags
.set(init
);
114 MapType::const_iterator i
= statsMap().find(this);
115 assert(i
!= statsMap().end());
121 InfoAccess::info() const
128 MapType::const_iterator i
= statsMap().find(this);
129 assert(i
!= statsMap().end());
134 Formula::Formula(Group
*parent
, const char *name
, const char *desc
)
135 : DataWrapVec
<Formula
, FormulaInfoProxy
>(parent
, name
, desc
)
142 Formula::Formula(Group
*parent
, const char *name
, const char *desc
,
144 : DataWrapVec
<Formula
, FormulaInfoProxy
>(parent
, name
, desc
)
150 Formula::operator=(const Temp
&r
)
152 assert(!root
&& "Can't change formulas");
153 root
= r
.getNodePtr();
160 Formula::operator+=(Temp r
)
163 root
= NodePtr(new BinaryNode
<std::plus
<Result
> >(root
, r
));
165 root
= r
.getNodePtr();
174 Formula::operator/=(Temp r
)
177 root
= NodePtr(new BinaryNode
<std::divides
<Result
> >(root
, r
));
185 Formula::result(VResult
&vec
) const
188 vec
= root
->result();
192 Formula::total() const
194 return root
? root
->total() : 0.0;
198 Formula::size() const
212 Formula::zero() const
216 for (VResult::size_type i
= 0; i
< vec
.size(); ++i
)
225 return root
? root
->str() : "";
228 Handler resetHandler
= NULL
;
229 Handler dumpHandler
= NULL
;
232 registerHandlers(Handler reset_handler
, Handler dump_handler
)
234 resetHandler
= reset_handler
;
235 dumpHandler
= dump_handler
;
238 CallbackQueue dumpQueue
;
239 CallbackQueue resetQueue
;
244 resetQueue
.process();
254 registerResetCallback(const std::function
<void()> &callback
)
256 resetQueue
.push_back(callback
);
259 bool _enabled
= false;
271 fatal("Stats are already enabled");
282 fatal("No registered Stats::dump handler");
291 fatal("No registered Stats::reset handler");
295 resolve(const std::string
&name
)
297 const auto &it
= nameMap().find(name
);
298 if (it
!= nameMap().cend()) {
301 return Root::root()->resolveStat(name
);
306 registerDumpCallback(const std::function
<void()> &callback
)
308 dumpQueue
.push_back(callback
);