Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Profiling of a TypeScript Node.js application

I am looking for a tool to make the profiling of a TypeScript Node.js application, and this without modifying the whole code source.

I mean by profiling: launching the application using some specific tool, which outputs the result like this:

Method | consumed memory | consumed time

a() | 1024 | 20ms ….

I did some internet research and I have found this one: https://github.com/screepers/screeps-typescript-profiler

But using it, I'm obliged to edit the whole code (by adding the @Profiler decorator), I'm looking for something to detect the methods automatically.

Thanks for your help!

like image 779
abderrahim_05 Avatar asked Dec 24 '19 10:12

abderrahim_05


1 Answers

You can use WebStorm IDE for V8 CPU and Memory Profiling. Here is a guide: https://www.jetbrains.com/help/webstorm/v8-cpu-and-memory-profiling.html.

There is no need to change any part of your code. You can run V8 Profiling, take Heap Snapshots and view useful snapshot diffs.

You can use the default Webstorm guide, however, for Node 12 there is a bug and you will get an error in CLI: bad option: --log-timer-events.

For Typescript project with Express and Socket.io server, I use it with ts-node-dev tool which simply passes all unknown params to ts-node and then to node. So, you can apply the same approach when using ts-node. Set --prof and --logfile=logfile-profiling.log arguments manually. Here is my example configuration:

Run configuration

Disable Record CPU profiling info to avoid the bug (we set --prof and --logfile manually) and enable Allow taking heap snapshots.

V8 Profiling configuration

Then run Debug for this configuration. To take a new heap snapshot click to a bottom icon of a left side panel while debugging your app:

Heap snapshot icon in the bottom

Heap Snapshots and CPU profiling logs will be stored in your project folder and you can analyze them from menu Tools > V8 Profiling > Analyze V8 Heap Snapshot as well as for CPU logs: Analyze V8 Profiling logs. CPU profiling logs are created in intervals, so you can run your app and open new logs at the same time.

like image 86
dev0experiment Avatar answered Sep 17 '22 03:09

dev0experiment