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