spindebug-v1.patch
application/octet-stream
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/storage/lmgr/lwlock.c | 9 | 3 |
| src/backend/storage/lmgr/s_lock.c | 2 | 1 |
| src/include/storage/s_lock.h | 2 | 5 |
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index cc41568..68a182f 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -95,6 +95,7 @@ static int counts_for_pid = 0;
static int *sh_acquire_counts;
static int *ex_acquire_counts;
static int *block_counts;
+static int *spin_counts;
#endif
#ifdef LOCK_DEBUG
@@ -135,10 +136,10 @@ print_lwlock_stats(int code, Datum arg)
for (i = 0; i < numLocks; i++)
{
- if (sh_acquire_counts[i] || ex_acquire_counts[i] || block_counts[i])
- fprintf(stderr, "PID %d lwlock %d: shacq %u exacq %u blk %u\n",
+ if (sh_acquire_counts[i] || ex_acquire_counts[i] || block_counts[i] || spin_counts[i])
+ fprintf(stderr, "PID %d lwlock %d: shacq %u exacq %u blk %u spin %u\n",
MyProcPid, i, sh_acquire_counts[i], ex_acquire_counts[i],
- block_counts[i]);
+ block_counts[i], spin_counts[i]);
}
LWLockRelease(0);
@@ -339,6 +340,7 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
sh_acquire_counts = calloc(numLocks, sizeof(int));
ex_acquire_counts = calloc(numLocks, sizeof(int));
block_counts = calloc(numLocks, sizeof(int));
+ spin_counts = calloc(numLocks, sizeof(int));
counts_for_pid = MyProcPid;
on_shmem_exit(print_lwlock_stats, 0);
}
@@ -388,7 +390,11 @@ LWLockAcquire(LWLockId lockid, LWLockMode mode)
bool mustwait;
/* Acquire mutex. Time spent holding mutex should be short! */
+#ifdef LWLOCK_STATS
+ spin_counts[lockid] += SpinLockAcquire(&lock->mutex);
+#else
SpinLockAcquire(&lock->mutex);
+#endif
/* If retrying, allow LWLockRelease to release waiters again */
if (retry)
diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c
index aa99f49..2dfd105 100644
--- a/src/backend/storage/lmgr/s_lock.c
+++ b/src/backend/storage/lmgr/s_lock.c
@@ -46,7 +46,7 @@ s_lock_stuck(volatile slock_t *lock, const char *file, int line)
/*
* s_lock(lock) - platform-independent portion of waiting for a spinlock.
*/
-void
+int
s_lock(volatile slock_t *lock, const char *file, int line)
{
/*
@@ -155,6 +155,7 @@ s_lock(volatile slock_t *lock, const char *file, int line)
if (spins_per_delay > MIN_SPINS_PER_DELAY)
spins_per_delay = Max(spins_per_delay - 1, MIN_SPINS_PER_DELAY);
}
+ return delays;
}
diff --git a/src/include/storage/s_lock.h b/src/include/storage/s_lock.h
index 074838e..13340ca 100644
--- a/src/include/storage/s_lock.h
+++ b/src/include/storage/s_lock.h
@@ -963,10 +963,7 @@ extern int tas_sema(volatile slock_t *lock);
#if !defined(S_LOCK)
#define S_LOCK(lock) \
- do { \
- if (TAS(lock)) \
- s_lock((lock), __FILE__, __LINE__); \
- } while (0)
+ (TAS(lock) ? s_lock((lock), __FILE__, __LINE__) : 0)
#endif /* S_LOCK */
#if !defined(S_LOCK_FREE)
@@ -1000,7 +997,7 @@ extern int tas(volatile slock_t *lock); /* in port/.../tas.s, or
/*
* Platform-independent out-of-line support routines
*/
-extern void s_lock(volatile slock_t *lock, const char *file, int line);
+extern int s_lock(volatile slock_t *lock, const char *file, int line);
/* Support for dynamic adjustment of spins_per_delay */
#define DEFAULT_SPINS_PER_DELAY 100