gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Histogram.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
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 
29 #ifndef __MEM_RUBY_COMMON_HISTOGRAM_HH__
30 #define __MEM_RUBY_COMMON_HISTOGRAM_HH__
31 
32 #include <iostream>
33 #include <vector>
34 
36 
37 class Histogram
38 {
39  public:
40  Histogram(int binsize = 1, uint32_t bins = 50);
41  ~Histogram();
42 
43  void add(int64_t value);
44  void add(Histogram& hist);
45  void doubleBinSize();
46 
47  void clear() { clear(m_data.size()); }
48  void clear(uint32_t bins);
49  void clear(int binsize, uint32_t bins);
50 
51  uint64_t size() const { return m_count; }
52  uint32_t getBins() const { return m_data.size(); }
53  int getBinSize() const { return m_binsize; }
54  int64_t getTotal() const { return m_sumSamples; }
55  uint64_t getSquaredTotal() const { return m_sumSquaredSamples; }
56  uint64_t getData(int index) const { return m_data[index]; }
57  int64_t getMax() const { return m_max; }
58 
59  void printWithMultiplier(std::ostream& out, double multiplier) const;
60  void printPercent(std::ostream& out) const;
61  void print(std::ostream& out) const;
62 
63 private:
65  int64_t m_max; // the maximum value seen so far
66  uint64_t m_count; // the number of elements added
67  int m_binsize; // the size of each bucket
68  uint32_t m_largest_bin; // the largest bin used
69 
70  int64_t m_sumSamples; // the sum of all samples
71  uint64_t m_sumSquaredSamples; // the sum of the square of all samples
72 
73  double getStandardDeviation() const;
74 };
75 
76 bool node_less_then_eq(const Histogram* n1, const Histogram* n2);
77 
78 inline std::ostream&
79 operator<<(std::ostream& out, const Histogram& obj)
80 {
81  obj.print(out);
82  out << std::flush;
83  return out;
84 }
85 
86 #endif // __MEM_RUBY_COMMON_HISTOGRAM_HH__
~Histogram()
Definition: Histogram.cc:44
Bitfield< 30, 0 > index
uint64_t getSquaredTotal() const
Definition: Histogram.hh:55
void doubleBinSize()
Definition: Histogram.cc:72
uint64_t m_sumSquaredSamples
Definition: Histogram.hh:71
int getBinSize() const
Definition: Histogram.hh:53
uint32_t m_largest_bin
Definition: Histogram.hh:68
std::ostream & operator<<(std::ostream &out, const Histogram &obj)
Definition: Histogram.hh:79
int64_t m_max
Definition: Histogram.hh:65
uint32_t getBins() const
Definition: Histogram.hh:52
int m_binsize
Definition: Histogram.hh:67
std::vector< uint64_t > m_data
Definition: Histogram.hh:64
void add(int64_t value)
Definition: Histogram.cc:88
uint64_t getData(int index) const
Definition: Histogram.hh:56
int64_t getTotal() const
Definition: Histogram.hh:54
int64_t getMax() const
Definition: Histogram.hh:57
double getStandardDeviation() const
Definition: Histogram.cc:176
int64_t m_sumSamples
Definition: Histogram.hh:70
Histogram(int binsize=1, uint32_t bins=50)
Definition: Histogram.cc:38
void printWithMultiplier(std::ostream &out, double multiplier) const
Definition: Histogram.cc:204
void printPercent(std::ostream &out) const
Definition: Histogram.cc:194
uint64_t m_count
Definition: Histogram.hh:66
void clear()
Definition: Histogram.hh:47
bool node_less_then_eq(const Histogram *n1, const Histogram *n2)
Definition: Histogram.cc:234
void print(std::ostream &out) const
Definition: Histogram.cc:188
uint64_t size() const
Definition: Histogram.hh:51

Generated on Fri Jun 9 2017 13:03:49 for gem5 by doxygen 1.8.6