stattest.cc revision 2665:a124942bacb8
1/*
2 * Copyright (c) 2003-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 <iomanip>
32#include <iostream>
33#include <fstream>
34#include <string>
35#include <unistd.h>
36
37#include "base/cprintf.hh"
38#include "base/misc.hh"
39#include "base/statistics.hh"
40#include "base/stats/text.hh"
41#include "base/stats/mysql.hh"
42#include "sim/host.hh"
43
44using namespace std;
45using namespace Stats;
46
47Tick curTick = 0;
48Tick ticksPerSecond = ULL(2000000000);
49
50Scalar<> s1;
51Scalar<> s2;
52Average<> s3;
53Scalar<MainBin> s4;
54Vector<MainBin> s5;
55Distribution<MainBin> s6;
56Vector<MainBin> s7;
57AverageVector<> s8;
58StandardDeviation<> s9;
59AverageDeviation<> s10;
60Scalar<> s11;
61Distribution<> s12;
62VectorDistribution<> s13;
63VectorStandardDeviation<> s14;
64VectorAverageDeviation<> s15;
65Vector2d<> s16;
66
67Formula f1;
68Formula f2;
69Formula f3;
70Value f4;
71Value f5;
72Formula f6;
73Formula f7;
74
75MainBin bin1("bin1");
76MainBin bin2("bin2");
77
78ostream *outputStream = &cout;
79
80double
81testfunc()
82{
83    return 9.8;
84}
85
86class TestClass {
87  public:
88    double operator()() { return 9.7; }
89};
90
91char *progname = "";
92
93void
94usage()
95{
96    panic("incorrect usage.\n"
97          "usage:\n"
98          "\t%s [-t [-c] [-d]]\n", progname);
99}
100
101int
102main(int argc, char *argv[])
103{
104    bool descriptions = false;
105    bool compat = false;
106    bool text = false;
107    string mysql_name;
108    string mysql_host;
109    string mysql_user = "binkertn";
110    string mysql_passwd;
111
112    char c;
113    progname = argv[0];
114    while ((c = getopt(argc, argv, "cdh:P:p:s:tu:")) != -1) {
115        switch (c) {
116          case 'c':
117            compat = true;
118            break;
119          case 'd':
120            descriptions = true;
121            break;
122          case 'h':
123            mysql_host = optarg;
124            break;
125          case 'P':
126            mysql_passwd = optarg;
127            break;
128          case 's':
129            mysql_name = optarg;
130            break;
131          case 't':
132            text = true;
133            break;
134          case 'u':
135            mysql_user = optarg;
136            break;
137          default:
138            usage();
139        }
140    }
141
142    if (!text && (compat || descriptions))
143        usage();
144
145    s5.init(5);
146    s6.init(1, 100, 13);
147    s7.init(7);
148    s8.init(10);
149    s12.init(1, 100, 13);
150    s13.init(4, 0, 99, 10);
151    s14.init(9);
152    s15.init(10);
153    s16.init(2, 9);
154
155    s1
156        .name("Stat01")
157        .desc("this is statistic 1")
158        ;
159
160    s2
161        .name("Stat02")
162        .desc("this is statistic 2")
163        .prereq(s11)
164        ;
165
166    s3
167        .name("Stat03")
168        .desc("this is statistic 3")
169        .prereq(f7)
170        ;
171
172    s4
173        .name("Stat04")
174        .desc("this is statistic 4")
175        .prereq(s11)
176        ;
177
178    s5
179        .name("Stat05")
180        .desc("this is statistic 5")
181        .prereq(s11)
182        .subname(0, "foo1")
183        .subname(1, "foo2")
184        .subname(2, "foo3")
185        .subname(3, "foo4")
186        .subname(4, "foo5")
187        ;
188
189    s6
190        .name("Stat06")
191        .desc("this is statistic 6")
192        .prereq(s11)
193        ;
194
195    s7
196        .name("Stat07")
197        .desc("this is statistic 7")
198        .precision(1)
199        .flags(pdf | total)
200        .prereq(s11)
201        ;
202
203    s8
204        .name("Stat08")
205        .desc("this is statistic 8")
206        .precision(2)
207        .prereq(s11)
208        .subname(4, "blarg")
209        ;
210
211    s9
212        .name("Stat09")
213        .desc("this is statistic 9")
214        .precision(4)
215        .prereq(s11)
216        ;
217
218    s10
219        .name("Stat10")
220        .desc("this is statistic 10")
221        .prereq(s11)
222        ;
223
224    s12
225        .name("Stat12")
226        .desc("this is statistic 12")
227        ;
228
229    s13
230        .name("Stat13")
231        .desc("this is statistic 13")
232        ;
233
234    s14
235        .name("Stat14")
236        .desc("this is statistic 14")
237        ;
238
239    s15
240        .name("Stat15")
241        .desc("this is statistic 15")
242        ;
243
244    s16
245        .name("Stat16")
246        .desc("this is statistic 16")
247        .flags(total)
248        .subname(0, "sub0")
249        .subname(1, "sub1")
250        .ysubname(0, "y0")
251        .ysubname(1, "y1")
252        ;
253
254    f1
255        .name("Formula1")
256        .desc("this is formula 1")
257        .prereq(s11)
258        ;
259
260    f2
261        .name("Formula2")
262        .desc("this is formula 2")
263        .prereq(s11)
264        .precision(1)
265        ;
266
267    f3
268        .name("Formula3")
269        .desc("this is formula 3")
270        .prereq(s11)
271        .subname(0, "bar1")
272        .subname(1, "bar2")
273        .subname(2, "bar3")
274        .subname(3, "bar4")
275        .subname(4, "bar5")
276        ;
277
278    f4
279        .functor(testfunc)
280        .name("Formula4")
281        .desc("this is formula 4")
282        ;
283
284    TestClass testclass;
285    f5
286        .functor(testclass)
287        .name("Formula5")
288        .desc("this is formula 5")
289        ;
290
291    f6
292        .name("Formula6")
293        .desc("this is formula 6")
294        ;
295
296    f1 = s1 + s2;
297    f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
298    f3 = sum(s5) * s7;
299    f6 += constant(10.0);
300    f6 += s5[3];
301    f7 = constant(1);
302
303    check();
304    reset();
305
306    bin1.activate();
307
308    s16[1][0] = 1;
309    s16[0][1] = 3;
310    s16[0][0] = 2;
311    s16[1][1] = 9;
312    s16[1][1] += 9;
313    s16[1][8] += 8;
314    s16[1][7] += 7;
315    s16[1][6] += 6;
316    s16[1][5] += 5;
317    s16[1][4] += 4;
318
319    s11 = 1;
320    s3 = 9;
321    s8[3] = 9;
322    s15[0].sample(1234);
323    s15[1].sample(1234);
324    s15[2].sample(1234);
325    s15[3].sample(1234);
326    s15[4].sample(1234);
327    s15[5].sample(1234);
328    s15[6].sample(1234);
329    s15[7].sample(1234);
330    s15[8].sample(1234);
331    s15[9].sample(1234);
332
333    s10.sample(1000000000);
334    curTick += ULL(1000000);
335    s10.sample(100000);
336    s10.sample(100000);
337    s10.sample(100000);
338    s10.sample(100000);
339    s10.sample(100000);
340    s10.sample(100000);
341    s10.sample(100000);
342    s10.sample(100000);
343    s10.sample(100000);
344    s10.sample(100000);
345    s10.sample(100000);
346    s10.sample(100000);
347    s10.sample(100000);
348    s13[0].sample(12);
349    s13[1].sample(29);
350    s13[2].sample(12);
351    s13[3].sample(29);
352    s13[0].sample(42);
353    s13[1].sample(29);
354    s13[2].sample(42);
355    s13[3].sample(32);
356    s13[0].sample(52);
357    s13[1].sample(49);
358    s13[2].sample(42);
359    s13[3].sample(25);
360    s13[0].sample(32);
361    s13[1].sample(49);
362    s13[2].sample(22);
363    s13[3].sample(49);
364    s13[0].sample(62);
365    s13[1].sample(99);
366    s13[2].sample(72);
367    s13[3].sample(23);
368    s13[0].sample(52);
369    s13[1].sample(78);
370    s13[2].sample(69);
371    s13[3].sample(49);
372
373    s14[0].sample(1234);
374    s14[1].sample(4134);
375    s14[4].sample(1213);
376    s14[3].sample(1124);
377    s14[2].sample(1243);
378    s14[7].sample(1244);
379    s14[4].sample(7234);
380    s14[2].sample(9234);
381    s14[3].sample(1764);
382    s14[7].sample(1564);
383    s14[3].sample(3234);
384    s14[1].sample(2234);
385    s14[5].sample(1234);
386    s14[2].sample(4334);
387    s14[2].sample(1234);
388    s14[4].sample(4334);
389    s14[6].sample(1234);
390    s14[8].sample(8734);
391    s14[1].sample(5234);
392    s14[3].sample(8234);
393    s14[7].sample(5234);
394    s14[4].sample(4434);
395    s14[3].sample(7234);
396    s14[2].sample(1934);
397    s14[1].sample(9234);
398    s14[5].sample(5634);
399    s14[3].sample(1264);
400    s14[7].sample(5223);
401    s14[0].sample(1234);
402    s14[0].sample(5434);
403    s14[3].sample(8634);
404    s14[1].sample(1234);
405
406
407    s15[0].sample(1234);
408    s15[1].sample(4134);
409    curTick += ULL(1000000);
410    s15[4].sample(1213);
411    curTick += ULL(1000000);
412    s15[3].sample(1124);
413    curTick += ULL(1000000);
414    s15[2].sample(1243);
415    curTick += ULL(1000000);
416    s15[7].sample(1244);
417    curTick += ULL(1000000);
418    s15[4].sample(7234);
419    s15[2].sample(9234);
420    s15[3].sample(1764);
421    s15[7].sample(1564);
422    s15[3].sample(3234);
423    s15[1].sample(2234);
424    curTick += ULL(1000000);
425    s15[5].sample(1234);
426    curTick += ULL(1000000);
427    s15[9].sample(4334);
428    curTick += ULL(1000000);
429    s15[2].sample(1234);
430    curTick += ULL(1000000);
431    s15[4].sample(4334);
432    s15[6].sample(1234);
433    curTick += ULL(1000000);
434    s15[8].sample(8734);
435    curTick += ULL(1000000);
436    s15[1].sample(5234);
437    curTick += ULL(1000000);
438    s15[3].sample(8234);
439    curTick += ULL(1000000);
440    s15[7].sample(5234);
441    s15[4].sample(4434);
442    s15[3].sample(7234);
443    s15[2].sample(1934);
444    s15[1].sample(9234);
445    curTick += ULL(1000000);
446    s15[5].sample(5634);
447    s15[3].sample(1264);
448    s15[7].sample(5223);
449    s15[0].sample(1234);
450    s15[0].sample(5434);
451    s15[3].sample(8634);
452    curTick += ULL(1000000);
453    s15[1].sample(1234);
454
455    s4 = curTick;
456
457    s8[3] = 99999;
458
459    s3 = 12;
460    s3++;
461    curTick += 9;
462
463    s1 = 9;
464    s1 += 9;
465    s1 -= 11;
466    s1++;
467    ++s1;
468    s1--;
469    --s1;
470
471    s2 = 9;
472
473    s5[0] += 1;
474    s5[1] += 2;
475    s5[2] += 3;
476    s5[3] += 4;
477    s5[4] += 5;
478
479    s7[0] = 10;
480    s7[1] = 20;
481    s7[2] = 30;
482    s7[3] = 40;
483    s7[4] = 50;
484    s7[5] = 60;
485    s7[6] = 70;
486
487    s6.sample(0);
488    s6.sample(1);
489    s6.sample(2);
490    s6.sample(3);
491    s6.sample(4);
492    s6.sample(5);
493    s6.sample(6);
494    s6.sample(7);
495    s6.sample(8);
496    s6.sample(9);
497
498    bin2.activate();
499    s6.sample(10);
500    s6.sample(10);
501    s6.sample(10);
502    s6.sample(10);
503    s6.sample(10);
504    s6.sample(10);
505    s6.sample(10);
506    s6.sample(10);
507    s6.sample(11);
508    s6.sample(19);
509    s6.sample(20);
510    s6.sample(20);
511    s6.sample(21);
512    s6.sample(21);
513    s6.sample(31);
514    s6.sample(98);
515    s6.sample(99);
516    s6.sample(99);
517    s6.sample(99);
518
519    s7[0] = 700;
520    s7[1] = 600;
521    s7[2] = 500;
522    s7[3] = 400;
523    s7[4] = 300;
524    s7[5] = 200;
525    s7[6] = 100;
526
527    s9.sample(100);
528    s9.sample(100);
529    s9.sample(100);
530    s9.sample(100);
531    s9.sample(10);
532    s9.sample(10);
533    s9.sample(10);
534    s9.sample(10);
535    s9.sample(10);
536
537    curTick += 9;
538    s4 = curTick;
539    s6.sample(100);
540    s6.sample(100);
541    s6.sample(100);
542    s6.sample(101);
543    s6.sample(102);
544
545    s12.sample(100);
546
547    if (text) {
548        Text out(cout);
549        out.descriptions = descriptions;
550        out.compat = compat;
551        out();
552    }
553
554    if (!mysql_name.empty()) {
555        MySql out;
556        out.connect(mysql_host, mysql_user, mysql_passwd, "m5stats",
557                    mysql_name, "test");
558        out();
559    }
560
561    return 0;
562}
563