简体   繁体   English

Node.js分析的最佳实践是什么?

[英]What is the best practice in nodejs profiling?

I don't want to use services like nodetime. 我不想使用诸如nodetime之类的服务。 I have small middleware nodejs application. 我有小的中间件nodejs应用程序。 And now I my application use cpu in strange way http://s27.postimg.org/fgzmmh85f/cpu.png So I need simple tools to profile my code. 现在我的应用程序以奇怪的方式使用cpu http://s27.postimg.org/fgzmmh85f/cpu.png因此,我需要简单的工具来分析我的代码。 I tried to use node --prof app.js but Chrome Dev Tool doen't open generated log-file. 我尝试使用node --prof app.js,但Chrome Dev Tool无法打开生成的日志文件。

Please advise tool to find out bottlenecks. 请告知工具以找出瓶颈。 Also I can't understand how v8 garbidge collector works. 我也不明白v8 garbidge收集器是如何工作的。

I'm not node expert, but I've been trying to profile some JS code for some time now. 我不是节点专家,但是一段时间以来我一直在尝试分析一些JS代码。 This is what I can tell you: 我可以告诉你的是:

There are two ways to profile, but both provide the same data. 有两种剖析方法,但是两者都提供相同的数据。 The first one is running your code with node -- , which will generate an isolate*.log file. 第一个正在使用node --运行您的代码,这将生成一个isolate*.log文件。 You give this file to node --prof-process and this will give you smoe output that, if you're kinda lucky, you can understand and act upon. 您将此文件提供给node --prof-process ,这将为您提供smoe输出,如果您还算幸运的话,您可以理解并采取行动。

The second one is more or less like this: 第二个或多或少是这样的:

var profiler = require('v8-profiler');
profiler.startProfiling('carto');

[your code here]

var profile = profiler.stopProfiling('carto');
profile.export(function(error, result) {
    fs.writeFileSync('carto.cpuprofile', result);
    profile.delete();
})

This will generate a .cpuprofile that you can load in chromium 's JS Profiler. 这将产生一个.cpuprofile ,你可以在装载chromium的JS探查。 This can be found in the Developer Tools, and you will have probably to enable the Javascript Profiler in the More Tools menu. 可以在开发人员工具中找到,您可能必须在“更多工具”菜单中启用Javascript Profiler。 This will give you three different ways to see in which functions you're spending time. 这将为您提供三种不同的方式来查看您花费时间的功能。

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

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