您如何查看ruby中的调用堆栈示例? [英] How do you view a sample of the call stack in ruby?

查看:416
本文介绍了您如何查看ruby中的调用堆栈示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究不同的优化技术,并且偶然发现了这篇文章分析代码效率?谁相信对调用堆栈进行采样比使用探查器更有效.基本思想是,如果您查看调用堆栈,则会看到应用程序大部分时间都花在哪里,然后在那儿进行优化.

I'm investigating different optimization techniques, and I came across this post Analyzing Code for Efficiency? by someone who believes that sampling the call stack is more effective than using a profiler. The basic idea is that if you take a view of the call stack, you see where your application is most likely to be spending most of its time, and then optimize there.

这当然很有趣,他显然是这方面的专家,但是我不知道如何在ruby中查看调用堆栈.在调试器中,我可以说信息堆栈",但似乎只显示一行.

It is certainly interesting, and he is obviously an expert on this, but I don't know how to view the call stack in ruby. In debugger I can say "info stack" but only seems to show one line.

我看到Mike Dunlavey的评论:我想指出的是,如果您在调试器下运行,请手动中断它,并显示调用堆栈..."

I saw this comment by Mike Dunlavey: "I would just like to point out that if you run under the debugger, interrupt it manually, and display the call stack..."

我只是不确定如何手动中断它并浸入调用堆栈.

I'm just not sure how to interrupt it manually and dipslay the call stack.

推荐答案

只需放置

puts caller

代码中的任何位置.如果您不喜欢它的格式,它是一个字符串数组,因此您可以对所需的输出进行一些正则表达式操作.

anywhere in the code. If you don't like its format, it's an array of strings, so you can do some regex manipulation for a desired output.

这篇关于您如何查看ruby中的调用堆栈示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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