@@ -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 ()
10351037void
10361038ImageCacheFile::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 ()
10471051void
10481052ImageCacheFile::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 ())) {
0 commit comments