Add cpu profiling
This commit is contained in:
parent
dabbe5c305
commit
1e7a55c852
@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime/pprof"
|
||||
"strings"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -41,6 +42,10 @@ func main() {
|
||||
Usage: "Path to config-file",
|
||||
Aliases: []string{"c"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "cpu-profile",
|
||||
Usage: "Profile cpu usage and write to file",
|
||||
},
|
||||
},
|
||||
Commands: []*cli.Command{
|
||||
{
|
||||
@ -69,11 +74,25 @@ func ActionServe(c *cli.Context) error {
|
||||
cfg.DebugLog(logger)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
// Setup RTMP-server
|
||||
rtmpServer := server.NewRTMPServer(ctx, cfg.RTMPListenAddr)
|
||||
rtmpServer.Logger = logger
|
||||
rtmpServer.Hostname = cfg.Hostname
|
||||
|
||||
if c.IsSet("cpu-profile") {
|
||||
filename := c.String("cpu-profile")
|
||||
logger.Infow("CPU-profiling enabled.", "filename", filename)
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return cli.Exit(fmt.Sprintf("Unable to create cpu-profile file '%s': %s", filename, err), 1)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
// Setup web-server
|
||||
webDone := make(chan struct{})
|
||||
if cfg.HTTPServerEnable {
|
||||
|
@ -2,7 +2,7 @@ package dogtamer
|
||||
|
||||
import "fmt"
|
||||
|
||||
const Version string = "v0.1.7"
|
||||
const Version string = "v0.1.8"
|
||||
|
||||
var Build string
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user