Commit 7ea8b832 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add code to profile zipfs.

parent a519b679
......@@ -5,8 +5,14 @@ import (
"fmt"
"github.com/hanwen/go-fuse/fuse"
"github.com/hanwen/go-fuse/zipfs"
"io"
"log"
"os"
"os/exec"
"runtime"
"runtime/pprof"
"strings"
"time"
)
var _ = log.Printf
......@@ -15,21 +21,43 @@ func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
latencies := flag.Bool("latencies", false, "record operation latencies.")
profile := flag.String("profile", "", "record cpu profile.")
mem_profile := flag.String("mem-profile", "", "record memory profile.")
command := flag.String("run", "", "run this command after mounting.")
ttl := flag.Float64("ttl", 1.0, "attribute/entry cache TTL.")
flag.Parse()
if flag.NArg() < 2 {
fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT ZIP-FILE\n", os.Args[0])
os.Exit(2)
}
var profFile, memProfFile io.Writer
var err error
if *profile != "" {
profFile, err = os.Create(*profile)
if err != nil {
log.Fatalf("os.Create: %v", err)
}
}
if *mem_profile != "" {
memProfFile, err = os.Create(*mem_profile)
if err != nil {
log.Fatalf("os.Create: %v", err)
}
}
var fs fuse.NodeFileSystem
fs, err := zipfs.NewArchiveFileSystem(flag.Arg(1))
fs, err = zipfs.NewArchiveFileSystem(flag.Arg(1))
if err != nil {
fmt.Fprintf(os.Stderr, "NewArchiveFileSystem failed: %v\n", err)
os.Exit(1)
}
state, _, err := fuse.MountNodeFileSystem(flag.Arg(0), fs, nil)
opts := &fuse.FileSystemOptions{
AttrTimeout: time.Duration(*ttl * float64(time.Second)),
EntryTimeout: time.Duration(*ttl * float64(time.Second)),
}
state, _, err := fuse.MountNodeFileSystem(flag.Arg(0), fs, opts)
if err != nil {
fmt.Printf("Mount fail: %v\n", err)
os.Exit(1)
......@@ -37,5 +65,20 @@ func main() {
state.SetRecordStatistics(*latencies)
state.Debug = *debug
runtime.GC()
if profFile != nil {
pprof.StartCPUProfile(profFile)
defer pprof.StopCPUProfile()
}
if *command != "" {
args := strings.Split(*command, " ")
cmd := exec.Command(args[0], args[1:]...)
cmd.Start()
}
state.Loop()
if memProfFile != nil {
pprof.WriteHeapProfile(memProfFile)
}
}
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