用每一行代码的执行时间分析 Rust?

Profiling Rust with execution time for each *line* of code?

我分析了我的 Rust 代码,发现一个处理器密集型函数占用了大部分时间。由于我不能将函数分解成更小的部分,我希望我能看到函数中的哪一行花费了多少时间。目前我已经尝试过 CLion 的 Rust 分析器,但它没有那个功能。

最好在 MacOS 上运行该工具,因为我没有 Windows/Linux 机器(虚拟化除外)。

P.S。 Visual studio 好像有这个功能;但我正在使用 Rust。 https://docs.microsoft.com/en-us/visualstudio/profiling/how-to-collect-line-level-sampling-data?view=vs-2017 它有:

Line-level sampling is the ability of the profiler to determine where in the code of a processor-intensive function, such as a function that has high exclusive samples, the processor has to spend most of its time.

感谢您的任何建议!


EDIT:使用 C++,我确实看到了源代码行级信息。例如,下面的玩具表明,“for”循环在大函数中占用了大部分时间。但是我正在使用 Rust...

一旦编译,Rust 的“行”就不存在了。优化器通过完全重组您编写的代码并找到表现与您预期的相同的最小机器代码来完成它的工作。

函数通常是内联的,因此即使测量在函数中花费的时间也可能会给出不正确的结果 - 或者如果您阻止程序被内联这样做,则会改变程序的性能特征。