00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
00079 dba_err run(const std::string& path);
00080
00081
00082 dba_err run();
00083
00084
00085 static Benchmark* root();
00086 };
00087
00088 struct RegisterRoot
00089 {
00090 RegisterRoot(Benchmark* b)
00091 {
00092 Benchmark::root()->addChild(b);
00093 }
00094 };
00095
00096
00097 #endif