From cfc9e1d52292b69260ba38d8652b8a5f67787a67 Mon Sep 17 00:00:00 2001 From: bodqhrohro Date: Mon, 13 Jan 2020 17:31:28 +0200 Subject: [PATCH] Add pprof --- README.md | 4 ++++ telegabber.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 4f286fb..fa09904 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,10 @@ It is good idea to obtain Telegram API ID from [**https://my.telegram.org**](htt ... ``` +### Arguments ### + +* `--profiling-port=xxxx`: starts the pprof server on port `xxxx`. Access is limited to localhost. + ### How to receive files from Telegram ### First of all, you need to set up web server that will serve some directory in your filesystem. diff --git a/telegabber.go b/telegabber.go index 2752163..14b3b3d 100644 --- a/telegabber.go +++ b/telegabber.go @@ -1,6 +1,10 @@ package main import ( + "flag" + "fmt" + "net/http" + _ "net/http/pprof" "os" "os/signal" @@ -25,6 +29,15 @@ var cleanupDone chan struct{} var sigintChannel chan os.Signal func main() { + var profilingPort = flag.Int("profiling-port", 0, "The port for pprof server") + flag.Parse() + + if *profilingPort > 0 { + go func() { + log.Println(http.ListenAndServe(fmt.Sprintf("localhost:%v", *profilingPort), nil)) + }() + } + cleanupDone = make(chan struct{}) sigintChannel = make(chan os.Signal, 1) signal.Notify(sigintChannel, os.Interrupt)