Commit c41992b3 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

print debug throughput for GET as well as PUT

parent a467b74b
......@@ -183,6 +183,17 @@ func (s sftpAPI) rempath(path string) string {
return path
}
// debug print throughput numbers
func throughput(fcn func() (int64, error)) (int64, error) {
t := time.Now()
n, err := fcn()
if err == nil {
tt := time.Now().Sub(t).Seconds()
debug("%fs, %d bytes; throughput %f Mb/s", tt, n, float64(n)*8/1024/1024/tt)
}
return n, err
}
// args: source, dest as abs paths
func (s sftpAPI) doPut(source, dest string) error {
dest = s.rempath(dest)
......@@ -198,13 +209,12 @@ func (s sftpAPI) doPut(source, dest string) error {
}
defer fin.Close()
t := time.Now()
n, err := io.Copy(fout, fin)
_, err = throughput(func() (int64, error) {
return io.Copy(fout, fin)
})
if err != nil {
return errors.Wrapf(err, "upload failed for %s -> %s", source, dest)
}
tt := time.Now().Sub(t).Seconds()
debug("%fs, %d bytes; throughput %f Mb/s", tt, n, float64(n)*8/1024/1024/tt)
return nil
}
......@@ -224,7 +234,9 @@ func (s sftpAPI) doGet(source, dest string) error {
}
defer fout.Close()
_, err = io.Copy(fout, fin)
_, err = throughput(func() (int64, error) {
return io.Copy(fout, fin)
})
if err != nil {
return errors.Wrapf(err, "download failed for %s -> %s", source, dest)
}
......
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