annotate base/HitCount.h @ 1257:5236543343c3 3.0-integration

A note on cache hit findings
author Chris Cannam
date Thu, 10 Nov 2016 09:23:05 +0000
parents d8d6d01505ed
children 6974bd4efdb5
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@1256 35 using namespace std;
Chris@1256 36 int total = m_hit + m_partial + m_miss;
Chris@1256 37 cerr << "Hit count: " << m_name << ": ";
Chris@1256 38 if (m_partial > 0) {
Chris@1256 39 cerr << m_hit << " hits, " << m_partial << " partial, "
Chris@1256 40 << m_miss << " misses";
Chris@1256 41 } else {
Chris@1256 42 cerr << m_hit << " hits, " << m_miss << " misses";
Chris@1256 43 }
Chris@1256 44 if (total > 0) {
Chris@1256 45 if (m_partial > 0) {
Chris@1256 46 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1256 47 << ((m_partial * 100.0) / total) << "%, "
Chris@1256 48 << ((m_miss * 100.0) / total) << "%)";
Chris@1256 49 } else {
Chris@1256 50 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
Chris@1256 51 << ((m_miss * 100.0) / total) << "%)";
Chris@1256 52 }
Chris@1256 53 }
Chris@1256 54 cerr << endl;
Chris@1256 55 }
Chris@1256 56
Chris@1256 57 void hit() { ++m_hit; }
Chris@1256 58 void partial() { ++m_partial; }
Chris@1256 59 void miss() { ++m_miss; }
Chris@1256 60
Chris@1256 61 private:
Chris@1256 62 std::string m_name;
Chris@1256 63 int m_hit;
Chris@1256 64 int m_partial;
Chris@1256 65 int m_miss;
Chris@1256 66 };
Chris@1256 67
Chris@1256 68 #endif