From 3c877c504b6102daf5dcc1083b1f1a7db88d304c Mon Sep 17 00:00:00 2001 From: Charlie Vieth Date: Sat, 13 Apr 2024 01:58:11 -0400 Subject: Enable profiling options when 'pprof' tag is set (#2813) This commit enables cpu, mem, block, and mutex profling of the FZF executable. To support flushing the profiles at program exit it adds util.AtExit to register "at exit" functions and mandates that util.Exit is used instead of os.Exit to stop the program. Co-authored-by: Junegunn Choi --- src/core.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'src/core.go') diff --git a/src/core.go b/src/core.go index ae5e58bf..8253c49e 100644 --- a/src/core.go +++ b/src/core.go @@ -3,7 +3,6 @@ package fzf import ( "fmt" - "os" "time" "unsafe" @@ -29,6 +28,8 @@ func sbytes(data string) []byte { // Run starts fzf func Run(opts *Options, version string, revision string) { + defer util.RunAtExitFuncs() + sort := opts.Sort > 0 sortCriteria = opts.Criteria @@ -38,7 +39,7 @@ func Run(opts *Options, version string, revision string) { } else { fmt.Println(version) } - os.Exit(exitOk) + util.Exit(exitOk) } // Event channel @@ -189,9 +190,9 @@ func Run(opts *Options, version string, revision string) { } } if found { - os.Exit(exitOk) + util.Exit(exitOk) } - os.Exit(exitNoMatch) + util.Exit(exitNoMatch) } // Synchronous search @@ -270,7 +271,7 @@ func Run(opts *Options, version string, revision string) { if reading { reader.terminate() } - os.Exit(value.(int)) + util.Exit(value.(int)) case EvtReadNew, EvtReadFin: if evt == EvtReadFin && nextCommand != nil { restart(*nextCommand, nextEnviron) @@ -372,9 +373,9 @@ func Run(opts *Options, version string, revision string) { opts.Printer(val.Get(i).item.AsString(opts.Ansi)) } if count > 0 { - os.Exit(exitOk) + util.Exit(exitOk) } - os.Exit(exitNoMatch) + util.Exit(exitNoMatch) } determine(val.final) } -- cgit v1.2.3