style: Bring statistics code in line with the proper style.
[gem5.git] / src / base / stats / mysql.cc
1 /*
2 * Copyright (c) 2004-2005 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 * Authors: Nathan Binkert
29 */
30
31 #include <cassert>
32 #include <map>
33 #include <sstream>
34 #include <string>
35 #include <vector>
36
37 #include "base/misc.hh"
38 #include "base/mysql.hh"
39 #include "base/statistics.hh"
40 #include "base/stats/flags.hh"
41 #include "base/stats/mysql.hh"
42 #include "base/stats/mysql_run.hh"
43 #include "base/stats/statdb.hh"
44 #include "base/stats/types.hh"
45 #include "base/str.hh"
46 #include "base/userinfo.hh"
47 #include "sim/host.hh"
48
49 using namespace std;
50
51 namespace Stats {
52
53 void
54 MySqlRun::connect(const string &host, const string &user, const string &passwd,
55 const string &db, const string &name, const string &sample,
56 const string &project)
57 {
58 if (connected())
59 panic("can only get one database connection at this time!");
60
61 mysql.connect(host, user, passwd, db);
62 if (mysql.error)
63 panic("could not connect to database server\n%s\n", mysql.error);
64
65 if (mysql.autocommit(false))
66 panic("could not set autocommit\n%s\n", mysql.error);
67
68 remove(name);
69 //cleanup();
70 setup(name, sample, user, project);
71 }
72
73 void
74 MySqlRun::setup(const string &name, const string &sample, const string &user,
75 const string &project)
76 {
77 assert(mysql.connected());
78
79 stringstream insert;
80 ccprintf(insert,
81 "INSERT INTO "
82 "runs(rn_name,rn_sample,rn_user,rn_project,rn_date,rn_expire)"
83 "values(\"%s\", \"%s\", \"%s\", \"%s\", NOW(),"
84 "DATE_ADD(CURDATE(), INTERVAL 31 DAY))",
85 name, sample, user, project);
86
87 mysql.query(insert);
88 if (mysql.error)
89 panic("could not get a run\n%s\n", mysql.error);
90
91 run_id = mysql.insert_id();
92 if (mysql.commit())
93 panic("could not commit transaction\n%s\n", mysql.error);
94 }
95
96 void
97 MySqlRun::remove(const string &name)
98 {
99 assert(mysql.connected());
100 stringstream sql;
101 ccprintf(sql, "DELETE FROM runs WHERE rn_name=\"%s\"", name);
102 mysql.query(sql);
103 if (mysql.error)
104 panic("could not delete run\n%s\n", mysql.error);
105 if (mysql.commit())
106 panic("could not commit transaction\n%s\n", mysql.error);
107 }
108
109 void
110 MySqlRun::cleanup()
111 {
112 assert(mysql.connected());
113
114 mysql.query("DELETE data "
115 "FROM data "
116 "LEFT JOIN runs ON dt_run=rn_id "
117 "WHERE rn_id IS NULL");
118
119 if (mysql.commit())
120 panic("could not commit transaction\n%s\n", mysql.error);
121
122 mysql.query("DELETE formula_ref "
123 "FROM formula_ref "
124 "LEFT JOIN runs ON fr_run=rn_id "
125 "WHERE rn_id IS NULL");
126
127 if (mysql.commit())
128 panic("could not commit transaction\n%s\n", mysql.error);
129
130 mysql.query("DELETE formulas "
131 "FROM formulas "
132 "LEFT JOIN formula_ref ON fm_stat=fr_stat "
133 "WHERE fr_stat IS NULL");
134
135 if (mysql.commit())
136 panic("could not commit transaction\n%s\n", mysql.error);
137
138 mysql.query("DELETE stats "
139 "FROM stats "
140 "LEFT JOIN data ON st_id=dt_stat "
141 "WHERE dt_stat IS NULL");
142
143 if (mysql.commit())
144 panic("could not commit transaction\n%s\n", mysql.error);
145
146 mysql.query("DELETE subdata "
147 "FROM subdata "
148 "LEFT JOIN data ON sd_stat=dt_stat "
149 "WHERE dt_stat IS NULL");
150
151 if (mysql.commit())
152 panic("could not commit transaction\n%s\n", mysql.error);
153
154 mysql.query("DELETE events"
155 "FROM events"
156 "LEFT JOIN runs ON ev_run=rn_id"
157 "WHERE rn_id IS NULL");
158
159 if (mysql.commit())
160 panic("could not commit transaction\n%s\n", mysql.error);
161
162 mysql.query("DELETE event_names"
163 "FROM event_names"
164 "LEFT JOIN events ON en_id=ev_event"
165 "WHERE ev_event IS NULL");
166
167 if (mysql.commit())
168 panic("could not commit transaction\n%s\n", mysql.error);
169 }
170
171 void
172 SetupStat::init()
173 {
174 name = "";
175 descr = "";
176 type = "";
177 print = false;
178 prereq = 0;
179 prec = -1;
180 nozero = false;
181 nonan = false;
182 total = false;
183 pdf = false;
184 cdf = false;
185 min = 0;
186 max = 0;
187 bktsize = 0;
188 size = 0;
189 }
190
191 unsigned
192 SetupStat::setup(MySqlRun *run)
193 {
194 MySQL::Connection &mysql = run->conn();
195
196 stringstream insert;
197 ccprintf(insert,
198 "INSERT INTO "
199 "stats(st_name, st_descr, st_type, st_print, st_prereq, "
200 "st_prec, st_nozero, st_nonan, st_total, st_pdf, st_cdf, "
201 "st_min, st_max, st_bktsize, st_size)"
202 "values(\"%s\",\"%s\",\"%s\","
203 " %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d)",
204 name, descr, type, print, prereq, (int)prec, nozero, nonan,
205 total, pdf, cdf,
206 min, max, bktsize, size);
207
208 mysql.query(insert);
209 if (!mysql.error) {
210 int id = mysql.insert_id();
211 if (mysql.commit())
212 panic("could not commit transaction\n%s\n", mysql.error);
213 return id;
214 }
215
216 stringstream select;
217 ccprintf(select, "SELECT * FROM stats WHERE st_name=\"%s\"", name);
218
219 mysql.query(select);
220 MySQL::Result result = mysql.store_result();
221 if (!result)
222 panic("could not find stat\n%s\n", mysql.error);
223
224 assert(result.num_fields() == 16);
225 MySQL::Row row = result.fetch_row();
226 if (!row)
227 panic("could not get stat row\n%s\n", mysql.error);
228
229 bool tb;
230 int8_t ti8;
231 uint16_t tu16;
232 int64_t ti64;
233 uint64_t tu64;
234
235 if (name != (char *)row[1])
236 panic("failed stat check on %s:name. %s != %s\n",
237 name, name, row[1]);
238
239 if (descr != (char *)row[2])
240 panic("failed stat check on %s:descr. %s != %s\n",
241 name, descr, row[2]);
242
243 if (type != (char *)row[3])
244 panic("failed stat check on %s:type. %s != %s\n",
245 name, type, row[3]);
246
247 if (!to_number(row[4], tb) || print != tb)
248 panic("failed stat check on %s:print. %d != %d\n",
249 name, print, tb);
250
251 if (!to_number(row[6], ti8) || prec != ti8)
252 panic("failed stat check on %s:prec. %d != %d\n",
253 name, prec, ti8);
254
255 if (!to_number(row[7], tb) || nozero != tb)
256 panic("failed stat check on %s:nozero. %d != %d\n",
257 name, nozero, tb);
258
259 if (!to_number(row[8], tb) || nonan != tb)
260 panic("failed stat check on %s:nonan. %d != %d\n",
261 name, nonan, tb);
262
263 if (!to_number(row[9], tb) || total != tb)
264 panic("failed stat check on %s:total. %d != %d\n",
265 name, total, tb);
266
267 if (!to_number(row[10], tb) || pdf != tb)
268 panic("failed stat check on %s:pdf. %d != %d\n",
269 name, pdf, tb);
270
271 if (!to_number(row[11], tb) || cdf != tb)
272 panic("failed stat check on %s:cdf. %d != %d\n",
273 name, cdf, tb);
274
275 if (!to_number(row[12], ti64) || min != ti64)
276 panic("failed stat check on %s:min. %d != %d\n",
277 name, min, ti64);
278
279 if (!to_number(row[13], ti64) || max != ti64)
280 panic("failed stat check on %s:max. %d != %d\n",
281 name, max, ti64);
282
283 if (!to_number(row[14], tu64) || bktsize != tu64)
284 panic("failed stat check on %s:bktsize. %d != %d\n",
285 name, bktsize, tu64);
286
287 if (!to_number(row[15], tu16) || size != tu16)
288 panic("failed stat check on %s:size. %d != %d\n",
289 name, size, tu16);
290
291 to_number(row[5], prereq);
292 uint16_t statid;
293 to_number(row[0], statid);
294 return statid;
295 }
296
297 InsertData::InsertData(MySqlRun *_run)
298 : run(_run)
299 {
300 query = new char[maxsize + 1];
301 size = 0;
302 flush();
303 }
304
305 InsertData::~InsertData()
306 {
307 delete [] query;
308 }
309
310 void
311 InsertData::flush()
312 {
313 if (size) {
314 MySQL::Connection &mysql = run->conn();
315 assert(mysql.connected());
316 mysql.query(query);
317 if (mysql.error)
318 panic("could not insert data\n%s\n", mysql.error);
319 if (mysql.commit())
320 panic("could not commit transaction\n%s\n", mysql.error);
321 }
322
323 query[0] = '\0';
324 size = 0;
325 first = true;
326 strcpy(query, "INSERT INTO "
327 "data(dt_stat,dt_x,dt_y,dt_run,dt_tick,dt_data) "
328 "values");
329 size = strlen(query);
330 }
331
332 void
333 InsertData::insert()
334 {
335 if (size + 1024 > maxsize)
336 flush();
337
338 if (!first) {
339 query[size++] = ',';
340 query[size] = '\0';
341 }
342
343 first = false;
344
345 size += sprintf(query + size, "(%u,%d,%d,%u,%llu,\"%f\")",
346 stat, x, y, run->run(), (unsigned long long)tick,
347 data);
348 }
349
350 InsertEvent::InsertEvent(MySqlRun *_run)
351 : run(_run)
352 {
353 query = new char[maxsize + 1];
354 size = 0;
355 first = true;
356 flush();
357 }
358
359 InsertEvent::~InsertEvent()
360 {
361 flush();
362 }
363
364 void
365 InsertEvent::insert(const string &stat)
366 {
367 MySQL::Connection &mysql = run->conn();
368 assert(mysql.connected());
369
370 event_map_t::iterator i = events.find(stat);
371 uint32_t event;
372 if (i == events.end()) {
373 mysql.query(
374 csprintf("SELECT en_id "
375 "from event_names "
376 "where en_name=\"%s\"",
377 stat));
378
379 MySQL::Result result = mysql.store_result();
380 if (!result)
381 panic("could not get a run\n%s\n", mysql.error);
382
383 assert(result.num_fields() == 1);
384 MySQL::Row row = result.fetch_row();
385 if (row) {
386 if (!to_number(row[0], event))
387 panic("invalid event id: %s\n", row[0]);
388 } else {
389 mysql.query(
390 csprintf("INSERT INTO "
391 "event_names(en_name)"
392 "values(\"%s\")",
393 stat));
394
395 if (mysql.error)
396 panic("could not get a run\n%s\n", mysql.error);
397
398 event = mysql.insert_id();
399 }
400 } else {
401 event = (*i).second;
402 }
403
404 if (size + 1024 > maxsize)
405 flush();
406
407 if (!first) {
408 query[size++] = ',';
409 query[size] = '\0';
410 }
411
412 first = false;
413
414 size += sprintf(query + size, "(%u,%u,%llu)",
415 event, run->run(), (unsigned long long)curTick);
416 }
417
418 void
419 InsertEvent::flush()
420 {
421 static const char query_header[] = "INSERT INTO "
422 "events(ev_event, ev_run, ev_tick)"
423 "values";
424
425 MySQL::Connection &mysql = run->conn();
426 assert(mysql.connected());
427
428 if (size)
429 mysql.query(query);
430
431 query[0] = '\0';
432 size = sizeof(query_header);
433 first = true;
434 memcpy(query, query_header, size);
435 }
436
437 struct InsertSubData
438 {
439 uint16_t stat;
440 int16_t x;
441 int16_t y;
442 string name;
443 string descr;
444
445 void setup(MySqlRun *run);
446 };
447
448 void
449 InsertSubData::setup(MySqlRun *run)
450 {
451 MySQL::Connection &mysql = run->conn();
452 assert(mysql.connected());
453 stringstream insert;
454 ccprintf(insert,
455 "INSERT INTO subdata(sd_stat,sd_x,sd_y,sd_name,sd_descr) "
456 "values(%d,%d,%d,\"%s\",\"%s\")",
457 stat, x, y, name, descr);
458
459 mysql.query(insert);
460 // if (mysql.error)
461 // panic("could not insert subdata\n%s\n", mysql.error);
462
463 if (mysql.commit())
464 panic("could not commit transaction\n%s\n", mysql.error);
465 }
466
467 MySql::MySql()
468 : run(new MySqlRun), newdata(run), newevent(run)
469 {}
470
471 MySql::~MySql()
472 {
473 delete run;
474 }
475
476 void
477 MySql::connect(const string &host, const string &user, const string &passwd,
478 const string &db, const string &name, const string &sample,
479 const string &project)
480 {
481 run->connect(host, user, passwd, db, name, sample, project);
482 }
483
484 bool
485 MySql::connected() const
486 {
487 return run->connected();
488 }
489
490 void
491 MySql::configure()
492 {
493 /*
494 * set up all stats!
495 */
496 using namespace Database;
497
498 MySQL::Connection &mysql = run->conn();
499
500 stat_list_t::const_iterator i, end = stats().end();
501 for (i = stats().begin(); i != end; ++i) {
502 (*i)->visit(*this);
503 }
504
505 for (i = stats().begin(); i != end; ++i) {
506 StatData *data = *i;
507 if (data->prereq) {
508 // update the prerequisite
509 uint16_t stat_id = find(data->id);
510 uint16_t prereq_id = find(data->prereq->id);
511 assert(stat_id && prereq_id);
512
513 stringstream update;
514 ccprintf(update, "UPDATE stats SET st_prereq=%d WHERE st_id=%d",
515 prereq_id, stat_id);
516 mysql.query(update);
517 if (mysql.error)
518 panic("could not update prereq\n%s\n", mysql.error);
519
520 if (mysql.commit())
521 panic("could not commit transaction\n%s\n", mysql.error);
522 }
523 }
524
525 if (mysql.commit())
526 panic("could not commit transaction\n%s\n", mysql.error);
527
528 configured = true;
529 }
530
531
532 bool
533 MySql::configure(const StatData &data, string type)
534 {
535 stat.init();
536 stat.name = data.name;
537 stat.descr = data.desc;
538 stat.type = type;
539 stat.print = data.flags & print;
540 stat.prec = data.precision;
541 stat.nozero = data.flags & nozero;
542 stat.nonan = data.flags & nonan;
543 stat.total = data.flags & total;
544 stat.pdf = data.flags & pdf;
545 stat.cdf = data.flags & cdf;
546
547 return stat.print;
548 }
549
550 void
551 MySql::configure(const ScalarData &data)
552 {
553 if (!configure(data, "SCALAR"))
554 return;
555
556 insert(data.id, stat.setup(run));
557 }
558
559 void
560 MySql::configure(const VectorData &data)
561 {
562 if (!configure(data, "VECTOR"))
563 return;
564
565 uint16_t statid = stat.setup(run);
566
567 if (!data.subnames.empty()) {
568 InsertSubData subdata;
569 subdata.stat = statid;
570 subdata.y = 0;
571 for (int i = 0; i < data.subnames.size(); ++i) {
572 subdata.x = i;
573 subdata.name = data.subnames[i];
574 subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
575
576 if (!subdata.name.empty() || !subdata.descr.empty())
577 subdata.setup(run);
578 }
579 }
580
581 insert(data.id, statid);
582 }
583
584 void
585 MySql::configure(const DistData &data)
586 {
587 if (!configure(data, "DIST"))
588 return;
589
590 if (!data.data.fancy) {
591 stat.size = data.data.size;
592 stat.min = data.data.min;
593 stat.max = data.data.max;
594 stat.bktsize = data.data.bucket_size;
595 }
596 insert(data.id, stat.setup(run));
597 }
598
599 void
600 MySql::configure(const VectorDistData &data)
601 {
602 if (!configure(data, "VECTORDIST"))
603 return;
604
605 if (!data.data[0].fancy) {
606 stat.size = data.data[0].size;
607 stat.min = data.data[0].min;
608 stat.max = data.data[0].max;
609 stat.bktsize = data.data[0].bucket_size;
610 }
611
612 uint16_t statid = stat.setup(run);
613
614 if (!data.subnames.empty()) {
615 InsertSubData subdata;
616 subdata.stat = statid;
617 subdata.y = 0;
618 for (int i = 0; i < data.subnames.size(); ++i) {
619 subdata.x = i;
620 subdata.name = data.subnames[i];
621 subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
622 if (!subdata.name.empty() || !subdata.descr.empty())
623 subdata.setup(run);
624 }
625 }
626
627 insert(data.id, statid);
628 }
629
630 void
631 MySql::configure(const Vector2dData &data)
632 {
633 if (!configure(data, "VECTOR2D"))
634 return;
635
636 uint16_t statid = stat.setup(run);
637
638 if (!data.subnames.empty()) {
639 InsertSubData subdata;
640 subdata.stat = statid;
641 subdata.y = -1;
642 for (int i = 0; i < data.subnames.size(); ++i) {
643 subdata.x = i;
644 subdata.name = data.subnames[i];
645 subdata.descr = data.subdescs.empty() ? "" : data.subdescs[i];
646 if (!subdata.name.empty() || !subdata.descr.empty())
647 subdata.setup(run);
648 }
649 }
650
651 if (!data.y_subnames.empty()) {
652 InsertSubData subdata;
653 subdata.stat = statid;
654 subdata.x = -1;
655 subdata.descr = "";
656 for (int i = 0; i < data.y_subnames.size(); ++i) {
657 subdata.y = i;
658 subdata.name = data.y_subnames[i];
659 if (!subdata.name.empty())
660 subdata.setup(run);
661 }
662 }
663
664 insert(data.id, statid);
665 }
666
667 void
668 MySql::configure(const FormulaData &data)
669 {
670 MySQL::Connection &mysql = run->conn();
671 assert(mysql.connected());
672
673 configure(data, "FORMULA");
674 insert(data.id, stat.setup(run));
675
676 uint16_t stat = find(data.id);
677 string formula = data.str();
678
679 stringstream insert_formula;
680 ccprintf(insert_formula,
681 "INSERT INTO formulas(fm_stat,fm_formula) values(%d, \"%s\")",
682 stat, formula);
683
684 mysql.query(insert_formula);
685 // if (mysql.error)
686 // panic("could not insert formula\n%s\n", mysql.error);
687
688 stringstream insert_ref;
689 ccprintf(insert_ref,
690 "INSERT INTO formula_ref(fr_stat,fr_run) values(%d, %d)",
691 stat, run->run());
692
693 mysql.query(insert_ref);
694 // if (mysql.error)
695 // panic("could not insert formula reference\n%s\n", mysql.error);
696
697 if (mysql.commit())
698 panic("could not commit transaction\n%s\n", mysql.error);
699 }
700
701 bool
702 MySql::valid() const
703 {
704 return run->connected();
705 }
706
707 void
708 MySql::output()
709 {
710 using namespace Database;
711 assert(valid());
712
713 if (!configured)
714 configure();
715
716 // store sample #
717 newdata.tick = curTick;
718
719 MySQL::Connection &mysql = run->conn();
720
721 Database::stat_list_t::const_iterator i, end = Database::stats().end();
722 for (i = Database::stats().begin(); i != end; ++i) {
723 StatData *stat = *i;
724 stat->visit(*this);
725 if (mysql.commit())
726 panic("could not commit transaction\n%s\n", mysql.error);
727 }
728
729 newdata.flush();
730 }
731
732 void
733 MySql::event(const std::string &event)
734 {
735 newevent.insert(event);
736 }
737
738
739 void
740 MySql::output(const ScalarData &data)
741 {
742 if (!(data.flags & print))
743 return;
744
745 newdata.stat = find(data.id);
746 newdata.x = 0;
747 newdata.y = 0;
748 newdata.data = data.value();
749
750 newdata.insert();
751 }
752
753 void
754 MySql::output(const VectorData &data)
755 {
756 if (!(data.flags & print))
757 return;
758
759 newdata.stat = find(data.id);
760 newdata.y = 0;
761
762 const VCounter &cvec = data.value();
763 int size = data.size();
764 for (int x = 0; x < size; x++) {
765 newdata.x = x;
766 newdata.data = cvec[x];
767 newdata.insert();
768 }
769 }
770
771 void
772 MySql::output(const DistDataData &data)
773 {
774 const int db_sum = -1;
775 const int db_squares = -2;
776 const int db_samples = -3;
777 const int db_min_val = -4;
778 const int db_max_val = -5;
779 const int db_underflow = -6;
780 const int db_overflow = -7;
781
782 newdata.x = db_sum;
783 newdata.data = data.sum;
784 newdata.insert();
785
786 newdata.x = db_squares;
787 newdata.data = data.squares;
788 newdata.insert();
789
790 newdata.x = db_samples;
791 newdata.data = data.samples;
792 newdata.insert();
793
794 if (data.samples && !data.fancy) {
795 newdata.x = db_min_val;
796 newdata.data = data.min_val;
797 newdata.insert();
798
799 newdata.x = db_max_val;
800 newdata.data = data.max_val;
801 newdata.insert();
802
803 newdata.x = db_underflow;
804 newdata.data = data.underflow;
805 newdata.insert();
806
807 newdata.x = db_overflow;
808 newdata.data = data.overflow;
809 newdata.insert();
810
811 int size = data.cvec.size();
812 for (int x = 0; x < size; x++) {
813 newdata.x = x;
814 newdata.data = data.cvec[x];
815 newdata.insert();
816 }
817 }
818 }
819
820
821 void
822 MySql::output(const DistData &data)
823 {
824 if (!(data.flags & print))
825 return;
826
827 newdata.stat = find(data.id);
828 newdata.y = 0;
829 output(data.data);
830 }
831
832 void
833 MySql::output(const VectorDistData &data)
834 {
835 if (!(data.flags & print))
836 return;
837
838 newdata.stat = find(data.id);
839
840 int size = data.data.size();
841 for (int y = 0; y < size; ++y) {
842 newdata.y = y;
843 output(data.data[y]);
844 }
845 }
846
847 void
848 MySql::output(const Vector2dData &data)
849 {
850 if (!(data.flags & print))
851 return;
852
853 newdata.stat = find(data.id);
854
855 int index = 0;
856 for (int x = 0; x < data.x; x++) {
857 newdata.x = x;
858 for (int y = 0; y < data.y; y++) {
859 newdata.y = y;
860 newdata.data = data.cvec[index++];
861 newdata.insert();
862 }
863 }
864 }
865
866 void
867 MySql::output(const FormulaData &data)
868 {
869 }
870
871 /*
872 * Implement the visitor
873 */
874 void
875 MySql::visit(const ScalarData &data)
876 {
877 if (!configured)
878 configure(data);
879 else
880 output(data);
881 }
882
883 void
884 MySql::visit(const VectorData &data)
885 {
886 if (!configured)
887 configure(data);
888 else
889 output(data);
890 }
891
892 void
893 MySql::visit(const DistData &data)
894 {
895 return;
896 if (!configured)
897 configure(data);
898 else
899 output(data);
900 }
901
902 void
903 MySql::visit(const VectorDistData &data)
904 {
905 return;
906 if (!configured)
907 configure(data);
908 else
909 output(data);
910 }
911
912 void
913 MySql::visit(const Vector2dData &data)
914 {
915 return;
916 if (!configured)
917 configure(data);
918 else
919 output(data);
920 }
921
922 void
923 MySql::visit(const FormulaData &data)
924 {
925 if (!configured)
926 configure(data);
927 else
928 output(data);
929 }
930
931 bool
932 initMySQL(string host, string user, string password, string database,
933 string project, string name, string sample)
934 {
935 extern list<Output *> OutputList;
936 static MySql mysql;
937
938 if (mysql.connected())
939 return false;
940
941 mysql.connect(host, user, password, database, name, sample, project);
942 OutputList.push_back(&mysql);
943
944 return true;
945 }
946
947 /* end namespace Stats */ }