了解Firebug探查器输出 [英] Understanding Firebug profiler output

查看:146
本文介绍了了解Firebug探查器输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Firebug的分析器来更好地理解我们看到的一些JavaScript性能问题的来源,但我对输出感到有些困惑。



当我分析一些代码时,探查器报告配置文件(464.323毫秒,26,412个呼叫)。我怀疑464.323 ms是这些26,412次调用的执行时间总和。



但是,当我深入查看详细结果时,我看到单个结果带有平均执行时间大于464.323 ms,例如平均时间最长的结果会报告以下详细信息:

 来电:** 1 ** 
百分比:* * 0%**
自己的时间:** 0.006毫秒**
时间:** 783.506毫秒**
平均:** 783.506毫秒**
最小值:** 783.506 ms **
最大值:** 783.506 ms **

另一个结果报告:

 电话:** 4 ** 
百分比:** 0.01%**
自己的时间:* * 0.032 ms **
时间:** 785.279 ms **
平均:** 196.32 ms **
最小值:** 0.012 ms **
最大值:** 783.741 ms **

在这两个结果之间,时间结果的总和远远大于464.323。 / p>

那么,这些不同的数字意味着什么?我应该信任哪些?

解决方案

每列都有一个描述,如果你将鼠标悬停在它上面它意味着什么萤火虫。我假设您可以阅读每个列如何在您自己的工作。但是,您肯定会遇到一些需要解释的奇怪行为。



自己的时间是函数执行所花费的时间代码本身。如果函数不调用其他函数,那么自己的时间应该与 time 相同。但是,如果存在嵌套函数调用,则 time 也会计算执行它们所花费的时间。因此, time 几乎总是大于自己的时间,并且在大多数情况下总计会超过分析器报告的总时间。



但是,单个功能的时间应该大于探查器为JavaScript调用记录的总时间。这个问题肯定是一个错误,我可以看到为什么当它给你这样一个矛盾的输出时你很难相信Firebug。我相信我已经找到了这个错误发生的原因:AJAX。



似乎AJAX调用导致计算嵌套函数调用的列报告错误信息。他们最终计算了JavaScript执行对服务器的请求的时间。



您可以通过执行以下操作重现此分析器错误:


  1. 转到任何使用AJAX的网站。 (我使用
    http://juicystudio.com/experiments/ajax/index.php

  2. 启用控制台/脚本调试。

  3. 打开探查器。

  4. 制作一个AJAX调用。 (多个问题可能会更多地解决问题。)

  5. 停止探查器,检查输出。

在此示例中,关于时间自己的时间,每个函数的自己的时间总计了探查器的总时间,但 time 列包含AJAX调用与服务器通信所花费的时间。这意味着如果您只是在寻找JavaScript执行的速度, time 列是不正确的。



它变得最糟糕:自时间平均时间 min max 所有计数嵌套函数调用,如果你使用它们都是不正确的AJAX。最重要的是,任何最终使用AJAX的函数(在嵌套函数调用中)也会错误地报告它们的时间。这意味着很多功能可能会报告不正确的信息!因此,在Firebug修复此问题之前,不要相信任何这些列。 (他们可能会以这种方式表达这种行为,尽管这样做会让人感到困惑。)



如果你没有使用AJAX,那么另一个问题在起作用;如果你不在,请告诉我们。


I've been trying to use Firebug's profiler to better understand the source of some JavaScript performance issues we are seeing, but I'm a little confused by the output.

When I profile some code the profiler reports Profile (464.323 ms, 26,412 calls). I suspect that the 464.323 ms is the sum of the execution time for those 26,412 calls.

However, when I drill down into the detailed results I see individual results with an average execution time greater than 464.323 ms, e.g. the result with the highest average time reports the following details:

Calls: **1**
Percent: **0%**
Own Time: **0.006 ms**
Time: **783.506 ms**
Avg: **783.506 ms**
Min: **783.506 ms**
Max: **783.506 ms**

Another result reports:

Calls: **4**
Percent: **0.01%**
Own Time: **0.032 ms**
Time: **785.279 ms**
Avg: **196.32 ms**
Min: **0.012 ms**
Max: **783.741 ms**

Between these two results the sum of the Time results is a lot more than 464.323.

So, what do these various numbers mean? Which ones should I trust?

解决方案

Each column has a description of what it means if you set your mouse to hover over it in Firebug. I'll assume you can read up on how each column works on your own then. However, you have definitely come across some odd behavior which needs to be explained.

The own time is the amount of time the function spent executing code inside of itself. If the function calls no other functions, then own time should be the same as time. However, if there are nested function calls, then time also counts the time spent executing them. Therefore, time will almost always be larger than own time, and will in most cases add up to more than the total time reported by the profiler.

However, no single function's time should be larger than the total time the profiler logged for JavaScript calls. This problem is definitely a bug, and I can see why you have trouble trusting Firebug when it gives you such a paradoxical output. I believe I've tracked down the reason this bug occurs: AJAX.

It appears that AJAX calls are causing columns that count nested function calls to report incorrect information. They end up counting both the time of JavaScript execution and the request to the server.

You can reproduce this profiler bug by doing the following:

  1. Go to any site that uses AJAX. (I used http://juicystudio.com/experiments/ajax/index.php)
  2. Enable Console/Script debugging.
  3. Turn on the profiler.
  4. Make an AJAX call. (Multiple ones may illuminate the issue more.)
  5. Stop the profiler, examine the output.

In this example, with regards to time vs. own time, the own time of each function adds up to the profiler's total time but the time column incorporates the amount of time the AJAX call took to talk to the server. This means that the time column is incorrect if you're looking for just the speed of JavaScript execution.

It gets worst: since time, average time, min and max all count nested function calls, they're all incorrect if you're using AJAX. On top of that, any function that eventually uses AJAX (in a nested function call) will also report their time incorrectly. This means that a whole lot of functions may be reporting incorrect information! So don't trust any of those columns for now until Firebug fixes the issue. (It's possible they intended the behavior to be this way, though it is confusing at best to leave it this way.)

If you're not using AJAX, then another issue is at play; let us know if you are or not.

这篇关于了解Firebug探查器输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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