Skip to content

Commit efeef65

Browse files
committed
Separately report sleep time
1 parent ad57f55 commit efeef65

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

pg_dtm.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ static void dtm_sleep(timestamp_t interval)
115115
{
116116
struct timespec ts;
117117
struct timespec rem;
118-
#if TRACE_SLEEP_TIME
119-
timestamp_t now = dtm_get_current_time();
120-
#endif
121118
ts.tv_sec = 0;
122119
ts.tv_nsec = interval*1000;
123120

@@ -126,17 +123,6 @@ static void dtm_sleep(timestamp_t interval)
126123
Assert(errno == EINTR);
127124
ts = rem;
128125
}
129-
#if TRACE_SLEEP_TIME
130-
totalSleepTime += dtm_get_current_time() - now;
131-
if (now > prevReportTime + USEC*10) {
132-
prevReportTime = now;
133-
if (firstReportTime == 0) {
134-
firstReportTime = now;
135-
} else {
136-
fprintf(stderr, "Sleep %lu of %lu usec (%f%%)\n", totalSleepTime, now - firstReportTime, totalSleepTime*100.0/(now - firstReportTime));
137-
}
138-
}
139-
#endif
140126
}
141127

142128
static cid_t dtm_get_cid()
@@ -155,7 +141,23 @@ static cid_t dtm_sync(cid_t global_cid)
155141
cid_t local_cid;
156142
while ((local_cid = dtm_get_cid()) < global_cid) {
157143
SpinLockRelease(&local->lock);
144+
#if TRACE_SLEEP_TIME
145+
{
146+
timestamp_t now = dtm_get_current_time();
147+
#endif
158148
dtm_sleep(global_cid - local_cid);
149+
#if TRACE_SLEEP_TIME
150+
totalSleepTime += dtm_get_current_time() - now;
151+
if (now > prevReportTime + USEC*10) {
152+
prevReportTime = now;
153+
if (firstReportTime == 0) {
154+
firstReportTime = now;
155+
} else {
156+
fprintf(stderr, "Sleep %lu of %lu usec (%f%%)\n", totalSleepTime, now - firstReportTime, totalSleepTime*100.0/(now - firstReportTime));
157+
}
158+
}
159+
}
160+
#endif
159161
SpinLockAcquire(&local->lock);
160162
}
161163
return global_cid;
@@ -449,7 +451,23 @@ bool DtmXidInMVCCSnapshot(TransactionId xid, Snapshot snapshot)
449451
{
450452
DTM_TRACE((stderr, "%d: wait for in-doubt transaction %u in snapshot %lu\n", getpid(), xid, dtm_tx.snapshot));
451453
SpinLockRelease(&local->lock);
454+
#if TRACE_SLEEP_TIME
455+
{
456+
timestamp_t now = dtm_get_current_time();
457+
#endif
452458
dtm_sleep(delay);
459+
#if TRACE_SLEEP_TIME
460+
totalSleepTime += dtm_get_current_time() - now;
461+
if (now > prevReportTime + USEC*10) {
462+
prevReportTime = now;
463+
if (firstReportTime == 0) {
464+
firstReportTime = now;
465+
} else {
466+
fprintf(stderr, "Sleep %lu of %lu usec (%f%%)\n", totalSleepTime, now - firstReportTime, totalSleepTime*100.0/(now - firstReportTime));
467+
}
468+
}
469+
}
470+
#endif
453471
if (delay*2 <= MAX_WAIT_TIMEOUT) {
454472
delay *= 2;
455473
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy