-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64c20ca
commit 448193b
Showing
5 changed files
with
196 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package lncfg | ||
|
||
import "fmt" | ||
|
||
// UsageError is an error type that signals a problem with the supplied flags. | ||
type UsageError struct { | ||
Err error | ||
} | ||
|
||
// Error returns the error string. | ||
// | ||
// NOTE: This is part of the error interface. | ||
func (u *UsageError) Error() string { | ||
return u.Err.Error() | ||
} | ||
|
||
// Unwrap returns the underlying error. | ||
func (u *UsageError) Unwrap() error { | ||
return u.Err | ||
} | ||
|
||
// mkErr creates a new error from a string. | ||
func mkErr(format string, args ...interface{}) error { | ||
return fmt.Errorf(format, args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package lncfg | ||
|
||
import ( | ||
"net" | ||
"strconv" | ||
) | ||
|
||
// Pprof holds the configuration options for LND's built-in pprof server. | ||
// | ||
//nolint:lll | ||
type Pprof struct { | ||
CPUProfile string `long:"cpuprofile" description:"Write CPU profile to the specified file"` | ||
|
||
Profile string `long:"profile" description:"Enable HTTP profiling on either a port or host:port"` | ||
|
||
BlockingProfile int `long:"blockingprofile" description:"Used to enable a blocking profile to be served on the profiling port. This takes a value from 0 to 1, with 1 including every blocking event, and 0 including no events."` | ||
|
||
MutexProfile int `long:"mutexprofile" description:"Used to Enable a mutex profile to be served on the profiling port. This takes a value from 0 to 1, with 1 including every mutex event, and 0 including no events."` | ||
} | ||
|
||
// Validate checks the values configured for the profiler. | ||
func (p *Pprof) Validate() error { | ||
if p.BlockingProfile > 0 { | ||
log.Warn("Blocking profile enabled only useful for " + | ||
"debugging because of significant performance impact") | ||
} | ||
|
||
if p.MutexProfile > 0 { | ||
log.Warn("Mutex profile enabled only useful for " + | ||
"debugging because of significant performance impact") | ||
} | ||
|
||
if p.CPUProfile != "" { | ||
log.Warn("CPU profile enabled only useful for " + | ||
"debugging because of significant performance impact") | ||
} | ||
|
||
if p.Profile != "" { | ||
str := "%v: The profile port must be between 1024 and 65535" | ||
|
||
// Try to parse Profile as a host:port. | ||
_, hostPort, err := net.SplitHostPort(p.Profile) | ||
if err == nil { | ||
// Determine if the port is valid. | ||
profilePort, err := strconv.Atoi(hostPort) | ||
|
||
if err != nil || profilePort < 1024 || | ||
profilePort > 65535 { | ||
|
||
return &UsageError{Err: mkErr(str, hostPort)} | ||
} | ||
} else { | ||
// Try to parse Profile as a port. | ||
profilePort, err := strconv.Atoi(p.Profile) | ||
if err != nil || profilePort < 1024 || | ||
profilePort > 65535 { | ||
|
||
return &UsageError{Err: mkErr(str, p.Profile)} | ||
} | ||
|
||
// Since the user just set a port, we will serve | ||
// debugging information over localhost. | ||
p.Profile = net.JoinHostPort("127.0.0.1", p.Profile) | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters