annotate base/HitCount.h @ 1311:90ac1df228aa 3.0-integration

Merge from branch mp3-gapless
author Chris Cannam
date Tue, 29 Nov 2016 16:45:53 +0000
parents 6974bd4efdb5
children 48e9f538e6e9
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@1256 24 class HitCount
Chris@1256 25 {
Chris@1256 26 public:
Chris@1256 27 HitCount(std::string name) :
Chris@1256 28 m_name(name),
Chris@1256 29 m_hit(0),
Chris@1256 30 m_partial(0),
Chris@1256 31 m_miss(0)
Chris@1256 32 { }
Chris@1256 33
Chris@1256 34 ~HitCount() {
Chris@1274 35 #ifndef NO_HIT_COUNTS
Chris@1256 36 using namespace std;
Chris@1256 37 int total = m_hit + m_partial + m_miss;
Chris@1256 38 cerr << "Hit count: " << m_name << ": ";
Chris@1256 39 if (m_partial > 0) {
Chris@1256 40 cerr << m_hit << " hits, " << m_partial << " partial, "
Chris@1256 41 << m_miss << " misses";
Chris@1256 42 } else {
Chris@1256 43 cerr << m_hit << " hits, " << m_miss << " misses";
Chris@1256 44 }
Chris@1256 45 if (total > 0) {
Chris@1256 46 if (m_partial > 0) {
Chris@1256 47 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1256 48 << ((m_partial * 100.0) / total) << "%, "
Chris@1256 49 << ((m_miss * 100.0) / total) << "%)";
Chris@1256 50 } else {
Chris@1256 51 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1256 52 << ((m_miss * 100.0) / total) << "%)";
Chris@1256 53 }
Chris@1256 54 }
Chris@1256 55 cerr << endl;
Chris@1274 56 #endif
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@1256 70 #endif