all repos — honk @ 4d093be7f9877158129b4a6fd2dd0e2beb830502

my fork of honk

profiling options
Ted Unangst tedu@tedunangst.com
Sun, 28 Jan 2024 17:00:00 -0500
commit

4d093be7f9877158129b4a6fd2dd0e2beb830502

parent

89b6a314476a7a18ecdfc580477c605db6ab5fa0

2 files changed, 27 insertions(+), 0 deletions(-)

jump to
M main.gomain.go

@@ -23,6 +23,7 @@ golog "log"

"log/syslog" notrand "math/rand" "os" + "runtime/pprof" "strconv" "time"

@@ -72,10 +73,28 @@ fmt.Fprintf(os.Stderr, msg+"\n", args...)

os.Exit(1) } +var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file") +var memprofile = flag.String("memprofile", "", "write memory profile to this file") +var memprofilefd *os.File + func main() { flag.StringVar(&dataDir, "datadir", dataDir, "data directory") flag.StringVar(&viewDir, "viewdir", viewDir, "view directory") flag.Parse() + if *cpuprofile != "" { + f, err := os.Create(*cpuprofile) + if err != nil { + errx("can't open cpu profile: %s", err) + } + pprof.StartCPUProfile(f) + } + if *memprofile != "" { + f, err := os.Create(*memprofile) + if err != nil { + errx("can't open mem profile: %s", err) + } + memprofilefd = f + } log.Init(log.Options{Progname: "honk", Facility: syslog.LOG_UUCP}) elog = log.E
M web.goweb.go

@@ -32,6 +32,7 @@ "net/url"

"os" "os/signal" "regexp" + "runtime/pprof" "sort" "strconv" "strings"

@@ -2661,6 +2662,13 @@ ilog.Printf("stopping...")

listenSocket.Close() for i := 0; i < workinprogress; i++ { endoftheworld <- true + } + if *cpuprofile != "" { + pprof.StopCPUProfile() + } + if *memprofile != "" { + pprof.WriteHeapProfile(memprofilefd) + memprofilefd.Close() } ilog.Printf("waiting...") go func() {