Skip to content

Commit e950829

Browse files
authored
IC: collect stats on how long we wait for imageinput mutexes (#1779)
1 parent becd840 commit e950829

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

src/libtexture/imagecache.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ ImageCacheFile::ImageCacheFile (ImageCacheImpl &imagecache,
288288
m_is_udim(false),
289289
m_tilesread(0), m_bytesread(0),
290290
m_redundant_tiles(0), m_redundant_bytesread(0),
291-
m_timesopened(0), m_iotime(0),
291+
m_timesopened(0), m_iotime(0), m_mutex_wait_time(0),
292292
m_mipused(false), m_validspec(false), m_errors_issued(0),
293293
m_imagecache(imagecache), m_duplicate(NULL),
294294
m_total_imagesize(0),
@@ -707,7 +707,9 @@ ImageCacheFile::read_tile (ImageCachePerThreadInfo *thread_info,
707707
TypeDesc format, void *data)
708708
{
709709
ASSERT (chend > chbegin);
710+
Timer input_mutex_timer;
710711
recursive_lock_guard guard (m_input_mutex);
712+
m_mutex_wait_time += input_mutex_timer();
711713

712714
if (! m_input && !m_broken) {
713715
// The file is already in the file cache, but the handle is
@@ -716,10 +718,10 @@ ImageCacheFile::read_tile (ImageCachePerThreadInfo *thread_info,
716718
// But wait, it's possible that somebody else is waiting on our
717719
// m_input_mutex, which we locked above. To avoid deadlock, we
718720
// need to release m_input_mutex while we close files.
719-
m_input_mutex.unlock ();
721+
unlock_input_mutex ();
720722
imagecache().check_max_files (thread_info);
721723
// Now we're back, whew! Grab the lock again.
722-
m_input_mutex.lock ();
724+
lock_input_mutex ();
723725
}
724726

725727
bool ok = open (thread_info);
@@ -1035,7 +1037,9 @@ ImageCacheFile::close ()
10351037
void
10361038
ImageCacheFile::release ()
10371039
{
1040+
Timer input_mutex_timer;
10381041
recursive_lock_guard guard (m_input_mutex);
1042+
m_mutex_wait_time += input_mutex_timer();
10391043
if (m_used)
10401044
m_used = false;
10411045
else
@@ -1047,7 +1051,9 @@ ImageCacheFile::release ()
10471051
void
10481052
ImageCacheFile::invalidate ()
10491053
{
1054+
Timer input_mutex_timer;
10501055
recursive_lock_guard guard (m_input_mutex);
1056+
m_mutex_wait_time += input_mutex_timer();
10511057
close ();
10521058
invalidate_spec ();
10531059
mark_not_broken ();
@@ -1205,7 +1211,9 @@ ImageCacheImpl::verify_file (ImageCacheFile *tf,
12051211
Timer timer;
12061212
if (! thread_info)
12071213
thread_info = get_perthread_info ();
1214+
Timer input_mutex_timer;
12081215
recursive_lock_guard guard (tf->m_input_mutex);
1216+
tf->m_mutex_wait_time += input_mutex_timer();
12091217
if (! tf->validspec()) {
12101218
tf->open (thread_info);
12111219
DASSERT (tf->m_broken || tf->validspec());
@@ -1697,6 +1705,7 @@ ImageCacheImpl::getstats (int level) const
16971705
size_t total_untiled = 0, total_unmipped = 0, total_duplicates = 0;
16981706
size_t total_constant = 0;
16991707
double total_iotime = 0;
1708+
double total_input_mutex_wait_time = 0;
17001709
std::vector<ImageCacheFileRef> files;
17011710
{
17021711
for (FilenameMap::iterator f = m_files.begin(); f != m_files.end(); ++f) {
@@ -1708,6 +1717,7 @@ ImageCacheImpl::getstats (int level) const
17081717
total_redundant_bytes += file->redundant_bytesread();
17091718
total_bytes += file->bytesread();
17101719
total_iotime += file->iotime();
1720+
total_input_mutex_wait_time += file->m_mutex_wait_time;
17111721
if (file->duplicate()) {
17121722
++total_duplicates;
17131723
continue;
@@ -1788,6 +1798,8 @@ ImageCacheImpl::getstats (int level) const
17881798
}
17891799
if (stats.file_locking_time > 0.001)
17901800
out << " File mutex locking time : " << Strutil::timeintervalformat (stats.file_locking_time) << "\n";
1801+
if (total_input_mutex_wait_time > 0.001)
1802+
out << " ImageInput mutex locking time : " << Strutil::timeintervalformat (total_input_mutex_wait_time) << "\n";
17911803
if (m_stat_tiles_created > 0) {
17921804
out << " Tiles: " << m_stat_tiles_created << " created, " << m_stat_tiles_current << " current, " << m_stat_tiles_peak << " peak\n";
17931805
out << " total tile requests : " << stats.find_tile_calls << "\n";
@@ -3222,7 +3234,9 @@ ImageCacheImpl::invalidate_all (bool force)
32223234
fileit != e; ++fileit) {
32233235
ImageCacheFileRef &f (fileit->second);
32243236
ustring name = f->filename();
3237+
Timer input_mutex_timer;
32253238
recursive_lock_guard guard (f->m_input_mutex);
3239+
f->m_mutex_wait_time += input_mutex_timer();
32263240
// If the file was broken when we opened it, or if it no longer
32273241
// exists, definitely invalidate it.
32283242
if (f->broken() || ! Filesystem::exists(name.string())) {

src/libtexture/imagecache_pvt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#include <OpenImageIO/hash.h>
4949
#include <OpenImageIO/imagebuf.h>
5050
#include <OpenImageIO/unordered_map_concurrent.h>
51+
#include <OpenImageIO/timer.h>
5152

5253

5354
OIIO_NAMESPACE_BEGIN
@@ -355,6 +356,7 @@ class OIIO_API ImageCacheFile : public RefCnt {
355356
atomic_ll m_redundant_bytesread;///< Redundant bytes read
356357
size_t m_timesopened; ///< Separate times we opened this file
357358
double m_iotime; ///< I/O time for this file
359+
double m_mutex_wait_time; ///< Wait time for m_input_mutex
358360
bool m_mipused; ///< MIP level >0 accessed
359361
volatile bool m_validspec; ///< If false, reread spec upon open
360362
mutable int m_errors_issued; ///< Errors issued for this file
@@ -380,7 +382,9 @@ class OIIO_API ImageCacheFile : public RefCnt {
380382

381383
/// Force the file to open, thread-safe.
382384
bool forceopen (ImageCachePerThreadInfo *thread_info) {
385+
Timer input_mutex_timer;
383386
recursive_lock_guard guard (m_input_mutex);
387+
m_mutex_wait_time += input_mutex_timer();
384388
return open (thread_info);
385389
}
386390

@@ -403,7 +407,9 @@ class OIIO_API ImageCacheFile : public RefCnt {
403407
int chbegin, int chend, TypeDesc format, void *data);
404408

405409
void lock_input_mutex () {
410+
Timer input_mutex_timer;
406411
m_input_mutex.lock ();
412+
m_mutex_wait_time += input_mutex_timer();
407413
}
408414

409415
void unlock_input_mutex () {

0 commit comments

Comments
 (0)