libdballe 4.0.18
|
00001 /* 00002 * DB-ALLe - Archive for punctual meteorological data 00003 * 00004 * Copyright (C) 2005,2006 ARPA-SIM <urpsim@smr.arpa.emr.it> 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 * 00019 * Author: Enrico Zini <enrico@enricozini.com> 00020 */ 00021 00022 #ifndef BENCHMARK_H 00023 #define BENCHMARK_H 00024 00025 #include <dballe/core/error.h> 00026 00027 #include <sys/times.h> 00028 00029 #include <vector> 00030 #include <string> 00031 #include <iosfwd> 00032 00033 class Benchmark 00034 { 00035 private: 00036 static double tps; 00037 std::string tag; 00038 struct tms lasttms; 00039 Benchmark* parent; 00040 std::vector<Benchmark*> children; 00041 00042 protected: 00043 // Main function with the benchmarks 00044 virtual dba_err main() { return dba_error_ok(); } 00045 00046 dba_err timing(const char* fmt, ...); 00047 00048 void setParent(Benchmark* parent) { this->parent = parent; } 00049 00050 std::string name() const { return tag; } 00051 00052 std::string fullName() const 00053 { 00054 if (parent) 00055 return parent->fullName() + "/" + tag; 00056 else 00057 return tag; 00058 } 00059 00060 public: 00061 Benchmark(const std::string& tag) : tag(tag), parent(0) {} 00062 00063 void addChild(Benchmark* child) 00064 { 00065 children.push_back(child); 00066 child->setParent(this); 00067 } 00068 00069 virtual ~Benchmark() 00070 { 00071 for (std::vector<Benchmark*>::iterator i = children.begin(); 00072 i != children.end(); i++) 00073 delete *i; 00074 } 00075 00076 void list(std::ostream& out); 00077 00078 // Run only the subtest at the given path 00079 dba_err run(const std::string& path); 00080 00081 // Run all subtests and this test 00082 dba_err run(); 00083 00084 // Return the singleton instance of the toplevel benchmark class 00085 static Benchmark* root(); 00086 }; 00087 00088 struct RegisterRoot 00089 { 00090 RegisterRoot(Benchmark* b) 00091 { 00092 Benchmark::root()->addChild(b); 00093 } 00094 }; 00095 00096 // vim:set ts=4 sw=4: 00097 #endif