[英]What is the best practice in nodejs profiling?
我不想使用諸如nodetime之類的服務。 我有小的中間件nodejs應用程序。 現在我的應用程序以奇怪的方式使用cpu http://s27.postimg.org/fgzmmh85f/cpu.png因此,我需要簡單的工具來分析我的代碼。 我嘗試使用node --prof app.js,但Chrome Dev Tool無法打開生成的日志文件。
請告知工具以找出瓶頸。 我也不明白v8 garbidge收集器是如何工作的。
我不是節點專家,但是一段時間以來我一直在嘗試分析一些JS代碼。 我可以告訴你的是:
有兩種剖析方法,但是兩者都提供相同的數據。 第一個正在使用node --
運行您的代碼,這將生成一個isolate*.log
文件。 您將此文件提供給node --prof-process
,這將為您提供smoe輸出,如果您還算幸運的話,您可以理解並采取行動。
第二個或多或少是這樣的:
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();
})
這將產生一個.cpuprofile
,你可以在裝載chromium
的JS探查。 可以在開發人員工具中找到,您可能必須在“更多工具”菜單中啟用Javascript Profiler。 這將為您提供三種不同的方式來查看您花費時間的功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.