mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
add skynet.stat() to get cpu cost and message count
This commit is contained in:
@@ -14,6 +14,8 @@
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#include <sys/time.h>
|
||||
#include <mach/task.h>
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
typedef void (*timer_execute_func)(void *ud,void *arg);
|
||||
@@ -296,3 +298,25 @@ skynet_timer_init(void) {
|
||||
TI->current_point = gettime();
|
||||
}
|
||||
|
||||
// for profile
|
||||
|
||||
#define NANOSEC 1000000000
|
||||
#define MICROSEC 1000000
|
||||
|
||||
uint64_t
|
||||
skynet_thread_time(void) {
|
||||
#if !defined(__APPLE__)
|
||||
struct timespec ti;
|
||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ti);
|
||||
|
||||
return (uint64_t)ti.tv_sec * MICROSEC + (uint64_t)ti.tv_nsec / (NANOSEC / MICROSEC);
|
||||
#else
|
||||
struct task_thread_times_info aTaskInfo;
|
||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
if (KERN_SUCCESS != task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (uint64_t)(aTaskInfo.user_time.seconds) + (uint64_t)aTaskInfo.user_time.microseconds;
|
||||
#endif
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user