1
| |
2/* 3 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29
| 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
|
30/* 31 * $Id$ 32 * 33 * Description: The histogram class implements a simple histogram 34 * 35 */
| 29#ifndef __MEM_RUBY_COMMON_HISTOGRAM_HH__ 30#define __MEM_RUBY_COMMON_HISTOGRAM_HH__
|
36
| 31
|
37#ifndef HISTOGRAM_H 38#define HISTOGRAM_H 39
| |
40#include <iostream> 41 42#include "mem/ruby/common/Global.hh" 43#include "mem/gems_common/Vector.hh" 44
| 32#include <iostream> 33 34#include "mem/ruby/common/Global.hh" 35#include "mem/gems_common/Vector.hh" 36
|
45class Histogram { 46public: 47 // Constructors 48 Histogram(int binsize = 1, int bins = 50);
| 37class Histogram 38{ 39 public: 40 Histogram(int binsize = 1, int bins = 50); 41 ~Histogram();
|
49
| 42
|
50 // Destructor 51 ~Histogram();
| 43 void add(int64 value); 44 void add(const Histogram& hist); 45 void clear() { clear(m_bins); } 46 void clear(int bins); 47 void clear(int binsize, int bins); 48 int64 size() const { return m_count; } 49 int getBins() const { return m_bins; } 50 int getBinSize() const { return m_binsize; } 51 int64 getTotal() const { return m_sumSamples; } 52 int64 getData(int index) const { return m_data[index]; }
|
52
| 53
|
53 // Public Methods
| 54 void printWithMultiplier(std::ostream& out, double multiplier) const; 55 void printPercent(std::ostream& out) const; 56 void print(std::ostream& out) const;
|
54
| 57
|
55 void add(int64 value); 56 void add(const Histogram& hist); 57 void clear() { clear(m_bins); } 58 void clear(int bins); 59 void clear(int binsize, int bins); 60 int64 size() const { return m_count; } 61 int getBins() const { return m_bins; } 62 int getBinSize() const { return m_binsize; } 63 int64 getTotal() const { return m_sumSamples; } 64 int64 getData(int index) const { return m_data[index]; } 65 66 void printWithMultiplier(std::ostream& out, double multiplier) const; 67 void printPercent(std::ostream& out) const; 68 void print(std::ostream& out) const;
| |
69private:
| 58private:
|
70 // Private Methods
| 59 Vector<int64> m_data; 60 int64 m_max; // the maximum value seen so far 61 int64 m_count; // the number of elements added 62 int m_binsize; // the size of each bucket 63 int m_bins; // the number of buckets 64 int m_largest_bin; // the largest bin used
|
71
| 65
|
72 // Private copy constructor and assignment operator 73 // Histogram(const Histogram& obj); 74 // Histogram& operator=(const Histogram& obj);
| 66 int64 m_sumSamples; // the sum of all samples 67 int64 m_sumSquaredSamples; // the sum of the square of all samples
|
75
| 68
|
76 // Data Members (m_ prefix) 77 Vector<int64> m_data; 78 int64 m_max; // the maximum value seen so far 79 int64 m_count; // the number of elements added 80 int m_binsize; // the size of each bucket 81 int m_bins; // the number of buckets 82 int m_largest_bin; // the largest bin used 83 84 int64 m_sumSamples; // the sum of all samples 85 int64 m_sumSquaredSamples; // the sum of the square of all samples 86 87 double getStandardDeviation() const;
| 69 double getStandardDeviation() const;
|
88}; 89 90bool node_less_then_eq(const Histogram* n1, const Histogram* n2); 91
| 70}; 71 72bool node_less_then_eq(const Histogram* n1, const Histogram* n2); 73
|
92// Output operator declaration 93std::ostream& operator<<(std::ostream& out, const Histogram& obj); 94 95// ******************* Definitions ******************* 96 97// Output operator definition 98extern inline 99std::ostream& operator<<(std::ostream& out, const Histogram& obj)
| 74inline std::ostream& 75operator<<(std::ostream& out, const Histogram& obj)
|
100{
| 76{
|
101 obj.print(out); 102 out << std::flush; 103 return out;
| 77 obj.print(out); 78 out << std::flush; 79 return out;
|
104} 105
| 80} 81
|
106#endif //HISTOGRAM_H
| 82#endif // __MEM_RUBY_COMMON_HISTOGRAM_HH__
|
| |