@@ -288,7 +288,7 @@ ImageCacheFile::ImageCacheFile (ImageCacheImpl &imagecache,
288
288
m_is_udim(false ),
289
289
m_tilesread(0 ), m_bytesread(0 ),
290
290
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 ),
292
292
m_mipused(false ), m_validspec(false ), m_errors_issued(0 ),
293
293
m_imagecache(imagecache), m_duplicate(NULL ),
294
294
m_total_imagesize(0 ),
@@ -707,7 +707,9 @@ ImageCacheFile::read_tile (ImageCachePerThreadInfo *thread_info,
707
707
TypeDesc format, void *data)
708
708
{
709
709
ASSERT (chend > chbegin);
710
+ Timer input_mutex_timer;
710
711
recursive_lock_guard guard (m_input_mutex);
712
+ m_mutex_wait_time += input_mutex_timer ();
711
713
712
714
if (! m_input && !m_broken) {
713
715
// The file is already in the file cache, but the handle is
@@ -716,10 +718,10 @@ ImageCacheFile::read_tile (ImageCachePerThreadInfo *thread_info,
716
718
// But wait, it's possible that somebody else is waiting on our
717
719
// m_input_mutex, which we locked above. To avoid deadlock, we
718
720
// need to release m_input_mutex while we close files.
719
- m_input_mutex. unlock ();
721
+ unlock_input_mutex ();
720
722
imagecache ().check_max_files (thread_info);
721
723
// Now we're back, whew! Grab the lock again.
722
- m_input_mutex. lock ();
724
+ lock_input_mutex ();
723
725
}
724
726
725
727
bool ok = open (thread_info);
@@ -1035,7 +1037,9 @@ ImageCacheFile::close ()
1035
1037
void
1036
1038
ImageCacheFile::release ()
1037
1039
{
1040
+ Timer input_mutex_timer;
1038
1041
recursive_lock_guard guard (m_input_mutex);
1042
+ m_mutex_wait_time += input_mutex_timer ();
1039
1043
if (m_used)
1040
1044
m_used = false ;
1041
1045
else
@@ -1047,7 +1051,9 @@ ImageCacheFile::release ()
1047
1051
void
1048
1052
ImageCacheFile::invalidate ()
1049
1053
{
1054
+ Timer input_mutex_timer;
1050
1055
recursive_lock_guard guard (m_input_mutex);
1056
+ m_mutex_wait_time += input_mutex_timer ();
1051
1057
close ();
1052
1058
invalidate_spec ();
1053
1059
mark_not_broken ();
@@ -1205,7 +1211,9 @@ ImageCacheImpl::verify_file (ImageCacheFile *tf,
1205
1211
Timer timer;
1206
1212
if (! thread_info)
1207
1213
thread_info = get_perthread_info ();
1214
+ Timer input_mutex_timer;
1208
1215
recursive_lock_guard guard (tf->m_input_mutex );
1216
+ tf->m_mutex_wait_time += input_mutex_timer ();
1209
1217
if (! tf->validspec ()) {
1210
1218
tf->open (thread_info);
1211
1219
DASSERT (tf->m_broken || tf->validspec ());
@@ -1697,6 +1705,7 @@ ImageCacheImpl::getstats (int level) const
1697
1705
size_t total_untiled = 0 , total_unmipped = 0 , total_duplicates = 0 ;
1698
1706
size_t total_constant = 0 ;
1699
1707
double total_iotime = 0 ;
1708
+ double total_input_mutex_wait_time = 0 ;
1700
1709
std::vector<ImageCacheFileRef> files;
1701
1710
{
1702
1711
for (FilenameMap::iterator f = m_files.begin (); f != m_files.end (); ++f) {
@@ -1708,6 +1717,7 @@ ImageCacheImpl::getstats (int level) const
1708
1717
total_redundant_bytes += file->redundant_bytesread ();
1709
1718
total_bytes += file->bytesread ();
1710
1719
total_iotime += file->iotime ();
1720
+ total_input_mutex_wait_time += file->m_mutex_wait_time ;
1711
1721
if (file->duplicate ()) {
1712
1722
++total_duplicates;
1713
1723
continue ;
@@ -1788,6 +1798,8 @@ ImageCacheImpl::getstats (int level) const
1788
1798
}
1789
1799
if (stats.file_locking_time > 0.001 )
1790
1800
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 " ;
1791
1803
if (m_stat_tiles_created > 0 ) {
1792
1804
out << " Tiles: " << m_stat_tiles_created << " created, " << m_stat_tiles_current << " current, " << m_stat_tiles_peak << " peak\n " ;
1793
1805
out << " total tile requests : " << stats.find_tile_calls << " \n " ;
@@ -3222,7 +3234,9 @@ ImageCacheImpl::invalidate_all (bool force)
3222
3234
fileit != e; ++fileit) {
3223
3235
ImageCacheFileRef &f (fileit->second );
3224
3236
ustring name = f->filename ();
3237
+ Timer input_mutex_timer;
3225
3238
recursive_lock_guard guard (f->m_input_mutex );
3239
+ f->m_mutex_wait_time += input_mutex_timer ();
3226
3240
// If the file was broken when we opened it, or if it no longer
3227
3241
// exists, definitely invalidate it.
3228
3242
if (f->broken () || ! Filesystem::exists (name.string ())) {
0 commit comments