简体   繁体   English

使用Chrome开发工具在JavaScript中查找无限(或非常大)的循环

[英]Finding an infinite (or very large) loop in JavaScript using Chrome Dev Tools

I'm using a third party statistics library which seems to have loads of issues. 我正在使用第三方统计库,似乎有很多问题。 It's both large and compressed, so it's not particularly easy to debug. 它既大又压缩,因此调试起来并不是特别容易。 I'm using the Chrome Dev Tools and I was wondering what options there might be for ranking functions by the number of calls by their name, maybe? 我正在使用Chrome开发工具,我想知道可能有什么选项可以通过名字的呼叫次数对功能进行排名? I thought the answer was the Profiler tab, but the profiles I captured are only documenting the JS files referencing "line 1" in long chains. 我认为答案是Profiler选项卡,但我捕获的配置文件只记录了长链中引用“第1行”的JS文件。

This thing is freezing my app and I'd rather avoid making changes to their code as much as possible, even if its for the sake of debugging. 这个东西冻结我的应用程序,我宁愿尽可能避免更改他们的代码,即使它是为了调试。 I'm happy to clarify anything that's not clear. 我很乐意澄清任何不清楚的事情。

EDIT: I seem to remember a recent demo of chrome dev tools somewhere showing a timeline that depicted function blocks stacked vertically based on the time increment going horizontally called "flame charts" or something similar... That would be ideal, but I can't remember the link right now for the life of me. 编辑:我似乎记得最近一个chrome dev工具的演示,显示了一个时间线,描绘了根据水平时间增量垂直堆叠的功能块,称为“火焰图”或类似的东西......这将是理想的,但我可以'记住我现在生活中的链接。 Not opposed to using Canary on this one at all if anyone knows what this tool is? 如果有人知道这个工具是什么,不反对在这个上使用Canary吗?

The latest video about DevTools is here http://youtu.be/x6qe_kVaBpg?t=19m44s 关于DevTools的最新视频在这里http://youtu.be/x6qe_kVaBpg?t=19m44s

It covers different topics about DevTools and includes a section about CPU profile too. 它涵盖了有关DevTools的不同主题,并且还包含有关CPU配置文件的部分。

So, you need to record a cpu profile and look into it. 因此,您需要记录一个cpu配置文件并查看它。

BottomUp视图

Also you can use FlameChart view on it. 您也可以在其上使用FlameChart视图。

FlameChart视图

You can click on an item in BottomUp or TopDown or even a FlameChart bar and see the function body in the Sources panel. 您可以单击BottomUp或TopDown中的项目,甚至可以单击FlameChart栏,然后在“源”面板中查看功能正文。

缩小版

If you sources are minified, as in the screenshot, then you can press a button in the status bar of Sources panel. 如果您缩小了源,如屏幕截图所示,则可以按“源”面板状态栏中的按钮。 It looks like two curly braces {}. 它看起来像两个花括号{}。 Then DevTools will format the sources. 然后DevTools将格式化源。

PrettyPrinted版本

and that action will affect all the links to the source file in all other places like Timeline, CPUProfile etc. As example in the first snapshot you saw a function O.Pk that was at line 778 of minified version of the script. 并且该操作将影响所有其他位置(如Timeline,CPUProfile等)中源文件的所有链接。例如,在第一个快照中,您看到了一个函数O.Pk,该函数位于脚本缩小版本的第778行。 After pretty printing the source file the link to the function was changed automatically. 在相当打印源文件后,该功能的链接自动更改。 Now it is pointing to the line 15871. 现在它指向15871线。

改变了链接

Looks like the answer is the "Timeline" tab. 看起来答案是“时间轴”选项卡。 Seems to work in regular chrome. 似乎在普通镀铬工作。 I set the tab to record just before I triggered the action that caused the hang, once the hang stopped (took about 20 seconds), I stopped recording and used the left and right selectors to zoom in on the master timeline (at the top) where I saw an longer execution period (at the top) with "Events" selected. 我将标签设置为在触发导致挂起的操作之前记录,一旦挂起停止(大约需要20秒),我停止录制并使用左右选择器放大主时间轴(在顶部)我看到更长的执行期(在顶部)选择了“事件”。

捕获后的时间线选项卡

From there I just expanded the dropdown and I got what I was looking for. 从那里我只是扩大了下拉菜单,我得到了我想要的东西。 (I blurred out the js filenames to avoid singling out the library) but I'm including a screenshot. (我模糊了js文件名,以避免单独删除库)但我包括一个截图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM