utils
utils copied to clipboard
Create a Embeddable package to monitor and profile go tools/apps
Proposed Changes
- To easily detect and share performance issues we need a library that effectively profiles application and monitors itself without any external dependency
### Tasks
- [ ] Env Based Input ( we can reuse existing logic in pprof package but cpuprofile might need to be improved)
- [ ] When this package is embedded it should launch a seperate process ( with appropriate syscall attributes to make it completely indedepent of current process ) and monitor/profile and save resulting data in cache directory . similar to screen command (Ref: https://github.com/projectdiscovery/utils/issues/346)
- [ ] Detection logic should be based on below logic
- [ ] Add Endpoint in PDTM API to support uploading and generating uuid of these profiles for effective sharing and ease of analysis
Detection Logic ( Task 3)
- [ ] continious monitering of Process MAX RSS with
timeas key - [ ] profiling on every tick with
timeas key - [ ] by plotting MAX RSS over time we can find inflection points and filter out
IMP/CRITICALprofiles and share them instead of sharing all xGB of profiles
References
- https://github.com/projectdiscovery/nuclei/issues/4756
- https://github.com/projectdiscovery/nuclei/pull/4680
What worked for me while debugging nuclei is this approach. It will dump the goroutines stack trace and memory allocations on a regular interval until stopped.
-
pprof.WriteHeapProfile() -
runtime.ReadMemStats(&memStat) -
pprof.Lookup("goroutine").WriteTo(f, 0)
Running these on an interval will create a new dump file every X minutes which might be what you need. You can then inspect the memory and goroutine stack trace using go tool pprof file.dump