测量程序启动时动态链接的时间? [英] Measure time taken dynamically linking at program startup?

查看:244
本文介绍了测量程序启动时动态链接的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何衡量在程序启动时动态链接的时间?

How can I measure the time spent dynamically linking at program startup?

我想到的解决方案以及我为什么犹豫:

Solutions that come to mind and why I'm hesitant:

1)在运行程序之前和主程序开始时打印时间。

不考虑在全局变量的main - 初始化和任何结果函数调用之前运行的可能的代码。它不是自动化的开箱即用,很好,它打击我的粗糙和可疑的准确。

This doesn't take into account possible code that runs before main -- initialization of globals and any resulting function calls. It's not automated out of the box and well, it strikes me as crude and of dubious accurately.

2)时间命令一个空的程序,所有的

我不确定这一个。我不知道编译器和链接器是否可以结合基于客户端代码的内容缩写动态链接,但似乎可能。

I'm not sure about this one. I don't know if the compiler and linker can collude to abbreviate dynamic linking based on the contents of client code but it seems possible.

编辑:我重复检查了Google上的明显搜索字词,测量动态链接所花费的时间,并最终作为第一次击中。

6 minutes after asking this I double checked the obvious search terms on Google, "measure time spent dynamically linking", and ended up back here as the first hit.

推荐答案

使用 LD_DEBUG

请尝试:

LD_DEBUG=statistics ./myprog

各种统计数据的简短列表。示例:

It'll output a short list of various statistics. An example:

xenon-lornix:~> LD_DEBUG=statistics ls
     22833:
     22833:     runtime linker statistics:
     22833:       total startup time in dynamic loader: 2500702 clock cycles
     22833:                 time needed for relocation: 757822 clock cycles (30.3%)
     22833:                      number of relocations: 155
     22833:           number of relocations from cache: 8
     22833:             number of relative relocations: 1253
     22833:                time needed to load objects: 1325154 clock cycles (52.9%)

显示有关加载/运行 ls 命令。

Shows info about loading/running the ls command.

使用 LD_DEBUG = help ./myprog 其他可用于 LD_DEBUG 的选项。

Using LD_DEBUG=help ./myprog will show names of other options available to use with LD_DEBUG.

更多信息可以在 ld.so ld-linux.so 手册页实际上是相同的)。 Google搜索可帮助您了解更多详情。

More information can be found in the ld.so, ld-linux.so man pages (these are identical actually). A Google search can help with more specifics.

这篇关于测量程序启动时动态链接的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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