Document env vars, start profiler based on STPROFILER
This commit is contained in:
parent
56b7d3c28d
commit
d4ef6a6285
@ -37,17 +37,27 @@ var (
|
|||||||
showVersion bool
|
showVersion bool
|
||||||
confDir string
|
confDir string
|
||||||
trace string
|
trace string
|
||||||
profiler string
|
|
||||||
verbose bool
|
verbose bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
usage = "syncthing [options]"
|
||||||
|
extraUsage = `The following environemnt variables can be set to facilitate debugging:
|
||||||
|
|
||||||
|
STPROFILER Set to a listen address such as "127.0.0.1:9090" to start the
|
||||||
|
profiler with HTTP access.
|
||||||
|
|
||||||
|
STTRACE A comma separated string of facilities to trace. The valid
|
||||||
|
facility strings:
|
||||||
|
- "scanner" (the file change scanner)`
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.StringVar(&confDir, "home", getDefaultConfDir(), "Set configuration directory")
|
flag.StringVar(&confDir, "home", getDefaultConfDir(), "Set configuration directory")
|
||||||
flag.StringVar(&trace, "debug.trace", "", "(connect,net,idx,file,pull)")
|
flag.StringVar(&trace, "debug.trace", "", "(connect,net,idx,file,pull)")
|
||||||
flag.StringVar(&profiler, "debug.profiler", "", "(addr)")
|
|
||||||
flag.BoolVar(&showVersion, "version", false, "Show version")
|
flag.BoolVar(&showVersion, "version", false, "Show version")
|
||||||
flag.BoolVar(&verbose, "v", false, "Be more verbose")
|
flag.BoolVar(&verbose, "v", false, "Be more verbose")
|
||||||
flag.Usage = usageFor(flag.CommandLine, "syncthing [options]")
|
flag.Usage = usageFor(flag.CommandLine, usage, extraUsage)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if len(os.Getenv("STRESTART")) > 0 {
|
if len(os.Getenv("STRESTART")) > 0 {
|
||||||
@ -156,8 +166,9 @@ func main() {
|
|||||||
|
|
||||||
var dir = expandTilde(cfg.Repositories[0].Directory)
|
var dir = expandTilde(cfg.Repositories[0].Directory)
|
||||||
|
|
||||||
if len(profiler) > 0 {
|
if profiler := os.Getenv("STPROFILER"); len(profiler) > 0 {
|
||||||
go func() {
|
go func() {
|
||||||
|
debugln("Starting profiler on", profiler)
|
||||||
err := http.ListenAndServe(profiler, nil)
|
err := http.ListenAndServe(profiler, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
warnln(err)
|
warnln(err)
|
||||||
|
|||||||
@ -22,18 +22,14 @@ func optionTable(w io.Writer, rows [][]string) {
|
|||||||
tw.Flush()
|
tw.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func usageFor(fs *flag.FlagSet, usage string) func() {
|
func usageFor(fs *flag.FlagSet, usage string, extra string) func() {
|
||||||
return func() {
|
return func() {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
b.WriteString("Usage:\n " + usage + "\n")
|
b.WriteString("Usage:\n " + usage + "\n")
|
||||||
|
|
||||||
var options [][]string
|
var options [][]string
|
||||||
fs.VisitAll(func(f *flag.Flag) {
|
fs.VisitAll(func(f *flag.Flag) {
|
||||||
var dash = "-"
|
var opt = " -" + f.Name
|
||||||
if len(f.Name) > 1 {
|
|
||||||
dash = "--"
|
|
||||||
}
|
|
||||||
var opt = " " + dash + f.Name
|
|
||||||
|
|
||||||
if f.DefValue != "false" {
|
if f.DefValue != "false" {
|
||||||
opt += "=" + f.DefValue
|
opt += "=" + f.DefValue
|
||||||
@ -48,5 +44,9 @@ func usageFor(fs *flag.FlagSet, usage string) func() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(b.String())
|
fmt.Println(b.String())
|
||||||
|
|
||||||
|
if len(extra) > 0 {
|
||||||
|
fmt.Println(extra)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user