Commit d56917d8 authored by Brian Tiger Chow's avatar Brian Tiger Chow

fix(main): profile at top-level since work may be async

parent 4b13b05f
......@@ -67,6 +67,13 @@ func main() {
fmt.Fprintf(os.Stderr, "Error: %s\n", err.Error())
}
stopFunc, err := profileIfEnabled()
if err != nil {
printErr(err)
os.Exit(1)
}
defer stopFunc() // to be executed as late as possible
// this is a local helper to print out help text.
// there's some considerations that this makes easier.
printHelp := func(long bool, w io.Writer) {
......@@ -153,16 +160,6 @@ func (i *cmdInvocation) Run(ctx context.Context) (output io.Reader, err error) {
u.SetDebugLogging()
}
// if debugging, let's profile.
// TODO maybe change this to its own option... profiling makes it slower.
if u.Debug {
stopProfilingFunc, err := startProfiling()
if err != nil {
return nil, err
}
defer stopProfilingFunc() // to be executed as late as possible
}
res, err := callCommand(ctx, i.req, Root, i.cmd)
if err != nil {
return nil, err
......@@ -511,3 +508,18 @@ func allInterruptSignals() chan os.Signal {
syscall.SIGTERM)
return sigc
}
func profileIfEnabled() (func(), error) {
// FIXME this is a temporary hack so profiling of asynchronous operations
// works as intended.
if u.GetenvBool("DEBUG") || os.Getenv("IPFS_LOGGING") == "debug" {
u.Debug = true
u.SetDebugLogging()
stopProfilingFunc, err := startProfiling() // TODO maybe change this to its own option... profiling makes it slower.
if err != nil {
return nil, err
}
return stopProfilingFunc, nil
}
return func() {}, nil
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment