github.com/metaworking/channeld@v0.7.3/pkg/channeld/profiling.go (about)

     1  package channeld
     2  
     3  import (
     4  	"log"
     5  	"os"
     6  	"os/signal"
     7  	"syscall"
     8  
     9  	"github.com/pkg/profile"
    10  )
    11  
    12  func StartProfiling() {
    13  	if GlobalSettings.ProfileOption != nil {
    14  		prof := profile.Start(
    15  			GlobalSettings.ProfileOption,
    16  			profile.ProfilePath(GlobalSettings.ProfilePath),
    17  			profile.NoShutdownHook,
    18  		)
    19  		// Replace pprof's default shutdown hook with more signals to make sure the file is saved before the process is terminated.
    20  		go func() {
    21  			c := make(chan os.Signal, 1)
    22  			signal.Notify(c, os.Interrupt, syscall.SIGQUIT, syscall.SIGTERM)
    23  			<-c
    24  
    25  			log.Println("profile: caught interrupt, stopping profiles")
    26  			prof.Stop()
    27  
    28  			os.Exit(0)
    29  		}()
    30  	}
    31  }