Hi, All,
I have some piece of code with very high cpu usage, logging is actually pretty cpu intensive, so I tried to turn it off as follows,
type myLog struct {
*log.Logger
enable bool
}
func (l *myLog) Println(v ...interface{}) {
if l.enable == true {
l.Output(2, fmt.Sprintln(v...))
}
}
Debug = myLog{log.New(debugHandle,
"DEBUG: ",
log.Ldate|log.Ltime|log.Lshortfile), false}
if debugOn == true {
Debug.enable = true
Debug.SetOutput(&lumberjack.Logger{
Filename: "/var/log/sflow/sFlowDecoder.debug",
MaxSize: MAX_LOG_SIZE, // megabytes after which new file is created
MaxBackups: MAX_LOG_BACKUP, // number of backups
MaxAge: MAX_LOG_KEEP_TIME, //days
})
} else {
Debug.enable = false
}
I was expecting Debug.Println will be compiled with zero footprint in the code, or at least a NOP. As far as I can see, the debugs are not logged into the file. However, when I did profiling, it still takes significant cpu resource.
by doing
(pprof) list main.pktDistribute
<snip>
10ms 1.59s 547: Debug.Println("put packet on the queue", tmpData)
<snip>
I am wondering what I did wrong? What would be a proper solution to completely turn this off?
Thanks,
Chun