1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
// Copyright 2016 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// statfs is a main driver for the file system from
// github.com/hanwen/go-fuse/benchmark, intended for benchmarking FUSE
// libraries.
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"os/exec"
"runtime"
"runtime/pprof"
"strings"
"syscall"
"time"
"github.com/hanwen/go-fuse/v2/benchmark"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
)
func main() {
// Scans the arg list and sets up flags
debug := flag.Bool("debug", false, "print debugging messages.")
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.Duration("ttl", time.Second, "attribute/entry cache TTL.")
flag.Parse()
if flag.NArg() < 2 {
fmt.Fprintf(os.Stderr, "usage: %s MOUNTPOINT FILENAMES-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)
}
}
root := &benchmark.StatFS{}
lines := benchmark.ReadLines(flag.Arg(1))
for _, l := range lines {
root.AddFile(strings.TrimSpace(l),
fuse.Attr{Mode: syscall.S_IFREG})
}
opts := &fs.Options{
AttrTimeout: ttl,
EntryTimeout: ttl,
}
opts.Debug = *debug
server, err := fs.Mount(flag.Arg(0), root, opts)
if err != nil {
log.Fatalf("Mount fail: %v\n", err)
}
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.Stdout = os.Stdout
cmd.Start()
}
server.Wait()
if memProfFile != nil {
pprof.WriteHeapProfile(memProfFile)
}
}
|