64 std::string Info::separatorString =
"::";
86 "shouldn't register stat twice!");
100 statsMap().insert(make_pair(
this, info));
101 assert(result.second &&
"this should never fail");
108 info()->storageParams = params;
112 InfoAccess::setInit()
114 info()->flags.set(
init);
125 MapType::const_iterator
i =
statsMap().find(
this);
132 InfoAccess::info()
const 139 MapType::const_iterator
i =
statsMap().find(
this);
145 StorageParams::~StorageParams()
156 int Info::id_count = 0;
161 : flags(
none), precision(-1), prereq(0), storageParams(NULL)
164 if (debug_break_id >= 0 and debug_break_id ==
id)
181 while (item != vec.end()) {
185 string::const_iterator
c = item->begin();
188 if (!isalpha(*c) && *c !=
'_')
192 while (++c != item->end()) {
193 if (!isalnum(*c) && *c !=
'_')
213 panic(
"invalid stat name '%s'", name);
220 auto p =
nameMap().insert(make_pair(name,
this));
223 panic(
"same statistic name used twice! name=%s\n",
233 const string &name1 = stat1->
name;
234 const string &name2 = stat2->
name;
242 size_type last = min(v1.size(), v2.size()) - 1;
245 return v1[
i] < v2[
i];
248 if (v1[last] == v2[last])
249 return v1.size() < v2.size();
251 return v1[last] < v2[last];
261 cprintf(
"this is stat number %d\n",
id);
263 panic(
"Not all stats have been initialized.\n" 264 "You may need to add <ParentClass>::regStats() to a" 265 " new SimObject's regStats() function. Name: %s",
271 panic(
"all printable stats must be named");
287 if (subnames.size() <
s)
289 if (subdescs.size() <
s)
297 if (subnames.size() <
s)
299 if (subdescs.size() <
s)
306 if (subnames.size() <
x)
308 if (subdescs.size() <
x)
310 if (y_subnames.size() < y)
311 y_subnames.resize(y);
317 int size = cvec.size();
319 int top_half = zero + (size - zero + 1) / 2;
320 int bottom_half = (size -
zero) / 2;
323 int low_pair = zero - 1;
324 for (
int i = zero - 1;
i >= bottom_half;
i--) {
325 cvec[
i] = cvec[low_pair];
326 if (low_pair - 1 >= 0)
327 cvec[
i] += cvec[low_pair - 1];
330 assert(low_pair == 0 || low_pair == -1 || low_pair == -2);
332 for (
int i = bottom_half - 1;
i >= 0;
i--)
336 int high_pair =
zero;
337 for (
int i = zero;
i < top_half;
i++) {
338 cvec[
i] = cvec[high_pair];
339 if (high_pair + 1 < size)
340 cvec[
i] += cvec[high_pair + 1];
343 assert(high_pair == size || high_pair == size + 1);
345 for (
int i = top_half;
i < size;
i++)
356 int size = cvec.size();
357 int half = (size + 1) / 2;
361 for (
int i = size - 1;
i >= half; --
i) {
362 cvec[
i] = cvec[pair];
364 cvec[
i] += cvec[pair - 1];
368 for (
int i = half - 1;
i >= 0;
i--)
371 min_bucket = -max_bucket;
378 int size = cvec.size();
379 int half = (size + 1) / 2;
382 for (
int i = 0;
i < half;
i++) {
383 cvec[
i] = cvec[pair];
385 cvec[
i] += cvec[pair + 1];
388 assert(pair == size || pair == size + 1);
390 for (
int i = half;
i < size;
i++)
400 int b_size = hs->
size();
401 assert(size() == b_size);
411 while (bucket_size < hs->bucket_size)
414 for (uint32_t
i = 0;
i < b_size;
i++)
436 assert(!
root &&
"Can't change formulas");
472 vec =
root->result();
518 resetHandler = reset_handler;
519 dumpHandler = dump_handler;
555 fatal(
"Stats are already enabled");
566 fatal(
"No registered Stats::dump handler");
575 fatal(
"No registered Stats::reset handler");
#define panic(...)
This implements a cprintf based panic() function.
double Result
All results are doubles.
Counter samples
The number of samples.
std::string name
The name of the stat.
static int id_count
A unique stat ID for each stat in the simulator.
void enable()
Enable the stat for use.
void processDumpQueue()
Process all the callbacks in the dump callbacks queue.
#define fatal(...)
This implements a cprintf based fatal() function.
virtual bool zero() const =0
NodePtr getNodePtr() const
Makde gcc < 4.6.3 happy and explicitly get the underlying node.
void process()
process all callbacks
VCounter cvec
Counter for each bucket.
void(* Handler)()
Register reset and dump handlers.
virtual void enable()
Enable the stat for use.
Overload hash function for BasicBlockRange type.
list< Info * > & statsList()
Counter logs
The sum of logarithm of each sample, used to compute geometric mean.
void enable()
Enable the stat for use.
Counter squares
The sum of squares.
Counter min_bucket
The minimum value to track.
Declaration of Statistics objects.
double Counter
All counters are of 64-bit values.
void add(Callback *callback)
Add a callback to the end of the queue.
Templatized storage and interface for a histogram stat.
static bool less(Info *stat1, Info *stat2)
Checks if the first stat's name is alphabetically less than the second.
Counter sum
The current sum.
std::shared_ptr< Node > NodePtr
Shared pointer to a function Node.
Flags flags
The formatting flags.
void registerResetCallback(Callback *cb)
Register a callback that should be called whenever statistics are reset.
void setName(const std::string &name)
Set the name of this statistic.
const FlagsType display
Print this stat.
const FlagsType none
Nothing extra to print.
std::map< const void *, Info * > MapType
void enable()
Enable the stat for use.
Counter bucket_size
The number of entries in each bucket.
Helper class to construct formula node trees.
void registerDumpCallback(Callback *cb)
Register a callback that should be called whenever statistics are about to be dumped.
void setInit()
Save Storage class parameters if any.
void processResetQueue()
Process all the callbacks in the reset callbacks queue.
bool validateStatName(const string &name)
void tokenize(vector< string > &v, const string &s, char token, bool ignore)
size_type size() const
Return the number of buckets in this distribution.
Formula & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
void dump()
Dump all statistics data to the registered outputs.
std::map< std::string, Info * > NameMapType
void registerHandlers(Handler reset_handler, Handler dump_handler)
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
const FlagsType init
This Stat is Initialized.
void cprintf(const char *format, const Args &...args)
std::string desc
The description of the stat.