comparison data/fileio/WavFileReader.cpp @ 1256:d8d6d01505ed 3.0-integration

Print out cache hit/miss counts
author Chris Cannam
date Wed, 09 Nov 2016 18:08:40 +0000
parents 6877f4200912
children 200c60de27ca
comparison
equal deleted inserted replaced
1255:ca9032dd2811 1256:d8d6d01505ed
12 License, or (at your option) any later version. See the file 12 License, or (at your option) any later version. See the file
13 COPYING included with this distribution for more information. 13 COPYING included with this distribution for more information.
14 */ 14 */
15 15
16 #include "WavFileReader.h" 16 #include "WavFileReader.h"
17
18 #include "base/HitCount.h"
17 19
18 #include <iostream> 20 #include <iostream>
19 21
20 #include <QMutexLocker> 22 #include <QMutexLocker>
21 #include <QFileInfo> 23 #include <QFileInfo>
128 } 130 }
129 131
130 vector<float> 132 vector<float>
131 WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const 133 WavFileReader::getInterleavedFrames(sv_frame_t start, sv_frame_t count) const
132 { 134 {
135 static HitCount lastRead("WavFileReader: last read");
136
133 if (count == 0) return {}; 137 if (count == 0) return {};
134 138
135 QMutexLocker locker(&m_mutex); 139 QMutexLocker locker(&m_mutex);
136 140
137 if (!m_file || !m_channelCount) { 141 if (!m_file || !m_channelCount) {
150 154
151 // Because WaveFileModel::getSummaries() is called separately for 155 // Because WaveFileModel::getSummaries() is called separately for
152 // individual channels, it's quite common for us to be called 156 // individual channels, it's quite common for us to be called
153 // repeatedly for the same data. So this is worth cacheing. 157 // repeatedly for the same data. So this is worth cacheing.
154 if (start == m_lastStart && count == m_lastCount) { 158 if (start == m_lastStart && count == m_lastCount) {
159 lastRead.hit();
155 return m_buffer; 160 return m_buffer;
161 }
162
163 // We don't actually support partial cache reads, but let's use
164 // the term partial to refer to any forward seek and consider a
165 // backward seek to be a miss
166 if (start >= m_lastStart) {
167 lastRead.partial();
168 } else {
169 lastRead.miss();
156 } 170 }
157 171
158 if (sf_seek(m_file, start, SEEK_SET) < 0) { 172 if (sf_seek(m_file, start, SEEK_SET) < 0) {
159 return {}; 173 return {};
160 } 174 }