简体   繁体   English

是否可以使用Firebug剖析内置的JavaScript函数?

[英]Is it possible to profile built-in JavaScript functions with Firebug?

I'm building a graphics-intensive site in HTML5 that makes heavy use of the canvas context's drawImage() function. 我正在HTML5中建立一个图形密集型网站,该网站大量使用了画布上下文的drawImage()函数。 In IE9 on Windows 7, performance is smooth, but in Firefox 4, things get choppy. 在Windows 7上的IE9中,性能是平稳的,但是在Firefox 4中,情况变得不稳定。 I'm trying to isolate bottlenecks so I can start optimizing. 我正在尝试隔离瓶颈,以便可以开始优化。

If I use the JavaScript performance profiling feature of Firebug 1.7.0, I can see statistics for my own functions, but I'd like to see calls to the built-in JavaScript functions as well. 如果我使用Firebug 1.7.0的JavaScript性能分析功能,则可以看到自己函数的统计信息,但是我也希望看到对内置JavaScript函数的调用。 Is there any way to do this in Firebug or some other tool? 在Firebug或其他工具中,有什么方法可以做到这一点?

As a workaround, I suppose I could make the profiling granularity finer by breaking things down into lots of tiny functions, but I'd rather my design not be driven by how easy it is to profile. 作为一种解决方法,我想可以通过将事情分解为许多微小的功能来使配置粒度更精细,但是我宁愿我的设计不受配置的难易程度驱动。

Update : Looking back at this question, it occurs to me that the built-in functions in question are not truly JavaScript functions but functions provided by the host. 更新 :回顾这个问题,我发现所讨论的内置函数不是真正的JavaScript函数,而是主机提供的函数。 In this case, they're DOM objects from the browser. 在这种情况下,它们是浏览器中的DOM对象。 Just thought I'd clarify that technical detail. 只是以为我会澄清技术细节。

Last I used it Firebug doesn't give you the ability to profile native code. 最后,我用了它Firebug没有为您提供分析本机代码的功能。

What you can do is make your own function that just calls the native piece you want to call. 您可以做的是制作自己的函数,该函数仅调用您要调用的本机代码。 As in turn the code: 依次代码:

ctx.fillRect(50,50,50,50);`

Into: 成:

// wrap in function
function fillR() {
ctx.fillRect(50,50,50,50);
};

// call it immediately afterwards
fillR();

Then you can get the stats for fillR. 然后,您可以获取fillR的统计信息。 Not the best fix, but it may useful enough. 不是最好的解决方法,但它可能足够有用。

You might try playing around with Venkman, Mozilla's JS debugger. 您可以尝试使用Mozilla的JS调试器Venkman。 At the moment the version on addons.mozilla.org is broken in Firefox 4.0. 目前,addons.mozilla.org上的版本在Firefox 4.0中已损坏。

You can get the most recent version via mercurial, which does work with Firefox 4.0: 您可以通过mercurial获取最新版本,该版本适用于Firefox 4.0:

hg clone http://hg.mozilla.org/venkman/
cd venkman/xpi
./makexpi.py
firefox venkman-0.9.88.1.xpi

After contemplating this on and off for a couple of days, I came up with a new solution and wrote a blog post about it: 在考虑了好几天之后,我想出了一个新的解决方案,并写了一篇博客文章:

http://andrewtwest.com/2011/03/26/profiling-built-in-javascript-functions-with-firebug/ http://andrewtwest.com/2011/03/26/profiling-built-in-javascript-functions-with-firebug/

This method does the following: 此方法执行以下操作:

  1. Checks to see if the Firebug console is open. 检查Firebug控制台是否打开。
  2. Does a combination of overriding and wrapping native functions with user-defined functions. 将重写和包装本机函数与用户定义的函数组合在一起。

These steps combined provide a way to profile DOM functions that doesn't affect your original script code unless you're debugging. 这些步骤组合在一起,提供了一种用于分析DOM功能的方法,除非您进行调试,否则该功能不会影响原始脚本代码。

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

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