mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
debug stat report boot time
This commit is contained in:
@@ -28,10 +28,6 @@ current_time(struct timespec *ti) {
|
|||||||
|
|
||||||
void
|
void
|
||||||
diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec) {
|
diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec) {
|
||||||
if (sec == NULL) {
|
|
||||||
current_time(ti);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
struct timespec end;
|
struct timespec end;
|
||||||
current_time(&end);
|
current_time(&end);
|
||||||
int diffsec = end.tv_sec - ti->tv_sec;
|
int diffsec = end.tv_sec - ti->tv_sec;
|
||||||
|
|||||||
@@ -509,6 +509,7 @@ function dbgcmd.STAT()
|
|||||||
local stat = {}
|
local stat = {}
|
||||||
query_state(stat, "count")
|
query_state(stat, "count")
|
||||||
query_state(stat, "time")
|
query_state(stat, "time")
|
||||||
|
stat.boottime = debug.getregistry().skynet_boottime
|
||||||
skynet.ret(skynet.pack(stat))
|
skynet.ret(skynet.pack(stat))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,42 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
// time
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#define NANOSEC 1000000000
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
#include <mach/task.h>
|
||||||
|
#include <mach/mach.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static void
|
||||||
|
current_time(struct timespec *ti) {
|
||||||
|
#if !defined(__APPLE__)
|
||||||
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ti);
|
||||||
|
#else
|
||||||
|
struct task_thread_times_info aTaskInfo;
|
||||||
|
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||||
|
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||||
|
ti->tv_sec = aTaskInfo.user_time.seconds;
|
||||||
|
ti->tv_nsec = aTaskInfo.user_time.microseconds * 1000;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static double
|
||||||
|
diff_time(struct timespec *ti) {
|
||||||
|
struct timespec end;
|
||||||
|
current_time(&end);
|
||||||
|
int diffsec = end.tv_sec - ti->tv_sec;
|
||||||
|
int diffnsec = end.tv_nsec - ti->tv_nsec;
|
||||||
|
if (diffnsec < 0) {
|
||||||
|
--diffsec;
|
||||||
|
diffnsec += NANOSEC;
|
||||||
|
}
|
||||||
|
return (double)diffsec + (double)diffnsec / NANOSEC;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_try_load(lua_State *L, const char * path, int pathlen, const char * name) {
|
_try_load(lua_State *L, const char * path, int pathlen, const char * name) {
|
||||||
int namelen = strlen(name);
|
int namelen = strlen(name);
|
||||||
@@ -178,7 +214,13 @@ _launch(struct skynet_context * context, void *ud, int type, int session, uint32
|
|||||||
assert(type == 0 && session == 0);
|
assert(type == 0 && session == 0);
|
||||||
struct snlua *l = ud;
|
struct snlua *l = ud;
|
||||||
skynet_callback(context, NULL, NULL);
|
skynet_callback(context, NULL, NULL);
|
||||||
if (_init(l, context, msg)) {
|
struct timespec ti;
|
||||||
|
current_time(&ti);
|
||||||
|
int err = _init(l, context, msg);
|
||||||
|
double t = diff_time(&ti);
|
||||||
|
lua_pushnumber(l->L, t);
|
||||||
|
lua_setfield(l->L, LUA_REGISTRYINDEX, "skynet_boottime");
|
||||||
|
if (err) {
|
||||||
skynet_command(context, "EXIT", NULL);
|
skynet_command(context, "EXIT", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user