Mercurial > hg > svcore
annotate base/HitCount.h @ 1696:187c76c40c6f single-point
Ensure a self-alignment is always reported as complete, since there is nothing to calculate
author | Chris Cannam |
---|---|
date | Wed, 01 May 2019 11:45:28 +0100 |
parents | 410819150cd3 |
children |
rev | line source |
---|---|
Chris@1256 | 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ |
Chris@1256 | 2 |
Chris@1256 | 3 /* |
Chris@1256 | 4 Sonic Visualiser |
Chris@1256 | 5 An audio file viewer and annotation editor. |
Chris@1256 | 6 Centre for Digital Music, Queen Mary, University of London. |
Chris@1256 | 7 |
Chris@1256 | 8 This program is free software; you can redistribute it and/or |
Chris@1256 | 9 modify it under the terms of the GNU General Public License as |
Chris@1256 | 10 published by the Free Software Foundation; either version 2 of the |
Chris@1256 | 11 License, or (at your option) any later version. See the file |
Chris@1256 | 12 COPYING included with this distribution for more information. |
Chris@1256 | 13 */ |
Chris@1256 | 14 |
Chris@1256 | 15 #ifndef HIT_COUNT_H |
Chris@1256 | 16 #define HIT_COUNT_H |
Chris@1256 | 17 |
Chris@1256 | 18 #include <string> |
Chris@1256 | 19 #include <iostream> |
Chris@1256 | 20 |
Chris@1256 | 21 /** |
Chris@1256 | 22 * Profile class for counting cache hits and the like. |
Chris@1256 | 23 */ |
Chris@1570 | 24 #ifndef NO_HIT_COUNTS |
Chris@1570 | 25 |
Chris@1256 | 26 class HitCount |
Chris@1256 | 27 { |
Chris@1256 | 28 public: |
Chris@1256 | 29 HitCount(std::string name) : |
Chris@1429 | 30 m_name(name), |
Chris@1429 | 31 m_hit(0), |
Chris@1429 | 32 m_partial(0), |
Chris@1429 | 33 m_miss(0) |
Chris@1256 | 34 { } |
Chris@1256 | 35 |
Chris@1256 | 36 ~HitCount() { |
Chris@1429 | 37 using namespace std; |
Chris@1429 | 38 int total = m_hit + m_partial + m_miss; |
Chris@1429 | 39 cerr << "Hit count: " << m_name << ": "; |
Chris@1429 | 40 if (m_partial > 0) { |
Chris@1429 | 41 cerr << m_hit << " hits, " << m_partial << " partial, " |
Chris@1429 | 42 << m_miss << " misses"; |
Chris@1429 | 43 } else { |
Chris@1429 | 44 cerr << m_hit << " hits, " << m_miss << " misses"; |
Chris@1429 | 45 } |
Chris@1429 | 46 if (total > 0) { |
Chris@1429 | 47 if (m_partial > 0) { |
Chris@1429 | 48 cerr << " (" << ((m_hit * 100.0) / total) << "%, " |
Chris@1429 | 49 << ((m_partial * 100.0) / total) << "%, " |
Chris@1429 | 50 << ((m_miss * 100.0) / total) << "%)"; |
Chris@1429 | 51 } else { |
Chris@1429 | 52 cerr << " (" << ((m_hit * 100.0) / total) << "%, " |
Chris@1429 | 53 << ((m_miss * 100.0) / total) << "%)"; |
Chris@1429 | 54 } |
Chris@1429 | 55 } |
Chris@1429 | 56 cerr << endl; |
Chris@1256 | 57 } |
Chris@1256 | 58 |
Chris@1256 | 59 void hit() { ++m_hit; } |
Chris@1256 | 60 void partial() { ++m_partial; } |
Chris@1256 | 61 void miss() { ++m_miss; } |
Chris@1256 | 62 |
Chris@1256 | 63 private: |
Chris@1256 | 64 std::string m_name; |
Chris@1256 | 65 int m_hit; |
Chris@1256 | 66 int m_partial; |
Chris@1256 | 67 int m_miss; |
Chris@1256 | 68 }; |
Chris@1256 | 69 |
Chris@1570 | 70 #else // NO_HIT_COUNTS |
Chris@1570 | 71 |
Chris@1570 | 72 class HitCount |
Chris@1570 | 73 { |
Chris@1570 | 74 public: |
Chris@1570 | 75 HitCount(std::string) {} |
Chris@1570 | 76 |
Chris@1570 | 77 void hit() {} |
Chris@1570 | 78 void partial() {} |
Chris@1570 | 79 void miss() {} |
Chris@1570 | 80 }; |
Chris@1570 | 81 |
Chris@1256 | 82 #endif |
Chris@1570 | 83 |
Chris@1570 | 84 #endif |