perf中的时间戳是什么意思? [英] What is meaning of timestamp in perf?

查看:160
本文介绍了perf中的时间戳是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用perf"来衡量函数的实际执行时间."perf脚本"命令在调用函数时提供时间戳.

I'd like to use 'perf' to measure real execution time of a function. 'perf script' command gives timestamp when the function is called.

Xorg  1523 [001] 25712.423702:    probe:sock_write_iter: (ffffffff95cd8b80)

时间戳字段的格式为 X.Y .我如何理解这个价值?是X.Y秒吗?

The timestamp field's format is X.Y. How can I understand this value? Is it X.Y seconds?

推荐答案

X.Y 是时间戳,单位为 seconds.microseconds .

该值的显示方式可以查看

How this value is displayed can be looked at here. You can pass the switch --ns to perf script to display the timestamps in seconds.nanoseconds format too.

要了解此值,您需要了解 perf 模块如何计算时间戳.您可以将每个事件与不同的时钟函数关联以计算时间戳.默认情况下, perf 使用 sched_clock 函数计算事件的时间戳,更多详细信息

To understand this value, you need to understand how the perf module calculates timestamps. You can associate each event with a different clock function to compute the timestamps. By default, perf uses sched_clock function to compute timestamps for an event, more details here.

event->clock = &local_clock;

但是您可以将 -k 开关与 perf record 命令一起使用,以将事件与各种时标关联.

But you can use the -k switch along with perf record command to associate an event with various clockids.

-k, --clockid
           Sets the clock id to use for the various time fields in the
           perf_event_type records. See clock_gettime(). In particular
           CLOCK_MONOTONIC and CLOCK_MONOTONIC_RAW are supported, some
           events might also allow CLOCK_BOOTTIME, CLOCK_REALTIME and
           CLOCK_TAI.

-k 开关添加到 perf record 命令将启用各种时钟功能,具体取决于您使用的时标,如

Adding the -k switch to perf record command will enable various clock functions depending on which clockid you use, as can be seen here.

sched_clock 函数应返回自系统启动以来的纳秒数.特定的体系结构可能会或可能不会单独提供 sched_clock()的实现.如果未提供本地实现,则系统jiffy计数器将用作 sched_clock().

sched_clock function shall return the number of nanoseconds since the system was started. A particular architecture may or may not provide an implementation of sched_clock() on its own. The system jiffy counter will be used as sched_clock(), if a local implementation is not provided.

请注意,以上所有代码段均适用于 Linux内核5.6.7 .

Note that, all of the above code snippets are for Linux kernel 5.6.7.

这篇关于perf中的时间戳是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆