utils icon indicating copy to clipboard operation
utils copied to clipboard

Create a Embeddable package to monitor and profile go tools/apps

Open tarunKoyalwar opened this issue 1 year ago • 1 comments

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 time as key
  • [ ] profiling on every tick with time as key
  • [ ] by plotting MAX RSS over time we can find inflection points and filter out IMP/CRITICAL profiles 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

tarunKoyalwar avatar Feb 20 '24 18:02 tarunKoyalwar

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

stan-threatmate avatar Feb 22 '24 04:02 stan-threatmate