diff --git a/.gitignore b/.gitignore index 5c86422da..ce1d39f93 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ _obj [68].out _test _testmain.go +_go_.[568] diff --git a/build.pl b/build.pl index 7b6db2edf..636f81a62 100755 --- a/build.pl +++ b/build.pl @@ -352,6 +352,7 @@ __DATA__ TARGET: clients/go/camget TARGET: clients/go/camput +TARGET: clients/go/cammount TARGET: clients/go/camsync TARGET: lib/go/camli/auth TARGET: lib/go/camli/blobref diff --git a/clients/go/cammount/.gitignore b/clients/go/cammount/.gitignore new file mode 100644 index 000000000..dc711e52b --- /dev/null +++ b/clients/go/cammount/.gitignore @@ -0,0 +1,2 @@ +cammount +_go_.[568] diff --git a/clients/go/cammount/main.go b/clients/go/cammount/main.go new file mode 100644 index 000000000..3ee135956 --- /dev/null +++ b/clients/go/cammount/main.go @@ -0,0 +1,94 @@ +/* +Copyright 2011 Google Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package main + +import ( + "flag" + "fmt" + "os" + "sort" + + "camli/third_party/github.com/hanwen/go-fuse/fuse" +) + +func PrintMap(m map[string]float64) { + keys := make([]string, len(m)) + for k, _ := range m { + keys = append(keys, k) + } + + sort.SortStrings(keys) + for _, k := range keys { + if m[k] > 0 { + fmt.Println(k, m[k]) + } + } +} + +func main() { + // Scans the arg list and sets up flags + debug := flag.Bool("debug", false, "print debugging messages.") + threaded := flag.Bool("threaded", true, "switch off threading; print debugging messages.") + flag.Parse() + if flag.NArg() < 2 { + // TODO - where to get program name? + fmt.Println("usage: main ORIGINAL MOUNTPOINT") + os.Exit(2) + } + + orig := flag.Arg(0) + fs := fuse.NewLoopbackFileSystem(orig) + timing := fuse.NewTimingPathFilesystem(fs) + + var opts fuse.PathFileSystemConnectorOptions + + opts.AttrTimeout = 1.0 + opts.EntryTimeout = 1.0 + opts.NegativeTimeout = 1.0 + + fs.SetOptions(&opts) + + conn := fuse.NewPathFileSystemConnector(timing) + rawTiming := fuse.NewTimingRawFilesystem(conn) + + state := fuse.NewMountState(rawTiming) + state.Debug = *debug + + mountPoint := flag.Arg(1) + err := state.Mount(mountPoint) + if err != nil { + fmt.Printf("MountFuse fail: %v\n", err) + os.Exit(1) + } + + fmt.Printf("Mounted %s on %s (threaded=%v, debug=%v)\n", orig, mountPoint, *threaded, *debug) + state.Loop(*threaded) + fmt.Println("Finished", state.Stats()) + + counts := state.OperationCounts() + fmt.Println("Counts: ", counts) + + latency := state.Latencies() + fmt.Println("MountState latency (ms):") + PrintMap(latency) + + latency = timing.Latencies() + fmt.Println("Path ops (ms):", latency) + + latency = rawTiming.Latencies() + fmt.Println("Raw FS (ms):", latency) +}