mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add skynet command MQLEN for debug
This commit is contained in:
@@ -526,6 +526,7 @@ function dbgcmd.STAT()
|
||||
query_state(stat, "count")
|
||||
query_state(stat, "time")
|
||||
stat.boottime = debug.getregistry().skynet_boottime
|
||||
stat.mqlen = skynet.mqlen()
|
||||
skynet.ret(skynet.pack(stat))
|
||||
end
|
||||
|
||||
@@ -692,4 +693,8 @@ function skynet.monitor(service, query)
|
||||
c.command("MONITOR", string.format(":%08x", monitor))
|
||||
end
|
||||
|
||||
function skynet.mqlen()
|
||||
return tonumber(c.command "MQLEN")
|
||||
end
|
||||
|
||||
return skynet
|
||||
|
||||
@@ -109,6 +109,19 @@ skynet_mq_handle(struct message_queue *q) {
|
||||
return q->handle;
|
||||
}
|
||||
|
||||
int
|
||||
skynet_mq_length(struct message_queue *q) {
|
||||
int head, tail;
|
||||
LOCK(q)
|
||||
head = q->head;
|
||||
tail = q->tail;
|
||||
UNLOCK(q)
|
||||
|
||||
if (head <= tail) {
|
||||
return tail - head;
|
||||
}
|
||||
return tail + q->cap - head;
|
||||
}
|
||||
|
||||
int
|
||||
skynet_mq_pop(struct message_queue *q, struct skynet_message *message) {
|
||||
|
||||
@@ -26,6 +26,9 @@ void skynet_mq_push(struct message_queue *q, struct skynet_message *message);
|
||||
void skynet_mq_lock(struct message_queue *q, int session);
|
||||
void skynet_mq_unlock(struct message_queue *q);
|
||||
|
||||
// return the length of message queue, for debug
|
||||
int skynet_mq_length(struct message_queue *q);
|
||||
|
||||
void skynet_mq_force_push(struct message_queue *q);
|
||||
void skynet_mq_pushglobal(struct message_queue *q);
|
||||
|
||||
|
||||
@@ -563,6 +563,12 @@ skynet_command(struct skynet_context * context, const char * cmd , const char *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcmp(cmd, "MQLEN") == 0) {
|
||||
int len = skynet_mq_length(context->queue);
|
||||
sprintf(context->result, "%d", len);
|
||||
return context->result;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user