fuse: add stats printing and note which files are transferring

This commit is contained in:
Nick Craig-Wood 2016-12-01 08:49:47 +00:00
parent be4fd51289
commit c24da0b886
4 changed files with 11 additions and 3 deletions

View file

@ -229,7 +229,7 @@ func Run(Retry bool, showStats bool, cmd *cobra.Command, f func() error) {
var err error var err error
var stopStats chan struct{} var stopStats chan struct{}
if showStats { if showStats {
stopStats = startStats() stopStats = StartStats()
} }
for try := 1; try <= *retries; try++ { for try := 1; try <= *retries; try++ {
err = f() err = f()
@ -286,10 +286,10 @@ func CheckArgs(MinArgs, MaxArgs int, cmd *cobra.Command, args []string) {
} }
} }
// startStats prints the stats every statsInterval // StartStats prints the stats every statsInterval
// //
// It returns a channel which should be closed to stop the stats. // It returns a channel which should be closed to stop the stats.
func startStats() chan struct{} { func StartStats() chan struct{} {
stopStats := make(chan struct{}) stopStats := make(chan struct{})
if *statsInterval > 0 { if *statsInterval > 0 {
go func() { go func() {

View file

@ -147,6 +147,10 @@ func Mount(f fs.Fs, mountpoint string) error {
dirPerms = 0777 &^ os.FileMode(umask) dirPerms = 0777 &^ os.FileMode(umask)
filePerms = 0666 &^ os.FileMode(umask) filePerms = 0666 &^ os.FileMode(umask)
// Show stats
stopStats := cmd.StartStats()
defer close(stopStats)
// Mount it // Mount it
errChan, err := mount(f, mountpoint) errChan, err := mount(f, mountpoint)
if err != nil { if err != nil {

View file

@ -31,6 +31,7 @@ func newReadFileHandle(o fs.Object) (*ReadFileHandle, error) {
o: o, o: o,
r: fs.NewAccount(r, o), // account and buffer the transfer r: fs.NewAccount(r, o), // account and buffer the transfer
} }
fs.Stats.Transferring(fh.o.Remote())
return fh, nil return fh, nil
} }
@ -123,6 +124,7 @@ func (fh *ReadFileHandle) close() error {
return errClosedFileHandle return errClosedFileHandle
} }
fh.closed = true fh.closed = true
fs.Stats.DoneTransferring(fh.o.Remote(), true)
return fh.r.Close() return fh.r.Close()
} }

View file

@ -45,6 +45,7 @@ func newWriteFileHandle(d *Dir, f *File, src fs.ObjectInfo) (*WriteFileHandle, e
fh.result <- err fh.result <- err
}() }()
fh.file.addWriters(1) fh.file.addWriters(1)
fs.Stats.Transferring(fh.remote)
return fh, nil return fh, nil
} }
@ -82,6 +83,7 @@ func (fh *WriteFileHandle) close() error {
return errClosedFileHandle return errClosedFileHandle
} }
fh.closed = true fh.closed = true
fs.Stats.DoneTransferring(fh.remote, true)
fh.file.addWriters(-1) fh.file.addWriters(-1)
writeCloseErr := fh.pipeWriter.Close() writeCloseErr := fh.pipeWriter.Close()
err := <-fh.result err := <-fh.result