add skynet.stat() to get cpu cost and message count

This commit is contained in:
Cloud Wu
2016-10-26 17:43:52 +08:00
parent 07a1499886
commit 249ffb9362
10 changed files with 104 additions and 27 deletions

View File

@@ -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
}