问题描述
现在,我正在试图确定一种方法来衡量一个特定功能会采取(类似pthread_create的)的时间。现在,当然,这些类型的功能是非常优化,以尽可能少的时间尽可能;这么少,事实上,使用gettimeofday的用户空间中哪些措施以微秒我的定时器不能充分衡量什么。
Right now, I'm trying to determine a method to measure the time that a particular function will take (something like pthread_create). Now, of course, these types of functions are extremely optimized to take as little time as possible; so little, in fact, that my timer that uses gettimeofday in userspace which measures in microseconds is unable to adequately measure anything.
通常情况下,如果我能惹的内核,我会使用类似get_cycles测量周期的原始数作为性能指标。但是,我还没有找到一种方法在用户空间做到这一点。有没有办法使用get_cycles(或同等),或其他一些高precision定时器,我可以在用户空间用来衡量极快的功能呢?
Normally, if I could mess with the kernel, I'd use something like get_cycles to measure the raw number of cycles as a performance metric. However, I haven't found a way to do this in userspace. Is there a way to use get_cycles (or an equivalent) or some other higher precision timer I could use in userspace to measure extremely fast functions?
推荐答案
clock_gettime
允许你从线程启动一个nanosecond- precise时间,流程启动或时代。
clock_gettime
allows you to get a nanosecond-precise time from the thread start, process start or epoch.
这篇关于在Linux的用户空间的高precision时机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!