comparison base/HitCount.h @ 1256:d8d6d01505ed 3.0-integration

Print out cache hit/miss counts
author Chris Cannam
date Wed, 09 Nov 2016 18:08:40 +0000
parents
children 6974bd4efdb5
comparison
equal deleted inserted replaced
1255:ca9032dd2811 1256:d8d6d01505ed
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 Sonic Visualiser
5 An audio file viewer and annotation editor.
6 Centre for Digital Music, Queen Mary, University of London.
7
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version. See the file
12 COPYING included with this distribution for more information.
13 */
14
15 #ifndef HIT_COUNT_H
16 #define HIT_COUNT_H
17
18 #include <string>
19 #include <iostream>
20
21 /**
22 * Profile class for counting cache hits and the like.
23 */
24 class HitCount
25 {
26 public:
27 HitCount(std::string name) :
28 m_name(name),
29 m_hit(0),
30 m_partial(0),
31 m_miss(0)
32 { }
33
34 ~HitCount() {
35 using namespace std;
36 int total = m_hit + m_partial + m_miss;
37 cerr << "Hit count: " << m_name << ": ";
38 if (m_partial > 0) {
39 cerr << m_hit << " hits, " << m_partial << " partial, "
40 << m_miss << " misses";
41 } else {
42 cerr << m_hit << " hits, " << m_miss << " misses";
43 }
44 if (total > 0) {
45 if (m_partial > 0) {
46 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
47 << ((m_partial * 100.0) / total) << "%, "
48 << ((m_miss * 100.0) / total) << "%)";
49 } else {
50 cerr << " (" << ((m_hit * 100.0) / total) << "%, "
51 << ((m_miss * 100.0) / total) << "%)";
52 }
53 }
54 cerr << endl;
55 }
56
57 void hit() { ++m_hit; }
58 void partial() { ++m_partial; }
59 void miss() { ++m_miss; }
60
61 private:
62 std::string m_name;
63 int m_hit;
64 int m_partial;
65 int m_miss;
66 };
67
68 #endif