From 576b6a89d5d66fd918b92b778123bb39b456a6c9 Mon Sep 17 00:00:00 2001 From: yuangongji <82787816@qq.com> Date: Thu, 30 May 2019 12:49:20 +0800 Subject: [PATCH] add debug interface timeouts_pendings() --- timeout.c | 14 ++++++++++++++ timeout.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/timeout.c b/timeout.c index e78f57d..76a47c1 100644 --- a/timeout.c +++ b/timeout.c @@ -622,6 +622,20 @@ TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *T, FILE *fp) { return 1; } /* timeouts_check() */ +#ifdef DEBUG +TIMEOUT_PUBLIC int timeouts_pendings(struct timeouts *T, uint64_t **pendings) { + int i; + if (pendings) { + *pendings = (uint64_t *)malloc(sizeof(uint64_t) * WHEEL_NUM); + for (i = 0; i < WHEEL_NUM; i++) { + (*pendings)[i] = T->pending[i]; + } + return WHEEL_NUM; + } + return 0; +} /* timeouts_pendings() */ +#endif + #define ENTER \ do { \ diff --git a/timeout.h b/timeout.h index 3ef76e9..369c532 100644 --- a/timeout.h +++ b/timeout.h @@ -198,6 +198,12 @@ TIMEOUT_PUBLIC bool timeouts_expired(struct timeouts *); TIMEOUT_PUBLIC bool timeouts_check(struct timeouts *, FILE *); /* return true if invariants hold. describes failures to optional file handle. */ +#ifdef DEBUG +TIMEOUT_PUBLIC int timeouts_pendings(struct timeouts *, uint64_t **); +/* return timing wheel number. copy pendings of all wheels to malloced memory + * (which need free by yourself). */ +#endif + #define TIMEOUTS_PENDING 0x10 #define TIMEOUTS_EXPIRED 0x20 #define TIMEOUTS_ALL (TIMEOUTS_PENDING|TIMEOUTS_EXPIRED)