Firefox 中的 javascript 配置文件
(我知道有些人已经问过有关 js 配置文件的问题,但如果我正确理解它们,这不是我需要的。)
我想跟踪 javascript 的执行以收集以下信息:1)调用了哪个函数,2)调用函数的时间,以及 3) 函数的执行时间。
我想在线收集信息(关于已部署的代码),但不是在内部收集信息。因此,权衡必须是轻松的。另外,我不想在调用函数的前后手动添加一行。然而,如果有一种方法可以动态地检测代码,那就太好了。
提前致谢!
(I know some people already asked questions about js profile, but that's not what I need if I understand them correctly.)
I'd like to trace the execution of javascript to collect the information of 1) which function is invoked, 2) the time when the function is invoked, and 3) the execution time of the function.
I want to collect the information online (on deployed code) but not in-house. So, the trade-off has to be light. Also, I don't want to manually add a line before and after where a function is invoked. However, it would be great if there's a way that can dynamically instrument the code.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认为有任何系统可以让 JavaScript 自动跟踪函数启动的时间和函数停止的时间。这可能是您必须自己添加的内容。如果这是您所需要的,您可能需要考虑使用 PHP 来提供 JavaScript 服务,并使用正则表达式通过正则表达式或类似的东西来查找每个函数的开头和结尾。
您的 RegExp 可能如下所示(完全未经测试,因此您必须进行实验):
一旦您有权访问函数的内部,您可以用该函数替换该值以跟踪其围绕原始函数定义的开头和结尾。
这样做的好处是可以完全按照您想要的方式进行操作,而无需担心修改 js 代码的功能。这就是服务器将完全处理的事情。
或者,不直接调用该函数,而是使用包装函数:
这比让服务器为您更新 JS 更干净。不幸的是,这也意味着必须手动重写 JS。
我的建议是简单地调整日志语法并使用它。大多数记录器将输出时间戳、上下文、级别和特定消息。如果您只是在函数的开头和结尾调用记录器,它将完全按照您的要求进行操作。此外,由于许多都是可配置的,您可以将其显示到 Firefox 中的 JS 控制台,将信息发送到服务器,或者完全禁用(如果您愿意的话)。
这里有一个 JS 记录器列表:
JavaScript 记录器
不幸的是,这需要您手动更新所有内容,但是这似乎是开箱即用地获得 90% 所需内容的最简单方法。
I don't think that there is any system whereby JavaScript will automatically track the time a function starts and the time a function stops. That is likely something you will have to add yourself. If this is what you need, you may want to consider using PHP to serve up your JavaScript and use a regular expression to find the beginnings and ends of each function with a regex or something like that.
Your RegExp might look like this (completely untested, so you'll have to experiment):
Once you have access to the inside of the function, you could replace that value with the function to track its beginning and end wrapped around the original function definition.
This has the benefit of doing exactly what you want, without worrying about modifying how your js code functions. It is then something the server will handle entirely.
Either that or, instead of calling the function directly, use a wrapper function:
This has the benefit of being a lot cleaner than having the server update your JS for you. Unfortunately, it also means having to re-write the JS manually.
My recommendation would be to simply adapt a logging syntax and use that. Most loggers will output a timestamp, a context, a level, and a specific message. If you simply call the logger at the beginning and end of the function, it will do exactly what you're looking for. Further, since many are configurable, you would be able to have it display to the JS console in Firefox, send information to the server, or completely disabled if you so chose.
There are a list of JS loggers here:
JavaScript loggers
This would unfortunately require you to manually update everything, but it seems like the simplest way to get 90% of what you're looking for out of the box.
也许 FireBug 中的分析器可以帮助您跟踪缓慢的函数。
此视频详细介绍了分析选项。 (索引:3:20)。
Perhaps the profiler in FireBug can help you track down slow functions.
Here's a video detailing the profiling options. (Index: 3:20).
http://getfirebug.com/wiki/index.php/Console_API
http://getfirebug.com/wiki/index.php/Console_API