Skip to content

Commit fe0d923

Browse files
committed
Trace sleep time
1 parent 4c26d45 commit fe0d923

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

contrib/pg_dtm/sockhub/sockhub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ void ShubLoop(Shub* shub)
469469
if (shub->params->delay != 0) {
470470
continue;
471471
}
472-
}
472+
}
473473
if (shub->in_buffer_used != 0) { /* if buffer is not empty... */
474474
/* ...then send it */
475475
#if SHOW_SENT_STATISTIC

contrib/pg_tsdtm/pg_dtm.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939

4040
#define USEC 1000000
4141

42+
#define TRACE_SLEEP_TIME 1
43+
4244
typedef uint64 timestamp_t;
4345

4446
typedef struct DtmTransStatus
@@ -72,7 +74,10 @@ static HTAB* xid2status;
7274
static HTAB* gtid2xid;
7375
static DtmNodeState* local;
7476
static DtmTransState dtm_tx;
75-
77+
static timestamp_t firstReportTime;
78+
static timestamp_t prevReportTime;
79+
static timestamp_t totalSleepTime;
80+
static uint64 totalSleepInterrupts;
7681
static int DtmVacuumDelay;
7782

7883
static Snapshot DtmGetSnapshot(Snapshot snapshot);
@@ -110,12 +115,25 @@ static void dtm_sleep(timestamp_t interval)
110115
{
111116
struct timespec ts;
112117
struct timespec rem;
113-
ts.tv_sec = interval / USEC;
114-
ts.tv_nsec = interval % USEC * 1000;
118+
#if TRACE_SLEEP_TIME
119+
timestamp_t now = dtm_get_current_time();
120+
#endif
115121
while (nanosleep(&ts, &rem) < 0) {
122+
totalSleepInterrupts += 1;
116123
Assert(errno == EINTR);
117124
ts = rem;
118125
}
126+
#if TRACE_SLEEP_TIME
127+
totalSleepTime += dtm_get_current_time() - now;
128+
if (now > prevReportTime + USEC*10) {
129+
prevReportTime = now;
130+
if (firstReportTime == 0) {
131+
firstReportTime = now;
132+
} else {
133+
fprintf(stderr, "Sleep %lu of %lu usec (%f%%)\n", totalSleepTime, now - firstReportTime, totalSleepTime*100.0/firstReportTime);
134+
}
135+
}
136+
#endif
119137
}
120138

121139
static cid_t dtm_get_cid()

0 commit comments

Comments
 (0)