简体   繁体   English

理解clock_gettime()的不同时钟

[英]Understanding the different clocks of clock_gettime()

Hi I wanted to use the clock_gettime() function for measuring the performance of my code. 嗨,我想使用clock_gettime()函数来测量我的代码的性能。

I am unable to understand the difference between the different kinds of clocks used in the function from the man page descriptions. 我无法理解手册页描述中函数中使用的各种时钟之间的区别。 esp ESP

CLOCK_REALTIME,

CLOCK_PROCESS_CPUTIME_ID

CLOCK_THREAD_CPUTIME_ID

Can someone explaing what each of these clocks do? 有人可以解释每个钟表的作用吗?

CLOCK_REALTIME reports the actual wall clock time. CLOCK_REALTIME报告实际的挂钟时间。

CLOCK_MONOTONIC is for measuring relative real time. CLOCK_MONOTONIC用于测量相对实时。 It advances at the same rate as the actual flow of time but it's not subject to discontinuities from manual or automatic (NTP) adjustments to the system clock. 它以与实际时间流相同的速率前进,但不会受到系统时钟的手动或自动(NTP)调整的不连续性影响。

CLOCK_PROCESS_CPUTIME_ID is for measuring the amount of CPU time consumed by the process. CLOCK_PROCESS_CPUTIME_ID用于测量进程消耗的CPU时间量。

CLOCK_THREAD_CPUTIME_ID is for measuring the amount of CPU time consumed by the thread. CLOCK_THREAD_CPUTIME_ID用于测量线程消耗的CPU时间量。 It's supported by modern kernels and glibc since 2.6.12, but on older linux kernels glibc emulates it badly by simply returning the amount of CPU time consumed by the process since the moment the thread was created. 它得到了自2.6.12以来的现代内核和glibc的支持,但是在较旧的Linux内核上,glibc通过简单地返回自创建线程之后的进程消耗的CPU时间量来严重模拟它。

http://man7.org/linux/man-pages/man2/clock_gettime.2.html http://man7.org/linux/man-pages/man2/clock_gettime.2.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM