2023-03-17 14:51:09 +08:00
|
|
|
//go:build go1.19
|
|
|
|
|
|
|
|
package box
|
|
|
|
|
|
|
|
import (
|
|
|
|
"runtime/debug"
|
|
|
|
|
2023-09-20 14:12:08 +08:00
|
|
|
"github.com/sagernet/sing-box/common/conntrack"
|
2023-03-17 14:51:09 +08:00
|
|
|
"github.com/sagernet/sing-box/option"
|
|
|
|
)
|
|
|
|
|
|
|
|
func applyDebugOptions(options option.DebugOptions) {
|
2023-04-22 15:58:25 +08:00
|
|
|
applyDebugListenOption(options)
|
2023-03-17 14:51:09 +08:00
|
|
|
if options.GCPercent != nil {
|
|
|
|
debug.SetGCPercent(*options.GCPercent)
|
|
|
|
}
|
|
|
|
if options.MaxStack != nil {
|
|
|
|
debug.SetMaxStack(*options.MaxStack)
|
|
|
|
}
|
|
|
|
if options.MaxThreads != nil {
|
|
|
|
debug.SetMaxThreads(*options.MaxThreads)
|
|
|
|
}
|
|
|
|
if options.PanicOnFault != nil {
|
|
|
|
debug.SetPanicOnFault(*options.PanicOnFault)
|
|
|
|
}
|
|
|
|
if options.TraceBack != "" {
|
|
|
|
debug.SetTraceback(options.TraceBack)
|
|
|
|
}
|
|
|
|
if options.MemoryLimit != 0 {
|
2023-09-20 22:01:58 +08:00
|
|
|
debug.SetMemoryLimit(int64(float64(options.MemoryLimit) / 1.5))
|
2023-09-20 14:12:08 +08:00
|
|
|
conntrack.MemoryLimit = uint64(options.MemoryLimit)
|
2023-03-17 14:51:09 +08:00
|
|
|
}
|
|
|
|
if options.OOMKiller != nil {
|
|
|
|
conntrack.KillerEnabled = *options.OOMKiller
|
|
|
|
}
|
|
|
|
}
|