stats: stick the distribution's fancy parameter into the parameters structure.
[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 const Params *params = safe_cast<const Params *>(info.storageParams);
587 if (!params->fancy) {
588 stat.size = params->buckets;
589 stat.min = params->min;
590 stat.max = params->max;
591 stat.bktsize = params->bucket_size;
592 }
593 insert(info.id, stat.setup(run));
594 }
595
596 void
597 MySql::configure(const VectorDistInfoBase &info)
598 {
599 if (!configure(info, "VECTORDIST"))
600 return;
601
602 const Params *params = safe_cast<const Params *>(info.storageParams);
603 if (!params->fancy) {
604 stat.size = params->buckets;
605 stat.min = params->min;
606 stat.max = params->max;
607 stat.bktsize = params->bucket_size;
608 }
609
610 uint16_t statid = stat.setup(run);
611
612 if (!info.subnames.empty()) {
613 InsertSubData subdata;
614 subdata.stat = statid;
615 subdata.y = 0;
616 for (off_type i = 0; i < info.subnames.size(); ++i) {
617 subdata.x = i;
618 subdata.name = info.subnames[i];
619 subdata.descr = info.subdescs.empty() ? "" : info.subdescs[i];
620 if (!subdata.name.empty() || !subdata.descr.empty())
621 subdata.setup(run);
622 }
623 }
624
625 insert(info.id, statid);
626 }
627
628 void
629 MySql::configure(const Vector2dInfoBase &info)
630 {
631 if (!configure(info, "VECTOR2D"))
632 return;
633
634 uint16_t statid = stat.setup(run);
635
636 if (!info.subnames.empty()) {
637 InsertSubData subdata;
638 subdata.stat = statid;
639 subdata.y = -1;
640 for (off_type i = 0; i < info.subnames.size(); ++i) {
641 subdata.x = i;
642 subdata.name = info.subnames[i];
643 subdata.descr = info.subdescs.empty() ? "" : info.subdescs[i];
644 if (!subdata.name.empty() || !subdata.descr.empty())
645 subdata.setup(run);
646 }
647 }
648
649 if (!info.y_subnames.empty()) {
650 InsertSubData subdata;
651 subdata.stat = statid;
652 subdata.x = -1;
653 subdata.descr = "";
654 for (off_type i = 0; i < info.y_subnames.size(); ++i) {
655 subdata.y = i;
656 subdata.name = info.y_subnames[i];
657 if (!subdata.name.empty())
658 subdata.setup(run);
659 }
660 }
661
662 insert(info.id, statid);
663 }
664
665 void
666 MySql::configure(const FormulaInfoBase &info)
667 {
668 MySQL::Connection &mysql = run->conn();
669 assert(mysql.connected());
670
671 configure(info, "FORMULA");
672 insert(info.id, stat.setup(run));
673
674 uint16_t stat = find(info.id);
675 string formula = info.str();
676
677 stringstream insert_formula;
678 ccprintf(insert_formula,
679 "INSERT INTO formulas(fm_stat,fm_formula) values(%d, \"%s\")",
680 stat, formula);
681
682 mysql.query(insert_formula);
683 // if (mysql.error)
684 // panic("could not insert formula\n%s\n", mysql.error);
685
686 stringstream insert_ref;
687 ccprintf(insert_ref,
688 "INSERT INTO formula_ref(fr_stat,fr_run) values(%d, %d)",
689 stat, run->run());
690
691 mysql.query(insert_ref);
692 // if (mysql.error)
693 // panic("could not insert formula reference\n%s\n", mysql.error);
694
695 if (mysql.commit())
696 panic("could not commit transaction\n%s\n", mysql.error);
697 }
698
699 bool
700 MySql::valid() const
701 {
702 return run->connected();
703 }
704
705 void
706 MySql::output()
707 {
708 assert(valid());
709
710 if (!configured)
711 configure();
712
713 // store sample #
714 newdata.tick = curTick;
715
716 MySQL::Connection &mysql = run->conn();
717
718 list<Info *>::const_iterator i, end = statsList().end();
719 for (i = statsList().begin(); i != end; ++i) {
720 Info *stat = *i;
721 stat->visit(*this);
722 if (mysql.commit())
723 panic("could not commit transaction\n%s\n", mysql.error);
724 }
725
726 newdata.flush();
727 }
728
729 void
730 MySql::event(const std::string &event)
731 {
732 newevent.insert(event);
733 }
734
735 void
736 MySql::output(const ScalarInfoBase &info)
737 {
738 if (!(info.flags & print))
739 return;
740
741 newdata.stat = find(info.id);
742 newdata.x = 0;
743 newdata.y = 0;
744 newdata.data = info.value();
745
746 newdata.insert();
747 }
748
749 void
750 MySql::output(const VectorInfoBase &info)
751 {
752 if (!(info.flags & print))
753 return;
754
755 newdata.stat = find(info.id);
756 newdata.y = 0;
757
758 const VCounter &cvec = info.value();
759 size_type size = info.size();
760 for (off_type x = 0; x < size; x++) {
761 newdata.x = x;
762 newdata.data = cvec[x];
763 newdata.insert();
764 }
765 }
766
767 void
768 MySql::output(const DistData &data)
769 {
770 const int db_sum = -1;
771 const int db_squares = -2;
772 const int db_samples = -3;
773 const int db_min_val = -4;
774 const int db_max_val = -5;
775 const int db_underflow = -6;
776 const int db_overflow = -7;
777
778 newdata.x = db_sum;
779 newdata.data = data.sum;
780 newdata.insert();
781
782 newdata.x = db_squares;
783 newdata.data = data.squares;
784 newdata.insert();
785
786 newdata.x = db_samples;
787 newdata.data = data.samples;
788 newdata.insert();
789
790 if (data.samples && !data.fancy) {
791 newdata.x = db_min_val;
792 newdata.data = data.min_val;
793 newdata.insert();
794
795 newdata.x = db_max_val;
796 newdata.data = data.max_val;
797 newdata.insert();
798
799 newdata.x = db_underflow;
800 newdata.data = data.underflow;
801 newdata.insert();
802
803 newdata.x = db_overflow;
804 newdata.data = data.overflow;
805 newdata.insert();
806
807 size_type size = data.cvec.size();
808 for (off_type x = 0; x < size; x++) {
809 newdata.x = x;
810 newdata.data = data.cvec[x];
811 newdata.insert();
812 }
813 }
814 }
815
816 void
817 MySql::output(const DistInfoBase &info)
818 {
819 if (!(info.flags & print))
820 return;
821
822 newdata.stat = find(info.id);
823 newdata.y = 0;
824 output(info.data);
825 }
826
827 void
828 MySql::output(const VectorDistInfoBase &info)
829 {
830 if (!(info.flags & print))
831 return;
832
833 newdata.stat = find(info.id);
834
835 size_type size = info.data.size();
836 for (off_type y = 0; y < size; ++y) {
837 newdata.y = y;
838 output(info.data[y]);
839 }
840 }
841
842 void
843 MySql::output(const Vector2dInfoBase &info)
844 {
845 if (!(info.flags & print))
846 return;
847
848 newdata.stat = find(info.id);
849
850 off_type index = 0;
851 for (off_type x = 0; x < info.x; x++) {
852 newdata.x = x;
853 for (off_type y = 0; y < info.y; y++) {
854 newdata.y = y;
855 newdata.data = info.cvec[index++];
856 newdata.insert();
857 }
858 }
859 }
860
861 void
862 MySql::output(const FormulaInfoBase &info)
863 {
864 }
865
866 /*
867 * Implement the visitor
868 */
869 void
870 MySql::visit(const ScalarInfoBase &info)
871 {
872 if (!configured)
873 configure(info);
874 else
875 output(info);
876 }
877
878 void
879 MySql::visit(const VectorInfoBase &info)
880 {
881 if (!configured)
882 configure(info);
883 else
884 output(info);
885 }
886
887 void
888 MySql::visit(const DistInfoBase &info)
889 {
890 return;
891 if (!configured)
892 configure(info);
893 else
894 output(info);
895 }
896
897 void
898 MySql::visit(const VectorDistInfoBase &info)
899 {
900 return;
901 if (!configured)
902 configure(info);
903 else
904 output(info);
905 }
906
907 void
908 MySql::visit(const Vector2dInfoBase &info)
909 {
910 return;
911 if (!configured)
912 configure(info);
913 else
914 output(info);
915 }
916
917 void
918 MySql::visit(const FormulaInfoBase &info)
919 {
920 if (!configured)
921 configure(info);
922 else
923 output(info);
924 }
925
926 bool
927 initMySQL(string host, string user, string password, string database,
928 string project, string name, string sample)
929 {
930 extern list<Output *> OutputList;
931 static MySql mysql;
932
933 if (mysql.connected())
934 return false;
935
936 mysql.connect(host, user, password, database, name, sample, project);
937 OutputList.push_back(&mysql);
938
939 return true;
940 }
941
942 /* end namespace Stats */ }