gpt4 book ai didi

javascript - 我可以使用 Visual Studio Code 分析 NodeJS 应用程序吗?

转载 作者:数据小太阳 更新时间:2023-10-29 04:59:45 27 4
gpt4 key购买 nike

我可以使用 Chrome 协议(protocol)将 VS Code 调试器成功连接到我的远程 NodeJS 目标。我相信相同的协议(protocol)支持分析和性能测量,因为它很容易从 Chrome 开发工具中完成,但我不确定这是我可以直接从 VS Code 中完成的事情。

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

最佳答案

Visual Studio Code 1.45(2020 年 4 月)应该有所帮助,因为它集成了 Javascript debugging capabilities ,包括分析:

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.

JS Debug profiling


cheesus提及 in the comments探查器输出中的行号有问题。
因此 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.

https://camo.githubusercontent.com/24b6e6f18cade2b5c8a621ded5241dc752896d00/68747470733a2f2f6d656d65732e706565742e696f2f696d672f32302d30372d38376265353862372d343530622d346334322d613233302d3266306532376336356234322e706e67

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.

关于javascript - 我可以使用 Visual Studio Code 分析 NodeJS 应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54794597/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com