blob: 50cecceede21dbe85ec1b8b3b55ac134d6d22b1b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#include "booksim.hpp"
#include <math.h>
#include <stdio.h>
#include <iostream>
#include "stats.hpp"
Stats::Stats( Module *parent, const string &name,
double bin_size, int num_bins ) :
Module( parent, name ),
_num_bins( num_bins ), _bin_size( bin_size )
{
_hist = new int [_num_bins];
Clear( );
}
Stats::~Stats( )
{
delete [] _hist;
}
void Stats::Clear( )
{
_num_samples = 0;
_sample_sum = 0.0;
for ( int b = 0; b < _num_bins; ++b ) {
_hist[b] = 0;
}
_reset = true;
}
double Stats::Average( ) const
{
return _sample_sum / (double)_num_samples;
}
double Stats::Min( ) const
{
return _min;
}
double Stats::Max( ) const
{
return _max;
}
int Stats::NumSamples( ) const
{
return _num_samples;
}
void Stats::AddSample( double val )
{
int b;
_num_samples++;
_sample_sum += val;
if ( _reset ) {
_reset = false;
_max = val;
_min = val;
} else {
if ( val > _max ) {
_max = val;
}
if ( val < _min ) {
_min = val;
}
}
b = (int)floor( val / _bin_size );
if ( b < 0 ) {
b = 0;
} else if ( b >= _num_bins ) {
b = _num_bins - 1;
}
_hist[b]++;
}
void Stats::AddSample( int val )
{
AddSample( (double)val );
}
void Stats::Display( ) const
{
int b;
if (_bin_size != 1.0 ) {
cout<<_fullname<<"_";
printf("bins = [ ");
for ( b = 0; b < _num_bins; ++b ) {
printf("%d ", b* (unsigned)_bin_size);
}
printf("];\n");
}
cout<<_fullname<<"_";
printf("freq = [ ");
for ( b = 0; b < _num_bins; ++b ) {
printf("%d ", (unsigned) _hist[b]);
}
printf("];\n");
}
bool Stats::NeverUsed() const
{
if ( _reset ) {
return true;
} else {
return false;
}
}
|