|
39 | 39 |
|
40 | 40 | #define USEC 1000000 |
41 | 41 |
|
| 42 | +#define TRACE_SLEEP_TIME 1 |
| 43 | + |
42 | 44 | typedef uint64 timestamp_t; |
43 | 45 |
|
44 | 46 | typedef struct DtmTransStatus |
@@ -72,7 +74,10 @@ static HTAB* xid2status; |
72 | 74 | static HTAB* gtid2xid; |
73 | 75 | static DtmNodeState* local; |
74 | 76 | static DtmTransState dtm_tx; |
75 | | - |
| 77 | +static timestamp_t firstReportTime; |
| 78 | +static timestamp_t prevReportTime; |
| 79 | +static timestamp_t totalSleepTime; |
| 80 | +static uint64 totalSleepInterrupts; |
76 | 81 | static int DtmVacuumDelay; |
77 | 82 |
|
78 | 83 | static Snapshot DtmGetSnapshot(Snapshot snapshot); |
@@ -110,12 +115,28 @@ static void dtm_sleep(timestamp_t interval) |
110 | 115 | { |
111 | 116 | struct timespec ts; |
112 | 117 | 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 |
| 121 | + ts.tv_sec = 0; |
| 122 | + ts.tv_nsec = interval*1000; |
| 123 | + |
115 | 124 | while (nanosleep(&ts, &rem) < 0) { |
| 125 | + totalSleepInterrupts += 1; |
116 | 126 | Assert(errno == EINTR); |
117 | 127 | ts = rem; |
118 | 128 | } |
| 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 |
119 | 140 | } |
120 | 141 |
|
121 | 142 | static cid_t dtm_get_cid() |
|
0 commit comments