github.com/sagernet/sing-box@v1.9.0-rc.20/debug_go119.go (about)

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