Skip to content

Commit f2a1010

Browse files
authored
fix(ImageCache): Avoid bad IC stats when no files were read (#3765)
1 parent a8b93f0 commit f2a1010

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/libtexture/imagecache.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,8 @@ ImageCacheImpl::getstats(int level) const
18751875
spin_lock lock(m_perthread_info_mutex);
18761876
size_t nthreads = m_all_perthread_info.size();
18771877
if (nthreads > 1 || level > 2) {
1878-
double perthreadtime = stats.fileio_time / (float)nthreads;
1878+
double perthreadtime = stats.fileio_time
1879+
/ std::max(size_t(1), nthreads);
18791880
print(out, " ({} average per thread, for {} threads)",
18801881
Strutil::timeintervalformat(perthreadtime), nthreads);
18811882
}
@@ -1895,14 +1896,16 @@ ImageCacheImpl::getstats(int level) const
18951896
m_stat_tiles_created, m_stat_tiles_current,
18961897
m_stat_tiles_peak);
18971898
print(out, " total tile requests : {}\n", stats.find_tile_calls);
1898-
print(out, " micro-cache misses : {} ({:.1f}%)\n",
1899-
stats.find_tile_microcache_misses,
1900-
100.0 * stats.find_tile_microcache_misses
1901-
/ (double)stats.find_tile_calls);
1902-
print(out, " main cache misses : {} ({:.1f}%)\n",
1903-
stats.find_tile_cache_misses,
1904-
100.0 * stats.find_tile_cache_misses
1905-
/ (double)stats.find_tile_calls);
1899+
if (stats.find_tile_microcache_misses)
1900+
print(out, " micro-cache misses : {} ({:.1f}%)\n",
1901+
stats.find_tile_microcache_misses,
1902+
100.0 * stats.find_tile_microcache_misses
1903+
/ (double)stats.find_tile_calls);
1904+
if (stats.find_tile_cache_misses)
1905+
print(out, " main cache misses : {} ({:.1f}%)\n",
1906+
stats.find_tile_cache_misses,
1907+
100.0 * stats.find_tile_cache_misses
1908+
/ (double)stats.find_tile_calls);
19061909
print(out, " redundant reads: {} tiles, {}\n",
19071910
total_redundant_tiles,
19081911
Strutil::memformat(total_redundant_bytes));
@@ -2011,11 +2014,13 @@ ImageCacheImpl::getstats(int level) const
20112014
nprinted, r, mb, file->iotime(),
20122015
onefile_stat_line(file, -1, false));
20132016
}
2014-
if (nprinted == 0)
2017+
if (nprinted == 0) {
20152018
print(out, " (nothing took more than 0.25s)\n");
2016-
double fast = files.back()->bytesread() / (1024.0 * 1024.0)
2017-
/ files.back()->iotime();
2018-
print(out, " (fastest was {:.1f} MB/s)\n", fast);
2019+
} else {
2020+
double fast = files.back()->bytesread() / (1024.0 * 1024.0)
2021+
/ files.back()->iotime();
2022+
print(out, " (fastest was {:.1f} MB/s)\n", fast);
2023+
}
20192024
if (total_redundant_tiles > 0) {
20202025
std::sort(files.begin(), files.end(), redundantbytes_compare);
20212026
print(out, " Top files by redundant I/O:\n");

0 commit comments

Comments
 (0)