mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
function:current time
This commit is contained in:
@@ -32,15 +32,7 @@ struct stat {
|
|||||||
static void
|
static void
|
||||||
_stat_begin(struct stat *S, struct timespec *ti) {
|
_stat_begin(struct stat *S, struct timespec *ti) {
|
||||||
S->count++;
|
S->count++;
|
||||||
#if !defined(__APPLE__)
|
current_time(ti);
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline static void
|
inline static void
|
||||||
|
|||||||
@@ -14,17 +14,26 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec) {
|
current_time(struct timespec *ti) {
|
||||||
struct timespec end;
|
|
||||||
#if !defined(__APPLE__)
|
#if !defined(__APPLE__)
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &end);
|
clock_gettime(CLOCK_THREAD_CPUTIME_ID, ti);
|
||||||
#else
|
#else
|
||||||
struct task_thread_times_info aTaskInfo;
|
struct task_thread_times_info aTaskInfo;
|
||||||
mach_msg_type_number_t aTaskInfoCount = TASK_THREAD_TIMES_INFO_COUNT;
|
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));
|
assert(KERN_SUCCESS == task_info(mach_task_self(), TASK_THREAD_TIMES_INFO, (task_info_t )&aTaskInfo, &aTaskInfoCount));
|
||||||
end.tv_sec = aTaskInfo.user_time.seconds;
|
ti->tv_sec = aTaskInfo.user_time.seconds;
|
||||||
end.tv_nsec = aTaskInfo.user_time.microseconds * 1000;
|
ti->tv_nsec = aTaskInfo.user_time.microseconds * 1000;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec) {
|
||||||
|
if (sec == NULL) {
|
||||||
|
current_time(ti);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
struct timespec end;
|
||||||
|
current_time(&end);
|
||||||
int diffsec = end.tv_sec - ti->tv_sec;
|
int diffsec = end.tv_sec - ti->tv_sec;
|
||||||
assert(diffsec>=0);
|
assert(diffsec>=0);
|
||||||
int diffnsec = end.tv_nsec - ti->tv_nsec;
|
int diffnsec = end.tv_nsec - ti->tv_nsec;
|
||||||
@@ -91,15 +100,7 @@ trace_new(struct trace_pool *p) {
|
|||||||
t->next = NULL;
|
t->next = NULL;
|
||||||
t->ti_sec = 0;
|
t->ti_sec = 0;
|
||||||
t->ti_nsec = 0;
|
t->ti_nsec = 0;
|
||||||
#if !defined(__APPLE__)
|
current_time(&t->ti);
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t->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));
|
|
||||||
t->ti.tv_sec = aTaskInfo.user_time.seconds;
|
|
||||||
t->ti.tv_nsec = aTaskInfo.user_time.microseconds * 1000;
|
|
||||||
#endif
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,15 +154,7 @@ trace_switch(struct trace_pool *p, int session) {
|
|||||||
if (t->next) {
|
if (t->next) {
|
||||||
t->next->prev = prev;
|
t->next->prev = prev;
|
||||||
}
|
}
|
||||||
#if !defined(__APPLE__)
|
current_time(&t->ti);
|
||||||
clock_gettime(CLOCK_THREAD_CPUTIME_ID, &t->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));
|
|
||||||
t->ti.tv_sec = aTaskInfo.user_time.seconds;
|
|
||||||
t->ti.tv_nsec = aTaskInfo.user_time.microseconds * 1000;
|
|
||||||
#endif
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
prev = t;
|
prev = t;
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#define NANOSEC 1000000000
|
#define NANOSEC 1000000000
|
||||||
|
|
||||||
|
void current_time(struct timespec *ti);
|
||||||
void diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec);
|
void diff_time(struct timespec *ti, uint32_t *sec, uint32_t *nsec);
|
||||||
|
|
||||||
struct trace_pool;
|
struct trace_pool;
|
||||||
|
|||||||
Reference in New Issue
Block a user