add profiling support for sdk

This commit is contained in:
arraykeys@gmail.com
2018-12-05 14:52:00 +08:00
parent 367cfb36dd
commit 4ce5fd463d

View File

@ -482,14 +482,19 @@ func Stop(serviceID string) {
func Version() string { func Version() string {
return SDK_VERSION return SDK_VERSION
} }
func StartProfiling() { func StartProfiling(storePath string) {
isProfiling = true if isProfiling {
cpuProfilingFile, _ = os.Create("cpu.prof") if storePath == "" {
memProfilingFile, _ = os.Create("memory.prof") storePath = "."
blockProfilingFile, _ = os.Create("block.prof") }
goroutineProfilingFile, _ = os.Create("goroutine.prof") isProfiling = true
threadcreateProfilingFile, _ = os.Create("threadcreate.prof") cpuProfilingFile, _ = os.Create(filepath.Join(storePath, "cpu.prof"))
pprof.StartCPUProfile(cpuProfilingFile) memProfilingFile, _ = os.Create(filepath.Join(storePath, "memory.prof"))
blockProfilingFile, _ = os.Create(filepath.Join(storePath, "block.prof"))
goroutineProfilingFile, _ = os.Create(filepath.Join(storePath, "goroutine.prof"))
threadcreateProfilingFile, _ = os.Create(filepath.Join(storePath, "threadcreate.prof"))
pprof.StartCPUProfile(cpuProfilingFile)
}
} }
func StopProfiling() { func StopProfiling() {
if isProfiling { if isProfiling {