Merged in new FastCPU stuff with existing code.
[gem5.git] / base / stats / mysql.hh
1 /*
2 * Copyright (c) 2003-2004 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __BASE_STATS_MYSQL_HH__
30 #define __BASE_STATS_MYSQL_HH__
31
32 #include <map>
33 #include <string>
34
35 #include "base/stats/output.hh"
36
37 namespace Stats {
38
39 class DistDataData;
40 class MySqlRun;
41 bool MySqlConnected();
42 extern MySqlRun MySqlDB;
43
44 struct SetupStat
45 {
46 std::string name;
47 std::string descr;
48 std::string type;
49 bool print;
50 uint16_t prereq;
51 int8_t prec;
52 bool nozero;
53 bool nonan;
54 bool total;
55 bool pdf;
56 bool cdf;
57 double min;
58 double max;
59 double bktsize;
60 uint16_t size;
61
62 void init();
63 unsigned setup();
64 };
65
66 class InsertData
67 {
68 private:
69 char *query;
70 int size;
71 bool first;
72 static const int maxsize = 1024*1024;
73
74 public:
75 MySqlRun *run;
76
77 public:
78 uint64_t sample;
79 double data;
80 uint16_t stat;
81 uint16_t bin;
82 int16_t x;
83 int16_t y;
84
85 public:
86 InsertData();
87 ~InsertData();
88
89 void flush();
90 void insert();
91 };
92
93 class MySql : public Output
94 {
95 protected:
96 SetupStat stat;
97 InsertData newdata;
98 std::list<FormulaData *> formulas;
99 bool configured;
100
101 protected:
102 std::map<int, int> idmap;
103
104 void insert(int sim_id, int db_id)
105 {
106 using namespace std;
107 idmap.insert(make_pair(sim_id, db_id));
108 }
109
110 int find(int sim_id)
111 {
112 using namespace std;
113 map<int,int>::const_iterator i = idmap.find(sim_id);
114 assert(i != idmap.end());
115 return (*i).second;
116 }
117 public:
118 // Implement Visit
119 virtual void visit(const ScalarData &data);
120 virtual void visit(const VectorData &data);
121 virtual void visit(const DistData &data);
122 virtual void visit(const VectorDistData &data);
123 virtual void visit(const Vector2dData &data);
124 virtual void visit(const FormulaData &data);
125
126 // Implement Output
127 virtual bool valid() const;
128 virtual void output();
129
130 protected:
131 // Output helper
132 void output(const std::string &bin);
133 void output(const DistDataData &data);
134 void output(const ScalarData &data);
135 void output(const VectorData &data);
136 void output(const DistData &data);
137 void output(const VectorDistData &data);
138 void output(const Vector2dData &data);
139 void output(const FormulaData &data);
140
141 void configure();
142 void configure(const StatData &data, std::string type);
143 void configure(const ScalarData &data);
144 void configure(const VectorData &data);
145 void configure(const DistData &data);
146 void configure(const VectorDistData &data);
147 void configure(const Vector2dData &data);
148 void configure(const FormulaData &data);
149 };
150
151 /* namespace Stats */ }
152
153 #endif // __BASE_STATS_MYSQL_HH__