Skip to content

Commit

Permalink
fs: add timing info for android extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hanwen committed Mar 2, 2013
1 parent af33d0d commit 3383d4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
13 changes: 11 additions & 2 deletions fs/android.go
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"log"
"syscall"
"time"

"github.com/hanwen/go-fuse/fuse"
)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 7 additions & 8 deletions fs/fs.go
Expand Up @@ -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)
Expand Down

0 comments on commit 3383d4f

Please sign in to comment.