debug.go 865 B

12345678910111213141516171819202122232425262728293031323334
  1. package box
  2. import (
  3. "runtime/debug"
  4. "github.com/sagernet/sing-box/option"
  5. E "github.com/sagernet/sing/common/exceptions"
  6. )
  7. func applyDebugOptions(options option.DebugOptions) error {
  8. applyDebugListenOption(options)
  9. if options.GCPercent != nil {
  10. debug.SetGCPercent(*options.GCPercent)
  11. }
  12. if options.MaxStack != nil {
  13. debug.SetMaxStack(*options.MaxStack)
  14. }
  15. if options.MaxThreads != nil {
  16. debug.SetMaxThreads(*options.MaxThreads)
  17. }
  18. if options.PanicOnFault != nil {
  19. debug.SetPanicOnFault(*options.PanicOnFault)
  20. }
  21. if options.TraceBack != "" {
  22. debug.SetTraceback(options.TraceBack)
  23. }
  24. if options.MemoryLimit.Value() != 0 {
  25. debug.SetMemoryLimit(int64(float64(options.MemoryLimit.Value()) / 1.5))
  26. }
  27. if options.OOMKiller != nil {
  28. return E.New("legacy oom_killer in debug options is removed, use oom-killer service instead")
  29. }
  30. return nil
  31. }