diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-16 00:39:31 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-16 00:39:31 +0300 |
| commit | 89943598a0b3c55d268e7dd51bd4199723a20c9d (patch) | |
| tree | 99ddf997f333c3068a1ae0a8da334abe4ed34948 /cmd/dcat | |
| parent | 0e63fe222d52c8ce01b648be67cf8f0688140679 (diff) | |
initial faster readfile
Diffstat (limited to 'cmd/dcat')
| -rw-r--r-- | cmd/dcat/main.go | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/cmd/dcat/main.go b/cmd/dcat/main.go index 98da089..71e2f1a 100644 --- a/cmd/dcat/main.go +++ b/cmd/dcat/main.go @@ -4,6 +4,7 @@ import ( "context" "flag" "os" + "runtime/pprof" "sync" "net/http" @@ -23,7 +24,8 @@ import ( func main() { var args config.Args var displayVersion bool - var pprof string + var pprofAddr string + var cpuprofile string userName := user.Name() @@ -44,7 +46,8 @@ func main() { flag.StringVar(&args.ServersStr, "servers", "", "Remote servers to connect") flag.StringVar(&args.UserName, "user", userName, "Your system user name") flag.StringVar(&args.What, "files", "", "File(s) to read") - flag.StringVar(&pprof, "pprof", "", "Start PProf server this address") + flag.StringVar(&pprofAddr, "pprof", "", "Start PProf server this address") + flag.StringVar(&cpuprofile, "cpuprofile", "", "Write CPU profile to file") flag.Parse() config.Setup(source.Client, &args, flag.Args()) @@ -53,14 +56,26 @@ func main() { version.PrintAndExit() } + if cpuprofile != "" { + f, err := os.Create(cpuprofile) + if err != nil { + panic(err) + } + defer f.Close() + if err := pprof.StartCPUProfile(f); err != nil { + panic(err) + } + defer pprof.StopCPUProfile() + } + ctx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup wg.Add(1) dlog.Start(ctx, &wg, source.Client) - if pprof != "" { - go http.ListenAndServe(pprof, nil) - dlog.Client.Info("Started PProf", pprof) + if pprofAddr != "" { + go http.ListenAndServe(pprofAddr, nil) + dlog.Client.Info("Started PProf", pprofAddr) } client, err := clients.NewCatClient(args) @@ -72,5 +87,10 @@ func main() { cancel() wg.Wait() + + if cpuprofile != "" { + pprof.StopCPUProfile() + } + os.Exit(status) } |
