debug_go119.go 856 B

123456789101112131415161718192021222324252627282930313233343536
  1. //go:build go1.19
  2. package box
  3. import (
  4. "runtime/debug"
  5. "github.com/sagernet/sing-box/common/conntrack"
  6. "github.com/sagernet/sing-box/option"
  7. )
  8. func applyDebugOptions(options option.DebugOptions) {
  9. applyDebugListenOption(options)
  10. if options.GCPercent != nil {
  11. debug.SetGCPercent(*options.GCPercent)
  12. }
  13. if options.MaxStack != nil {
  14. debug.SetMaxStack(*options.MaxStack)
  15. }
  16. if options.MaxThreads != nil {
  17. debug.SetMaxThreads(*options.MaxThreads)
  18. }
  19. if options.PanicOnFault != nil {
  20. debug.SetPanicOnFault(*options.PanicOnFault)
  21. }
  22. if options.TraceBack != "" {
  23. debug.SetTraceback(options.TraceBack)
  24. }
  25. if options.MemoryLimit != 0 {
  26. debug.SetMemoryLimit(int64(float64(options.MemoryLimit) / 1.5))
  27. conntrack.MemoryLimit = uint64(options.MemoryLimit)
  28. }
  29. if options.OOMKiller != nil {
  30. conntrack.KillerEnabled = *options.OOMKiller
  31. }
  32. }