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