@@ -95,6 +95,7 @@ static int counts_for_pid = 0;
95
95
static int * sh_acquire_counts ;
96
96
static int * ex_acquire_counts ;
97
97
static int * block_counts ;
98
+ static int * spin_delay_counts ;
98
99
#endif
99
100
100
101
#ifdef LOCK_DEBUG
@@ -134,6 +135,7 @@ init_lwlock_stats(void)
134
135
135
136
sh_acquire_counts = calloc (numLocks , sizeof (int ));
136
137
ex_acquire_counts = calloc (numLocks , sizeof (int ));
138
+ spin_delay_counts = calloc (numLocks , sizeof (int ));
137
139
block_counts = calloc (numLocks , sizeof (int ));
138
140
counts_for_pid = MyProcPid ;
139
141
on_shmem_exit (print_lwlock_stats , 0 );
@@ -151,10 +153,10 @@ print_lwlock_stats(int code, Datum arg)
151
153
152
154
for (i = 0 ; i < numLocks ; i ++ )
153
155
{
154
- if (sh_acquire_counts [i ] || ex_acquire_counts [i ] || block_counts [i ])
155
- fprintf (stderr , "PID %d lwlock %d: shacq %u exacq %u blk %u\n" ,
156
+ if (sh_acquire_counts [i ] || ex_acquire_counts [i ] || block_counts [i ] || spin_delay_counts [ i ] )
157
+ fprintf (stderr , "PID %d lwlock %d: shacq %u exacq %u blk %u spindelay %u \n" ,
156
158
MyProcPid , i , sh_acquire_counts [i ], ex_acquire_counts [i ],
157
- block_counts [i ]);
159
+ block_counts [i ], spin_delay_counts [ i ] );
158
160
}
159
161
160
162
LWLockRelease (0 );
@@ -395,7 +397,11 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
395
397
bool mustwait ;
396
398
397
399
/* Acquire mutex. Time spent holding mutex should be short! */
400
+ #ifdef LWLOCK_STATS
401
+ spin_delay_counts [lockid ] += SpinLockAcquire (& lock -> mutex );
402
+ #else
398
403
SpinLockAcquire (& lock -> mutex );
404
+ #endif
399
405
400
406
/* If retrying, allow LWLockRelease to release waiters again */
401
407
if (retry )
0 commit comments