Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile JS code #637

Open
ram-vet opened this issue May 4, 2023 · 2 comments
Open

Profile JS code #637

ram-vet opened this issue May 4, 2023 · 2 comments

Comments

@ram-vet
Copy link

ram-vet commented May 4, 2023

Hi, is there a way to profile JS code in NJS ? Or any other possible integration for profiling just the JS part.

@xeioex
Copy link
Contributor

xeioex commented May 5, 2023

Hi @ram-vet,

There is console.time() and console.timeEnd() pair for njs CLI. Otherwise there no profiling tools specific to njs.

Please elaborate what you are trying to profile and what part of nginx/njs you are trying to measure.

@tippexs
Copy link

tippexs commented May 6, 2023

Hi @ram-vet
I wrote a little profiling tool for another NGINX user / customer.

https://gist.github.com/tippexs/59cc1a2d2e2b909947ba22a63608a90b

It is not in an state where it would make sense to call it a tool but what you can basically do with it is measure execution times of NJS functions and write them to a file.

$ ~> node index.js
event1: Min: 1, Middle 80.52228112910159, Max: 305, Std. Deviation: 44.29781599231003, Start: 167116922931, End: Start: 167116926031
event2 server 1: Min: 0, Middle 1.2707481005260082, Max: 101, Std. Deviation: 4.78749625209064, Start: 167116922872, End: Start: 167116926027
event3 server 2: Min: 1, Middle 78.99934512115259, Max: 294, Std. Deviation: 41.49847599276098, Start: 167116922931, End: Start: 167116926031
File successfully created!
File successfully created!

It will generate a log file and a little NodeJs application can actually create diagrams like this one.

image

All of this is very hacky :D and I feel very bad sharing the code as it will be (with a very high chance) the most ugliest piece of code you have ever seen in your live. Not kidding.

But let me know if this sounds useful to you. Happy to upload the stuff to a github repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants