Permalink
Browse files

fs: add timing info for android extensions.

  • Loading branch information...
1 parent af33d0d commit 3383d4fc17db105e33f3b1fc5756d210eddffa69 @hanwen committed Mar 2, 2013
Showing with 18 additions and 10 deletions.
  1. +11 −2 fs/android.go
  2. +7 −8 fs/fs.go
View
13 fs/android.go
@@ -9,6 +9,7 @@ import (
"fmt"
"log"
"syscall"
+ "time"
"github.com/hanwen/go-fuse/fuse"
)
@@ -17,14 +18,18 @@ type androidNode struct {
mtpNodeImpl
// If set, the backing file was changed.
- write bool
+ write bool
+ start time.Time
+ byteCount int64
}
func (n *androidNode) startEdit() bool {
if n.write {
return true
}
+ n.start = time.Now()
+ n.byteCount = 0
err := n.fs.dev.AndroidBeginEditObject(n.Handle())
if err != nil {
log.Println("AndroidBeginEditObject failed:", err)
@@ -39,6 +44,10 @@ func (n *androidNode) endEdit() bool {
return true
}
+ dt := time.Now().Sub(n.start)
+ log.Printf("%d bytes in %v: %d mb/s",
+ n.byteCount, dt, (1e3*n.byteCount)/(dt.Nanoseconds()))
+
err := n.fs.dev.AndroidEndEditObject(n.Handle())
if err != nil {
log.Println("AndroidEndEditObject failed:", err)
@@ -106,7 +115,7 @@ func (f *androidFile) Write(dest []byte, off int64) (written uint32, status fuse
if !f.node.startEdit() {
return 0, fuse.EIO
}
-
+ f.node.byteCount += int64(len(dest))
b := bytes.NewBuffer(dest)
err := f.node.fs.dev.AndroidSendPartialObject(f.node.Handle(), off, uint32(len(dest)), b)
if err != nil {
View
15 fs/fs.go
@@ -501,22 +501,21 @@ func (n *folderNode) Create(name string, flags uint32, mode uint32, context *fus
return nil, nil, fuse.EIO
}
- if err := n.fs.dev.AndroidBeginEditObject(handle); err != nil {
- log.Println("AndroidBeginEditObject failed:", err)
- return nil, nil, fuse.EIO
- }
-
- node = &androidNode{
+ aNode := &androidNode{
mtpNodeImpl: mtpNodeImpl{
obj: &obj,
fs: n.fs,
handle: handle,
},
- write: true,
+ }
+
+ if !aNode.startEdit() {
+ return nil, nil, fuse.EIO
}
file = &androidFile{
- node: node.(*androidNode),
+ node: aNode,
}
+ node = aNode
} else {
var err error
file, node, err = n.fs.createClassicFile(obj)

0 comments on commit 3383d4f

Please sign in to comment.