2004-05-04 23:01:00 +02:00
|
|
|
/*
|
2005-06-05 11:16:00 +02:00
|
|
|
* Copyright (c) 2004-2005 The Regents of The University of Michigan
|
2004-05-04 23:01:00 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met: redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer;
|
|
|
|
* redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution;
|
|
|
|
* neither the name of the copyright holders nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2006-06-01 01:26:56 +02:00
|
|
|
*
|
|
|
|
* Authors: Nathan Binkert
|
2004-05-04 23:01:00 +02:00
|
|
|
*/
|
|
|
|
|
2004-06-21 06:58:30 +02:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
#define _GLIBCPP_USE_C99 1
|
|
|
|
#endif
|
|
|
|
|
2007-01-27 00:48:51 +01:00
|
|
|
#if defined(__sun)
|
2011-04-15 19:44:14 +02:00
|
|
|
#include <math.h>
|
2007-01-27 00:48:51 +01:00
|
|
|
#endif
|
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
#include <cassert>
|
|
|
|
#ifdef __SUNPRO_CC
|
2011-04-15 19:44:14 +02:00
|
|
|
#include <math.h>
|
2009-04-22 22:38:00 +02:00
|
|
|
#endif
|
|
|
|
#include <cmath>
|
2011-04-15 19:44:06 +02:00
|
|
|
#include <fstream>
|
2004-05-04 23:01:00 +02:00
|
|
|
#include <iostream>
|
2006-05-16 02:06:42 +02:00
|
|
|
#include <sstream>
|
2004-05-04 23:01:00 +02:00
|
|
|
#include <string>
|
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
#include "base/stats/info.hh"
|
2004-05-04 23:01:00 +02:00
|
|
|
#include "base/stats/text.hh"
|
2011-04-15 19:44:06 +02:00
|
|
|
#include "base/cast.hh"
|
|
|
|
#include "base/misc.hh"
|
|
|
|
#include "base/str.hh"
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#ifndef NAN
|
|
|
|
float __nan();
|
|
|
|
/** Define Not a number. */
|
|
|
|
#define NAN (__nan())
|
|
|
|
/** Need to define __nan() */
|
|
|
|
#define __M5_NAN
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __M5_NAN
|
|
|
|
float
|
|
|
|
__nan()
|
|
|
|
{
|
|
|
|
union {
|
|
|
|
uint32_t ui;
|
|
|
|
float f;
|
|
|
|
} nan;
|
|
|
|
|
|
|
|
nan.ui = 0x7fc00000;
|
|
|
|
return nan.f;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-05-21 19:39:20 +02:00
|
|
|
namespace Stats {
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
std::list<Info *> &statsList();
|
|
|
|
|
2004-05-04 23:01:00 +02:00
|
|
|
Text::Text()
|
2009-04-22 19:25:14 +02:00
|
|
|
: mystream(false), stream(NULL), descriptions(false)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Text::Text(std::ostream &stream)
|
2009-04-22 19:25:14 +02:00
|
|
|
: mystream(false), stream(NULL), descriptions(false)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
|
|
|
open(stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
Text::Text(const std::string &file)
|
2009-04-22 19:25:14 +02:00
|
|
|
: mystream(false), stream(NULL), descriptions(false)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
|
|
|
open(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Text::~Text()
|
|
|
|
{
|
|
|
|
if (mystream) {
|
|
|
|
assert(stream);
|
|
|
|
delete stream;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Text::open(std::ostream &_stream)
|
|
|
|
{
|
|
|
|
if (stream)
|
|
|
|
panic("stream already set!");
|
|
|
|
|
|
|
|
mystream = false;
|
|
|
|
stream = &_stream;
|
2008-10-02 18:46:57 +02:00
|
|
|
if (!valid())
|
|
|
|
fatal("Unable to open output stream for writing\n");
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Text::open(const std::string &file)
|
|
|
|
{
|
|
|
|
if (stream)
|
|
|
|
panic("stream already set!");
|
|
|
|
|
|
|
|
mystream = true;
|
|
|
|
stream = new ofstream(file.c_str(), ios::trunc);
|
2008-10-02 18:46:57 +02:00
|
|
|
if (!valid())
|
|
|
|
fatal("Unable to open statistics file for writing\n");
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
Text::valid() const
|
|
|
|
{
|
2008-10-02 18:46:57 +02:00
|
|
|
return stream != NULL && stream->good();
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-05-12 20:19:35 +02:00
|
|
|
Text::begin()
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
|
|
|
ccprintf(*stream, "\n---------- Begin Simulation Statistics ----------\n");
|
2011-05-12 20:19:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Text::end()
|
|
|
|
{
|
2004-05-04 23:01:00 +02:00
|
|
|
ccprintf(*stream, "\n---------- End Simulation Statistics ----------\n");
|
|
|
|
stream->flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2009-02-23 21:22:15 +01:00
|
|
|
Text::noOutput(const Info &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2010-06-15 17:34:19 +02:00
|
|
|
if (!info.flags.isSet(display))
|
2004-05-04 23:01:00 +02:00
|
|
|
return true;
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
if (info.prereq && info.prereq->zero())
|
2004-05-04 23:01:00 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
string
|
2009-04-22 19:25:14 +02:00
|
|
|
ValueToString(Result value, int precision)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
|
|
|
stringstream val;
|
|
|
|
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
if (!std::isnan(value)) {
|
2004-05-04 23:01:00 +02:00
|
|
|
if (precision != -1)
|
|
|
|
val.precision(precision);
|
|
|
|
else if (value == rint(value))
|
|
|
|
val.precision(0);
|
|
|
|
|
|
|
|
val.unsetf(ios::showpoint);
|
|
|
|
val.setf(ios::fixed);
|
|
|
|
val << value;
|
|
|
|
} else {
|
2012-05-09 20:51:42 +02:00
|
|
|
val << "nan";
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return val.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ScalarPrint
|
|
|
|
{
|
|
|
|
Result value;
|
|
|
|
string name;
|
|
|
|
string desc;
|
2009-04-22 22:38:01 +02:00
|
|
|
Flags flags;
|
2004-05-04 23:01:00 +02:00
|
|
|
bool descriptions;
|
|
|
|
int precision;
|
|
|
|
Result pdf;
|
|
|
|
Result cdf;
|
|
|
|
|
2009-05-13 16:18:01 +02:00
|
|
|
void update(Result val, Result total);
|
2013-06-09 14:29:57 +02:00
|
|
|
void operator()(ostream &stream, bool oneLine = false) const;
|
2004-05-04 23:01:00 +02:00
|
|
|
};
|
|
|
|
|
2009-05-13 16:18:01 +02:00
|
|
|
void
|
|
|
|
ScalarPrint::update(Result val, Result total)
|
|
|
|
{
|
|
|
|
value = val;
|
|
|
|
if (total) {
|
|
|
|
pdf = val / total;
|
|
|
|
cdf += pdf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-05-04 23:01:00 +02:00
|
|
|
void
|
2013-06-09 14:29:57 +02:00
|
|
|
ScalarPrint::operator()(ostream &stream, bool oneLine) const
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2014-01-10 23:19:40 +01:00
|
|
|
if ((flags.isSet(nozero) && (!oneLine) && value == 0.0) ||
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
(flags.isSet(nonan) && std::isnan(value)))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
stringstream pdfstr, cdfstr;
|
|
|
|
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
if (!std::isnan(pdf))
|
2004-05-04 23:01:00 +02:00
|
|
|
ccprintf(pdfstr, "%.2f%%", pdf * 100.0);
|
|
|
|
|
clang/gcc: Fix compilation issues with clang 3.0 and gcc 4.6
This patch addresses a number of minor issues that cause problems when
compiling with clang >= 3.0 and gcc >= 4.6. Most importantly, it
avoids using the deprecated ext/hash_map and instead uses
unordered_map (and similarly so for the hash_set). To make use of the
new STL containers, g++ and clang has to be invoked with "-std=c++0x",
and this is now added for all gcc versions >= 4.6, and for clang >=
3.0. For gcc >= 4.3 and <= 4.5 and clang <= 3.0 we use the tr1
unordered_map to avoid the deprecation warning.
The addition of c++0x in turn causes a few problems, as the
compiler is more stringent and adds a number of new warnings. Below,
the most important issues are enumerated:
1) the use of namespaces is more strict, e.g. for isnan, and all
headers opening the entire namespace std are now fixed.
2) another other issue caused by the more stringent compiler is the
narrowing of the embedded python, which used to be a char array,
and is now unsigned char since there were values larger than 128.
3) a particularly odd issue that arose with the new c++0x behaviour is
found in range.hh, where the operator< causes gcc to complain about
the template type parsing (the "<" is interpreted as the beginning
of a template argument), and the problem seems to be related to the
begin/end members introduced for the range-type iteration, which is
a new feature in c++11.
As a minor update, this patch also fixes the build flags for the clang
debug target that used to be shared with gcc and incorrectly use
"-ggdb".
2012-04-14 11:43:31 +02:00
|
|
|
if (!std::isnan(cdf))
|
2004-05-04 23:01:00 +02:00
|
|
|
ccprintf(cdfstr, "%.2f%%", cdf * 100.0);
|
|
|
|
|
2013-06-09 14:29:57 +02:00
|
|
|
if (oneLine) {
|
|
|
|
ccprintf(stream, " |%12s %10s %10s",
|
|
|
|
ValueToString(value, precision), pdfstr.str(), cdfstr.str());
|
|
|
|
} else {
|
|
|
|
ccprintf(stream, "%-40s %12s %10s %10s", name,
|
|
|
|
ValueToString(value, precision), pdfstr.str(), cdfstr.str());
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2013-06-09 14:29:57 +02:00
|
|
|
if (descriptions) {
|
|
|
|
if (!desc.empty())
|
|
|
|
ccprintf(stream, " # %s", desc);
|
|
|
|
}
|
|
|
|
stream << endl;
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct VectorPrint
|
|
|
|
{
|
|
|
|
string name;
|
2011-04-20 20:14:52 +02:00
|
|
|
string separatorString;
|
2004-05-04 23:01:00 +02:00
|
|
|
string desc;
|
|
|
|
vector<string> subnames;
|
|
|
|
vector<string> subdescs;
|
2009-04-22 22:38:01 +02:00
|
|
|
Flags flags;
|
2004-05-04 23:01:00 +02:00
|
|
|
bool descriptions;
|
|
|
|
int precision;
|
|
|
|
VResult vec;
|
|
|
|
Result total;
|
2013-08-20 17:21:26 +02:00
|
|
|
bool forceSubnames;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
void operator()(ostream &stream) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
VectorPrint::operator()(std::ostream &stream) const
|
|
|
|
{
|
2008-10-09 13:58:23 +02:00
|
|
|
size_type _size = vec.size();
|
2004-05-04 23:01:00 +02:00
|
|
|
Result _total = 0.0;
|
|
|
|
|
2009-04-22 22:38:01 +02:00
|
|
|
if (flags.isSet(pdf | cdf)) {
|
2008-10-09 13:58:23 +02:00
|
|
|
for (off_type i = 0; i < _size; ++i) {
|
2004-05-04 23:01:00 +02:00
|
|
|
_total += vec[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 20:14:52 +02:00
|
|
|
string base = name + separatorString;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
ScalarPrint print;
|
|
|
|
print.name = name;
|
|
|
|
print.desc = desc;
|
|
|
|
print.precision = precision;
|
|
|
|
print.descriptions = descriptions;
|
|
|
|
print.flags = flags;
|
2009-05-13 16:18:01 +02:00
|
|
|
print.pdf = _total ? 0.0 : NAN;
|
|
|
|
print.cdf = _total ? 0.0 : NAN;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
bool havesub = !subnames.empty();
|
|
|
|
|
|
|
|
if (_size == 1) {
|
2013-08-19 09:52:29 +02:00
|
|
|
// If forceSubnames is set, get the first subname (or index in
|
|
|
|
// the case where there are no subnames) and append it to the
|
|
|
|
// base name.
|
|
|
|
if (forceSubnames)
|
2014-09-20 23:17:49 +02:00
|
|
|
print.name = base + (havesub ? subnames[0] : std::to_string(0));
|
2004-05-04 23:01:00 +02:00
|
|
|
print.value = vec[0];
|
|
|
|
print(stream);
|
2009-04-22 19:25:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2013-06-09 14:29:57 +02:00
|
|
|
if ((!flags.isSet(nozero)) || (total != 0)) {
|
|
|
|
if (flags.isSet(oneline)) {
|
|
|
|
ccprintf(stream, "%-40s", name);
|
|
|
|
print.flags = print.flags & (~nozero);
|
|
|
|
}
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2013-06-09 14:29:57 +02:00
|
|
|
for (off_type i = 0; i < _size; ++i) {
|
|
|
|
if (havesub && (i >= subnames.size() || subnames[i].empty()))
|
|
|
|
continue;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2014-09-20 23:17:49 +02:00
|
|
|
print.name = base + (havesub ? subnames[i] : std::to_string(i));
|
2013-06-09 14:29:57 +02:00
|
|
|
print.desc = subdescs.empty() ? desc : subdescs[i];
|
|
|
|
|
|
|
|
print.update(vec[i], _total);
|
|
|
|
print(stream, flags.isSet(oneline));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.isSet(oneline)) {
|
|
|
|
if (descriptions) {
|
|
|
|
if (!desc.empty())
|
|
|
|
ccprintf(stream, " # %s", desc);
|
|
|
|
}
|
|
|
|
stream << endl;
|
|
|
|
}
|
2009-04-22 19:25:14 +02:00
|
|
|
}
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-04-22 22:38:01 +02:00
|
|
|
if (flags.isSet(::Stats::total)) {
|
2009-04-22 19:25:14 +02:00
|
|
|
print.pdf = NAN;
|
|
|
|
print.cdf = NAN;
|
|
|
|
print.name = base + "total";
|
|
|
|
print.desc = desc;
|
|
|
|
print.value = total;
|
|
|
|
print(stream);
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct DistPrint
|
|
|
|
{
|
|
|
|
string name;
|
2011-04-20 20:14:52 +02:00
|
|
|
string separatorString;
|
2004-05-04 23:01:00 +02:00
|
|
|
string desc;
|
2009-04-22 22:38:01 +02:00
|
|
|
Flags flags;
|
2004-05-04 23:01:00 +02:00
|
|
|
bool descriptions;
|
|
|
|
int precision;
|
|
|
|
|
2009-03-07 23:30:53 +01:00
|
|
|
const DistData &data;
|
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
DistPrint(const Text *text, const DistInfo &info);
|
|
|
|
DistPrint(const Text *text, const VectorDistInfo &info, int i);
|
2010-07-22 03:54:53 +02:00
|
|
|
void init(const Text *text, const Info &info);
|
2004-05-04 23:01:00 +02:00
|
|
|
void operator()(ostream &stream) const;
|
|
|
|
};
|
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
DistPrint::DistPrint(const Text *text, const DistInfo &info)
|
2009-03-07 23:30:53 +01:00
|
|
|
: data(info.data)
|
|
|
|
{
|
2010-07-22 03:54:53 +02:00
|
|
|
init(text, info);
|
2009-03-07 23:30:53 +01:00
|
|
|
}
|
|
|
|
|
2009-04-22 22:38:00 +02:00
|
|
|
DistPrint::DistPrint(const Text *text, const VectorDistInfo &info, int i)
|
2009-03-07 23:30:53 +01:00
|
|
|
: data(info.data[i])
|
|
|
|
{
|
2010-07-22 03:54:53 +02:00
|
|
|
init(text, info);
|
2009-03-07 23:30:53 +01:00
|
|
|
|
|
|
|
name = info.name + "_" +
|
2014-09-20 23:17:49 +02:00
|
|
|
(info.subnames[i].empty() ? (std::to_string(i)) : info.subnames[i]);
|
2009-03-07 23:30:53 +01:00
|
|
|
|
|
|
|
if (!info.subdescs[i].empty())
|
|
|
|
desc = info.subdescs[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-07-22 03:54:53 +02:00
|
|
|
DistPrint::init(const Text *text, const Info &info)
|
2009-03-07 23:30:53 +01:00
|
|
|
{
|
|
|
|
name = info.name;
|
2011-04-20 20:14:52 +02:00
|
|
|
separatorString = info.separatorString;
|
2009-03-07 23:30:53 +01:00
|
|
|
desc = info.desc;
|
|
|
|
flags = info.flags;
|
|
|
|
precision = info.precision;
|
2009-04-22 15:44:29 +02:00
|
|
|
descriptions = text->descriptions;
|
2009-03-07 23:30:53 +01:00
|
|
|
}
|
|
|
|
|
2004-05-04 23:01:00 +02:00
|
|
|
void
|
|
|
|
DistPrint::operator()(ostream &stream) const
|
|
|
|
{
|
2014-01-10 23:19:40 +01:00
|
|
|
if (flags.isSet(nozero) && data.samples == 0) return;
|
2011-04-20 20:14:52 +02:00
|
|
|
string base = name + separatorString;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
ScalarPrint print;
|
2009-05-13 16:18:01 +02:00
|
|
|
print.precision = precision;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.flags = flags;
|
|
|
|
print.descriptions = descriptions;
|
2009-05-13 16:18:01 +02:00
|
|
|
print.desc = desc;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.pdf = NAN;
|
|
|
|
print.cdf = NAN;
|
|
|
|
|
2014-01-10 23:19:40 +01:00
|
|
|
if (flags.isSet(oneline)) {
|
|
|
|
print.name = base + "bucket_size";
|
|
|
|
print.value = data.bucket_size;
|
|
|
|
print(stream);
|
|
|
|
|
|
|
|
print.name = base + "min_bucket";
|
|
|
|
print.value = data.min;
|
|
|
|
print(stream);
|
|
|
|
|
|
|
|
print.name = base + "max_bucket";
|
|
|
|
print.value = data.max;
|
|
|
|
print(stream);
|
|
|
|
}
|
|
|
|
|
2004-05-04 23:01:00 +02:00
|
|
|
print.name = base + "samples";
|
2009-03-07 23:30:53 +01:00
|
|
|
print.value = data.samples;
|
2004-05-04 23:01:00 +02:00
|
|
|
print(stream);
|
|
|
|
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "mean";
|
|
|
|
print.value = data.samples ? data.sum / data.samples : NAN;
|
|
|
|
print(stream);
|
|
|
|
|
2012-01-10 01:08:20 +01:00
|
|
|
if (data.type == Hist) {
|
|
|
|
print.name = base + "gmean";
|
|
|
|
print.value = data.samples ? exp(data.logs / data.samples) : NAN;
|
|
|
|
print(stream);
|
|
|
|
}
|
|
|
|
|
2009-05-13 16:18:01 +02:00
|
|
|
Result stdev = NAN;
|
|
|
|
if (data.samples)
|
|
|
|
stdev = sqrt((data.samples * data.squares - data.sum * data.sum) /
|
|
|
|
(data.samples * (data.samples - 1.0)));
|
|
|
|
print.name = base + "stdev";
|
|
|
|
print.value = stdev;
|
2004-05-04 23:01:00 +02:00
|
|
|
print(stream);
|
|
|
|
|
2010-07-22 03:54:53 +02:00
|
|
|
if (data.type == Deviation)
|
2009-05-13 16:18:01 +02:00
|
|
|
return;
|
|
|
|
|
2010-07-22 03:54:53 +02:00
|
|
|
size_t size = data.cvec.size();
|
2009-05-13 16:18:01 +02:00
|
|
|
|
|
|
|
Result total = 0.0;
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.underflow != NAN)
|
2009-05-13 16:18:01 +02:00
|
|
|
total += data.underflow;
|
|
|
|
for (off_type i = 0; i < size; ++i)
|
|
|
|
total += data.cvec[i];
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.overflow != NAN)
|
2009-05-13 16:18:01 +02:00
|
|
|
total += data.overflow;
|
|
|
|
|
2009-04-22 19:25:14 +02:00
|
|
|
if (total) {
|
2009-05-13 16:18:01 +02:00
|
|
|
print.pdf = 0.0;
|
|
|
|
print.cdf = 0.0;
|
|
|
|
}
|
|
|
|
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.underflow != NAN) {
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "underflows";
|
|
|
|
print.update(data.underflow, total);
|
|
|
|
print(stream);
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
2014-01-10 23:19:40 +01:00
|
|
|
if (flags.isSet(oneline)) {
|
|
|
|
ccprintf(stream, "%-40s", name);
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:25:14 +02:00
|
|
|
for (off_type i = 0; i < size; ++i) {
|
|
|
|
stringstream namestr;
|
|
|
|
namestr << base;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2010-07-22 03:54:53 +02:00
|
|
|
Counter low = i * data.bucket_size + data.min;
|
|
|
|
Counter high = ::min(low + data.bucket_size - 1.0, data.max);
|
2009-04-22 19:25:14 +02:00
|
|
|
namestr << low;
|
|
|
|
if (low < high)
|
|
|
|
namestr << "-" << high;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-04-22 19:25:14 +02:00
|
|
|
print.name = namestr.str();
|
2009-05-13 16:18:01 +02:00
|
|
|
print.update(data.cvec[i], total);
|
2014-01-10 23:19:40 +01:00
|
|
|
print(stream, flags.isSet(oneline));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags.isSet(oneline)) {
|
|
|
|
if (descriptions) {
|
|
|
|
if (!desc.empty())
|
|
|
|
ccprintf(stream, " # %s", desc);
|
|
|
|
}
|
|
|
|
stream << endl;
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.overflow != NAN) {
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "overflows";
|
|
|
|
print.update(data.overflow, total);
|
|
|
|
print(stream);
|
2009-04-22 19:25:14 +02:00
|
|
|
}
|
|
|
|
|
2004-05-04 23:01:00 +02:00
|
|
|
print.pdf = NAN;
|
|
|
|
print.cdf = NAN;
|
|
|
|
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.min_val != NAN) {
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "min_value";
|
|
|
|
print.value = data.min_val;
|
|
|
|
print(stream);
|
|
|
|
}
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2011-01-10 20:11:17 +01:00
|
|
|
if (data.type == Dist && data.max_val != NAN) {
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "max_value";
|
|
|
|
print.value = data.max_val;
|
|
|
|
print(stream);
|
|
|
|
}
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-05-13 16:18:01 +02:00
|
|
|
print.name = base + "total";
|
|
|
|
print.value = total;
|
2009-04-22 19:25:14 +02:00
|
|
|
print(stream);
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const ScalarInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-02-23 21:22:15 +01:00
|
|
|
if (noOutput(info))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
ScalarPrint print;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.value = info.result();
|
|
|
|
print.name = info.name;
|
|
|
|
print.desc = info.desc;
|
|
|
|
print.flags = info.flags;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.descriptions = descriptions;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.precision = info.precision;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.pdf = NAN;
|
|
|
|
print.cdf = NAN;
|
|
|
|
|
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const VectorInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-02-23 21:22:15 +01:00
|
|
|
if (noOutput(info))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
size_type size = info.size();
|
2004-05-04 23:01:00 +02:00
|
|
|
VectorPrint print;
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
print.name = info.name;
|
2011-04-20 20:14:52 +02:00
|
|
|
print.separatorString = info.separatorString;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.desc = info.desc;
|
|
|
|
print.flags = info.flags;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.descriptions = descriptions;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.precision = info.precision;
|
|
|
|
print.vec = info.result();
|
|
|
|
print.total = info.total();
|
2013-08-20 17:21:26 +02:00
|
|
|
print.forceSubnames = false;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
if (!info.subnames.empty()) {
|
2008-10-09 13:58:23 +02:00
|
|
|
for (off_type i = 0; i < size; ++i) {
|
2009-02-23 21:22:15 +01:00
|
|
|
if (!info.subnames[i].empty()) {
|
|
|
|
print.subnames = info.subnames;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.subnames.resize(size);
|
2008-10-09 13:58:23 +02:00
|
|
|
for (off_type i = 0; i < size; ++i) {
|
2009-02-23 21:22:15 +01:00
|
|
|
if (!info.subnames[i].empty() &&
|
|
|
|
!info.subdescs[i].empty()) {
|
|
|
|
print.subdescs = info.subdescs;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.subdescs.resize(size);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const Vector2dInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-02-23 21:22:15 +01:00
|
|
|
if (noOutput(info))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
bool havesub = false;
|
|
|
|
VectorPrint print;
|
|
|
|
|
2012-01-10 01:08:20 +01:00
|
|
|
if (!info.y_subnames.empty()) {
|
|
|
|
for (off_type i = 0; i < info.y; ++i) {
|
|
|
|
if (!info.y_subnames[i].empty()) {
|
|
|
|
print.subnames = info.y_subnames;
|
2014-09-19 16:35:08 +02:00
|
|
|
break;
|
2012-01-10 01:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-23 21:22:15 +01:00
|
|
|
print.flags = info.flags;
|
2011-04-20 20:14:52 +02:00
|
|
|
print.separatorString = info.separatorString;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.descriptions = descriptions;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.precision = info.precision;
|
2013-08-19 09:52:29 +02:00
|
|
|
print.forceSubnames = true;
|
2004-05-04 23:01:00 +02:00
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
if (!info.subnames.empty()) {
|
|
|
|
for (off_type i = 0; i < info.x; ++i)
|
|
|
|
if (!info.subnames[i].empty())
|
2004-05-04 23:01:00 +02:00
|
|
|
havesub = true;
|
|
|
|
}
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
VResult tot_vec(info.y);
|
2013-08-19 09:52:29 +02:00
|
|
|
VResult super_total(1, 0.0);
|
2009-02-23 21:22:15 +01:00
|
|
|
for (off_type i = 0; i < info.x; ++i) {
|
|
|
|
if (havesub && (i >= info.subnames.size() || info.subnames[i].empty()))
|
2004-05-04 23:01:00 +02:00
|
|
|
continue;
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
off_type iy = i * info.y;
|
|
|
|
VResult yvec(info.y);
|
2004-05-04 23:01:00 +02:00
|
|
|
|
|
|
|
Result total = 0.0;
|
2009-02-23 21:22:15 +01:00
|
|
|
for (off_type j = 0; j < info.y; ++j) {
|
|
|
|
yvec[j] = info.cvec[iy + j];
|
2004-05-04 23:01:00 +02:00
|
|
|
tot_vec[j] += yvec[j];
|
|
|
|
total += yvec[j];
|
2013-08-19 09:52:29 +02:00
|
|
|
super_total[0] += yvec[j];
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
print.name = info.name + "_" +
|
2014-09-20 23:17:49 +02:00
|
|
|
(havesub ? info.subnames[i] : std::to_string(i));
|
2009-02-23 21:22:15 +01:00
|
|
|
print.desc = info.desc;
|
2004-05-04 23:01:00 +02:00
|
|
|
print.vec = yvec;
|
|
|
|
print.total = total;
|
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
|
2013-08-19 09:52:29 +02:00
|
|
|
// Create a subname for printing the total
|
|
|
|
vector<string> total_subname;
|
|
|
|
total_subname.push_back("total");
|
|
|
|
|
2009-04-22 22:38:01 +02:00
|
|
|
if (info.flags.isSet(::Stats::total) && (info.x > 1)) {
|
2009-02-23 21:22:15 +01:00
|
|
|
print.name = info.name;
|
2013-08-19 09:52:29 +02:00
|
|
|
print.subnames = total_subname;
|
2009-02-23 21:22:15 +01:00
|
|
|
print.desc = info.desc;
|
2013-08-19 09:52:29 +02:00
|
|
|
print.vec = super_total;
|
|
|
|
print.flags = print.flags & ~total;
|
2004-05-04 23:01:00 +02:00
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const DistInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-02-23 21:22:15 +01:00
|
|
|
if (noOutput(info))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
2009-04-22 15:44:29 +02:00
|
|
|
DistPrint print(this, info);
|
2004-05-04 23:01:00 +02:00
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const VectorDistInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-02-23 21:22:15 +01:00
|
|
|
if (noOutput(info))
|
2004-05-04 23:01:00 +02:00
|
|
|
return;
|
|
|
|
|
2009-02-23 21:22:15 +01:00
|
|
|
for (off_type i = 0; i < info.size(); ++i) {
|
2009-04-22 15:44:29 +02:00
|
|
|
DistPrint print(this, info, i);
|
2004-05-04 23:01:00 +02:00
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-04-22 22:38:00 +02:00
|
|
|
Text::visit(const FormulaInfo &info)
|
2004-05-04 23:01:00 +02:00
|
|
|
{
|
2009-04-22 22:38:00 +02:00
|
|
|
visit((const VectorInfo &)info);
|
2004-05-04 23:01:00 +02:00
|
|
|
}
|
|
|
|
|
2011-08-19 22:08:05 +02:00
|
|
|
/*
|
|
|
|
This struct implements the output methods for the sparse
|
|
|
|
histogram stat
|
|
|
|
*/
|
|
|
|
struct SparseHistPrint
|
|
|
|
{
|
|
|
|
string name;
|
|
|
|
string separatorString;
|
|
|
|
string desc;
|
|
|
|
Flags flags;
|
|
|
|
bool descriptions;
|
|
|
|
int precision;
|
|
|
|
|
|
|
|
const SparseHistData &data;
|
|
|
|
|
|
|
|
SparseHistPrint(const Text *text, const SparseHistInfo &info);
|
|
|
|
void init(const Text *text, const Info &info);
|
|
|
|
void operator()(ostream &stream) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Call initialization function */
|
|
|
|
SparseHistPrint::SparseHistPrint(const Text *text, const SparseHistInfo &info)
|
|
|
|
: data(info.data)
|
|
|
|
{
|
|
|
|
init(text, info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialization function */
|
|
|
|
void
|
|
|
|
SparseHistPrint::init(const Text *text, const Info &info)
|
|
|
|
{
|
|
|
|
name = info.name;
|
|
|
|
separatorString = info.separatorString;
|
|
|
|
desc = info.desc;
|
|
|
|
flags = info.flags;
|
|
|
|
precision = info.precision;
|
|
|
|
descriptions = text->descriptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Grab data from map and write to output stream */
|
|
|
|
void
|
|
|
|
SparseHistPrint::operator()(ostream &stream) const
|
|
|
|
{
|
|
|
|
string base = name + separatorString;
|
|
|
|
|
|
|
|
ScalarPrint print;
|
|
|
|
print.precision = precision;
|
|
|
|
print.flags = flags;
|
|
|
|
print.descriptions = descriptions;
|
|
|
|
print.desc = desc;
|
|
|
|
print.pdf = NAN;
|
|
|
|
print.cdf = NAN;
|
|
|
|
|
|
|
|
print.name = base + "samples";
|
|
|
|
print.value = data.samples;
|
|
|
|
print(stream);
|
|
|
|
|
|
|
|
MCounter::const_iterator it;
|
|
|
|
for (it = data.cmap.begin(); it != data.cmap.end(); it++) {
|
|
|
|
stringstream namestr;
|
|
|
|
namestr << base;
|
|
|
|
|
|
|
|
namestr <<(*it).first;
|
|
|
|
print.name = namestr.str();
|
|
|
|
print.value = (*it).second;
|
|
|
|
print(stream);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Text::visit(const SparseHistInfo &info)
|
|
|
|
{
|
|
|
|
if (noOutput(info))
|
|
|
|
return;
|
|
|
|
|
|
|
|
SparseHistPrint print(this, info);
|
|
|
|
print(*stream);
|
|
|
|
}
|
|
|
|
|
2011-05-12 20:19:35 +02:00
|
|
|
Output *
|
2009-04-22 19:25:14 +02:00
|
|
|
initText(const string &filename, bool desc)
|
2007-02-18 07:52:32 +01:00
|
|
|
{
|
|
|
|
static Text text;
|
|
|
|
static bool connected = false;
|
|
|
|
|
2011-05-12 20:19:35 +02:00
|
|
|
if (!connected) {
|
2015-11-27 15:41:59 +01:00
|
|
|
text.open(*simout.findOrCreate(filename)->stream());
|
2011-05-12 20:19:35 +02:00
|
|
|
text.descriptions = desc;
|
|
|
|
connected = true;
|
|
|
|
}
|
2007-02-18 07:52:32 +01:00
|
|
|
|
2011-05-12 20:19:35 +02:00
|
|
|
return &text;
|
2007-02-18 07:52:32 +01:00
|
|
|
}
|
|
|
|
|
2011-01-03 23:35:43 +01:00
|
|
|
} // namespace Stats
|