我可以使用 Visual Studio Code 分析 NodeJS 应用程序吗? [英] Can I profile NodeJS Applications using Visual Studio Code?

查看:57
本文介绍了我可以使用 Visual Studio Code 分析 NodeJS 应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用 Chrome 协议成功地将 VS Code 调试器连接到我的远程 NodeJS 目标.我相信相同的协议支持分析和性能测量,因为它很容易从 Chrome Dev Tools 中完成,但我不确定我是否可以直接从 VS Code 中完成.

是否支持此功能?我该如何使用它?

解决方案

Visual Studio Code 1.45(2020 年 4 月)应该会有所帮助,因为它集成了


cheesus 提到了 在评论中 分析器输出中的行号有问题.
因此 microsoft/vscode-js-debug问题 559:

<块引用>

事实证明这是因为该位置位于仅存在于已编译代码中的函数内.
我们实际上确实尝试将其源映射回原始文件,但在该位置没有可用的映射.

如果您将目标更改为 es6 或更高版本——现在您可以这样做,除非您的目标是 Internet Explorer 或 Node 版本 <= 4——TS 不需要生成这些东西和行号有效.
您的代码也会运行得更快.这是最新的映射

此调试器仅支持 Node 8 及以上版本.
由于这个错误仅在针对旧的 JavaScript 版本时才存在,当在为比调试器本身支持的更早的 Node 版本编译的代码上使用就地转换时,以及修复此问题所涉及的复杂性,我将关闭此问题超出范围.

I can successfully connect the VS Code debugger to my remote NodeJS target using the Chrome protocol. I believe that same protocol supports profiling and performance measurements as it is easy to do from Chrome Dev Tools, but I am not sure it is something I can do from VS Code directly.

Is there any support for this feature ? How can I use it ?

解决方案

Visual Studio Code 1.45 (April 2020) should help, as it integrates Javascript debugging capabilities, including profiling:

New JavaScript debugger

This month we've continued making progress on our new JavaScript debugger.
It's installed by default on Insiders, and can be installed from the Marketplace in VS Code Stable.

You can start using it with your existing launch configurations by enabling the debug.javascript.usePreview setting.

Here are some new features added this month:

Profiling Support

You can capture CPU profiles from your Node.js or browser applications by clicking the new "Profile" button in the Call Stack view, or using the Debug: Take Performance Profile command.

Once you do, you can choose how long the profile will run: until you stop it, for a length of time, or until you hit another breakpoint.

After the profile ends, it's saved in your workspace folder and visualized in VS Code.
When you open the profile, code lenses are added to your files containing performance information at a function level and for certain 'hot' lines.
Unlike profiles captured in many other tools, the recorded profile is sourcemap-aware.


cheesus mentions in the comments having an problem with the line numbers in the profiler output.
Hence microsoft/vscode-js-debug issue 559:

Turns out this is because that location is inside a function that only exists in the compiled code.
We actually do try to source-map it back into the original file, but there's no mapping at that location to use.

If you change your target to es6 or newer -- which you can do nowadays unless you're targeting Internet Explorer or Node versions <= 4 -- TS does not need to generate this stuff and line numbers work.
Your code will also run faster. Here's the latest mappings

This debugger only supports Node 8 and above.
Due to the fact that this bug is only present when targeting old JavaScript versions when using in-place transpilation on code compiled for a version of Node older than what the debugger itself supports, and the complexity involved in fixing this, I will close this issue as out-of-scope.

这篇关于我可以使用 Visual Studio Code 分析 NodeJS 应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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