cmd/torrent: Add -stats flag
Requires updated tagflag package.
This commit is contained in:
parent
6354b9b967
commit
37fc800cb1
@ -130,6 +130,7 @@ var flags = struct {
|
|||||||
DownloadRate tagflag.Bytes `help:"max bytes per second down from peers"`
|
DownloadRate tagflag.Bytes `help:"max bytes per second down from peers"`
|
||||||
Debug bool
|
Debug bool
|
||||||
PackedBlocklist string
|
PackedBlocklist string
|
||||||
|
Stats *bool
|
||||||
tagflag.StartPos
|
tagflag.StartPos
|
||||||
Torrent []string `arity:"+" help:"torrent file path or magnet uri"`
|
Torrent []string `arity:"+" help:"torrent file path or magnet uri"`
|
||||||
}{
|
}{
|
||||||
@ -143,9 +144,17 @@ func stdoutAndStderrAreSameFile() bool {
|
|||||||
return os.SameFile(fi1, fi2)
|
return os.SameFile(fi1, fi2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func statsEnabled() bool {
|
||||||
|
if flags.Stats == nil {
|
||||||
|
return flags.Debug
|
||||||
|
}
|
||||||
|
return *flags.Stats
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
tagflag.Parse(&flags)
|
tagflag.Parse(&flags)
|
||||||
|
defer envpprof.Stop()
|
||||||
clientConfig := torrent.Config{
|
clientConfig := torrent.Config{
|
||||||
Debug: flags.Debug,
|
Debug: flags.Debug,
|
||||||
Seed: flags.Seed,
|
Seed: flags.Seed,
|
||||||
@ -193,10 +202,18 @@ func main() {
|
|||||||
log.Fatal("y u no complete torrents?!")
|
log.Fatal("y u no complete torrents?!")
|
||||||
}
|
}
|
||||||
if flags.Seed {
|
if flags.Seed {
|
||||||
|
outputStats(client)
|
||||||
select {}
|
select {}
|
||||||
}
|
}
|
||||||
|
outputStats(client)
|
||||||
|
}
|
||||||
|
|
||||||
|
func outputStats(cl *torrent.Client) {
|
||||||
|
if !statsEnabled() {
|
||||||
|
return
|
||||||
|
}
|
||||||
expvar.Do(func(kv expvar.KeyValue) {
|
expvar.Do(func(kv expvar.KeyValue) {
|
||||||
fmt.Printf("%s: %s\n", kv.Key, kv.Value)
|
fmt.Printf("%s: %s\n", kv.Key, kv.Value)
|
||||||
})
|
})
|
||||||
envpprof.Stop()
|
cl.WriteStatus(os.Stdout)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user