From 1177e7a3c861d77360074e97661952d427cd8640 Mon Sep 17 00:00:00 2001 From: Nathan Binkert Date: Thu, 12 May 2011 11:19:35 -0700 Subject: stats: move code that loops over all stats into python --- src/base/stats/info.hh | 4 +-- src/base/stats/mysql.cc | 52 +++++++++++++++++++++------------- src/base/stats/mysql.hh | 10 ++++--- src/base/stats/output.cc | 73 ------------------------------------------------ src/base/stats/output.hh | 24 ++++++++++++---- src/base/stats/text.cc | 29 +++++++++---------- src/base/stats/text.hh | 5 ++-- src/base/stats/visit.cc | 41 --------------------------- src/base/stats/visit.hh | 59 -------------------------------------- 9 files changed, 75 insertions(+), 222 deletions(-) delete mode 100644 src/base/stats/output.cc delete mode 100644 src/base/stats/visit.cc delete mode 100644 src/base/stats/visit.hh (limited to 'src/base/stats') diff --git a/src/base/stats/info.hh b/src/base/stats/info.hh index 1759b4796..fa7c8cc3d 100644 --- a/src/base/stats/info.hh +++ b/src/base/stats/info.hh @@ -62,7 +62,7 @@ const FlagsType nonan = 0x0200; const FlagsType __reserved = init | display; struct StorageParams; -struct Visit; +struct Output; class Info { @@ -129,7 +129,7 @@ class Info /** * Visitor entry for outputing statistics data */ - virtual void visit(Visit &visitor) = 0; + virtual void visit(Output &visitor) = 0; /** * Checks if the first stat's name is alphabetically less than the second. diff --git a/src/base/stats/mysql.cc b/src/base/stats/mysql.cc index c08394605..9f9a862d4 100644 --- a/src/base/stats/mysql.cc +++ b/src/base/stats/mysql.cc @@ -395,7 +395,8 @@ MySql::configure() list::const_iterator i, end = statsList().end(); for (i = statsList().begin(); i != end; ++i) { - (*i)->visit(*this); + Info *info = *i; + info->visit(*this); } for (i = statsList().begin(); i != end; ++i) { @@ -606,7 +607,7 @@ MySql::valid() const } void -MySql::output() +MySql::begin() { assert(valid()); @@ -615,20 +616,22 @@ MySql::output() // store sample # newdata.tick = curTick(); +} - MySQL::Connection &mysql = run->conn(); - - list::const_iterator i, end = statsList().end(); - for (i = statsList().begin(); i != end; ++i) { - Info *stat = *i; - stat->visit(*this); - if (mysql.commit()) - panic("could not commit transaction\n%s\n", mysql.error); - } - +void +MySql::end() +{ newdata.flush(); } +void +MySql::commit() +{ + MySQL::Connection &mysql = run->conn(); + if (mysql.commit()) + panic("could not commit transaction\n%s\n", mysql.error); +} + void MySql::output(const ScalarInfo &info) { @@ -641,6 +644,8 @@ MySql::output(const ScalarInfo &info) newdata.data = info.value(); newdata.insert(); + + commit(); } void @@ -659,6 +664,8 @@ MySql::output(const VectorInfo &info) newdata.data = cvec[x]; newdata.insert(); } + + commit(); } void @@ -708,6 +715,8 @@ MySql::output(const DistData &data, const DistParams *params) newdata.insert(); } } + + commit(); } void @@ -719,6 +728,8 @@ MySql::output(const DistInfo &info) newdata.stat = find(info.id); newdata.y = 0; output(info.data, safe_cast(info.storageParams)); + + commit(); } void @@ -735,6 +746,8 @@ MySql::output(const VectorDistInfo &info) output(info.data[y], safe_cast(info.storageParams)); } + + commit(); } void @@ -754,6 +767,8 @@ MySql::output(const Vector2dInfo &info) newdata.insert(); } } + + commit(); } void @@ -821,20 +836,17 @@ MySql::visit(const FormulaInfo &info) output(info); } -bool +Output * initMySQL(string host, string user, string password, string database, string project, string name, string sample) { - extern list OutputList; static MySql mysql; - if (mysql.connected()) - return false; - - mysql.connect(host, user, password, database, name, sample, project); - OutputList.push_back(&mysql); + if (mysql.connected()) { + mysql.connect(host, user, password, database, name, sample, project); + } - return true; + return &mysql; } } // namespace Stats diff --git a/src/base/stats/mysql.hh b/src/base/stats/mysql.hh index caee2a1c2..a305304a2 100644 --- a/src/base/stats/mysql.hh +++ b/src/base/stats/mysql.hh @@ -147,10 +147,12 @@ class MySql : public Output // Implement Output virtual bool valid() const; - virtual void output(); + virtual void begin(); + virtual void end(); protected: // Output helper + void commit(); void output(const ScalarInfo &info); void output(const VectorInfo &info); void output(const DistInfo &info); @@ -169,17 +171,17 @@ class MySql : public Output void configure(const FormulaInfo &info); }; -bool initMySQL(std::string host, std::string database, std::string user, +Output *initMySQL(std::string host, std::string database, std::string user, std::string passwd, std::string project, std::string name, std::string sample); #if !USE_MYSQL -inline bool +inline Output * initMySQL(std::string host, std::string user, std::string password, std::string database, std::string project, std::string name, std::string sample) { - return false; + return NULL; } #endif diff --git a/src/base/stats/output.cc b/src/base/stats/output.cc deleted file mode 100644 index 6e1ba1c3b..000000000 --- a/src/base/stats/output.cc +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Regents of The University of Michigan - * 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. - * - * Authors: Nathan Binkert - */ - -#include - -#include "base/stats/output.hh" -#include "base/statistics.hh" -#include "base/types.hh" -#include "sim/eventq.hh" - -using namespace std; - -namespace Stats { - -Tick lastDump(0); -list OutputList; - -void -dump() -{ - assert(lastDump <= curTick()); - if (lastDump == curTick()) - return; - lastDump = curTick(); - - prepare(); - - list::iterator i = OutputList.begin(); - list::iterator end = OutputList.end(); - for (; i != end; ++i) { - Output *output = *i; - if (!output->valid()) - continue; - - output->output(); - } -} - -} // namespace Stats - -void -debugDumpStats() -{ - Stats::dump(); -} - diff --git a/src/base/stats/output.hh b/src/base/stats/output.hh index 0f485dee3..d45e32f77 100644 --- a/src/base/stats/output.hh +++ b/src/base/stats/output.hh @@ -31,17 +31,31 @@ #ifndef __BASE_STATS_OUTPUT_HH__ #define __BASE_STATS_OUTPUT_HH__ +#include #include -#include "base/stats/visit.hh" - namespace Stats { -struct Output : public Visit +class Info; +class ScalarInfo; +class VectorInfo; +class DistInfo; +class VectorDistInfo; +class Vector2dInfo; +class FormulaInfo; + +struct Output { - inline void operator()() { output(); } - virtual void output() = 0; + virtual void begin() = 0; + virtual void end() = 0; virtual bool valid() const = 0; + + virtual void visit(const ScalarInfo &info) = 0; + virtual void visit(const VectorInfo &info) = 0; + virtual void visit(const DistInfo &info) = 0; + virtual void visit(const VectorDistInfo &info) = 0; + virtual void visit(const Vector2dInfo &info) = 0; + virtual void visit(const FormulaInfo &info) = 0; }; } // namespace Stats diff --git a/src/base/stats/text.cc b/src/base/stats/text.cc index f1ba59f0e..45d59ff29 100644 --- a/src/base/stats/text.cc +++ b/src/base/stats/text.cc @@ -48,7 +48,6 @@ #include "base/stats/info.hh" #include "base/stats/text.hh" -#include "base/stats/visit.hh" #include "base/cast.hh" #include "base/misc.hh" #include "base/str.hh" @@ -138,12 +137,14 @@ Text::valid() const } void -Text::output() +Text::begin() { ccprintf(*stream, "\n---------- Begin Simulation Statistics ----------\n"); - list::const_iterator i, end = statsList().end(); - for (i = statsList().begin(); i != end; ++i) - (*i)->visit(*this); +} + +void +Text::end() +{ ccprintf(*stream, "\n---------- End Simulation Statistics ----------\n"); stream->flush(); } @@ -580,23 +581,19 @@ Text::visit(const FormulaInfo &info) visit((const VectorInfo &)info); } -bool +Output * initText(const string &filename, bool desc) { static Text text; static bool connected = false; - if (connected) - return false; - - extern list OutputList; - - text.open(*simout.find(filename)); - text.descriptions = desc; - OutputList.push_back(&text); - connected = true; + if (!connected) { + text.open(*simout.find(filename)); + text.descriptions = desc; + connected = true; + } - return true; + return &text; } } // namespace Stats diff --git a/src/base/stats/text.hh b/src/base/stats/text.hh index de2bf9401..24abaac97 100644 --- a/src/base/stats/text.hh +++ b/src/base/stats/text.hh @@ -70,10 +70,11 @@ class Text : public Output // Implement Output virtual bool valid() const; - virtual void output(); + virtual void begin(); + virtual void end(); }; -bool initText(const std::string &filename, bool desc); +Output *initText(const std::string &filename, bool desc); } // namespace Stats diff --git a/src/base/stats/visit.cc b/src/base/stats/visit.cc deleted file mode 100644 index 1d13bc25d..000000000 --- a/src/base/stats/visit.cc +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Regents of The University of Michigan - * 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. - * - * Authors: Nathan Binkert - */ - -#include "base/stats/visit.hh" - -namespace Stats { - -Visit::Visit() -{} - -Visit::~Visit() -{} - -} // namespace Stats diff --git a/src/base/stats/visit.hh b/src/base/stats/visit.hh deleted file mode 100644 index 606d1c633..000000000 --- a/src/base/stats/visit.hh +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2004-2005 The Regents of The University of Michigan - * 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. - * - * Authors: Nathan Binkert - */ - -#ifndef __BASE_STATS_VISIT_HH__ -#define __BASE_STATS_VISIT_HH__ - -namespace Stats { - -class Info; -class ScalarInfo; -class VectorInfo; -class DistInfo; -class VectorDistInfo; -class Vector2dInfo; -class FormulaInfo; - -struct Visit -{ - Visit(); - virtual ~Visit(); - - virtual void visit(const ScalarInfo &info) = 0; - virtual void visit(const VectorInfo &info) = 0; - virtual void visit(const DistInfo &info) = 0; - virtual void visit(const VectorDistInfo &info) = 0; - virtual void visit(const Vector2dInfo &info) = 0; - virtual void visit(const FormulaInfo &info) = 0; -}; - -} // namespace Stats - -#endif // __BASE_STATS_VISIT_HH__ -- cgit v1.2.3