summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2015-09-18 22:14:07 +0200
committerJakob Unterwurzacher2015-09-18 22:14:07 +0200
commit8fe5ec7381778bbbf90a7ad0e9d1f05cb2d9ac23 (patch)
tree567874364416aafa400336a103d0423f4a76f0f3
parente84c1e3741bd7f7b3be8a424ee142005b1e7601f (diff)
Add --cpuprofile flag
-rw-r--r--main.go18
-rw-r--r--main_test.go16
2 files changed, 25 insertions, 9 deletions
diff --git a/main.go b/main.go
index f974e7b..4ee9080 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
package main
import (
+ "runtime/pprof"
"io/ioutil"
"flag"
"fmt"
@@ -73,7 +74,19 @@ func main() {
flag.BoolVar(&fusedebug, "fusedebug", false, "Enable fuse library debug output")
flag.BoolVar(&init, "init", false, "Initialize encrypted directory")
flag.BoolVar(&zerokey, "zerokey", false, "Use all-zero dummy master key")
+ var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
+
flag.Parse()
+ if *cpuprofile != "" {
+ f, err := os.Create(*cpuprofile)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(ERREXIT_INIT)
+ }
+ fmt.Printf("Writing CPU profile to %s\n", *cpuprofile)
+ pprof.StartCPUProfile(f)
+ defer pprof.StopCPUProfile()
+ }
if debug {
cryptfs.Debug.Enable()
cryptfs.Debug.Printf("Debug output enabled\n")
@@ -102,7 +115,7 @@ func main() {
key := make([]byte, cryptfs.KEY_LEN)
if zerokey {
fmt.Printf("Zerokey mode active: using all-zero dummy master key.\n")
- fmt.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL.\n")
+ fmt.Printf("ZEROKEY MODE PROVIDES NO SECURITY AT ALL AND SHOULD ONLY BE USED FOR TESTING.\n")
} else {
cfname := filepath.Join(cipherdir, cryptfs.ConfDefaultName)
_, err = os.Stat(cfname)
@@ -218,9 +231,6 @@ func cluefsFrontend(key []byte, cipherdir string, mountpoint string) {
fmt.Println(err)
os.Exit(ERREXIT_MOUNT2)
}
-
- // We are done
- os.Exit(0)
}
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool){
diff --git a/main_test.go b/main_test.go
index 667d626..93aa6ff 100644
--- a/main_test.go
+++ b/main_test.go
@@ -16,12 +16,16 @@ const tmpDir = "main_test_tmp/"
const plainDir = tmpDir + "plain/"
const cipherDir = tmpDir + "cipher/"
-func TestMain(m *testing.M) {
-
+func unmount() error {
fu := exec.Command("fusermount", "-u", plainDir)
fu.Stdout = os.Stdout
fu.Stderr = os.Stderr
- fu.Run()
+ return fu.Run()
+}
+
+func TestMain(m *testing.M) {
+
+ unmount()
os.RemoveAll(tmpDir)
err := os.MkdirAll(plainDir, 0777)
@@ -34,6 +38,7 @@ func TestMain(m *testing.M) {
panic("Could not create cipherDir")
}
+ //c := exec.Command("./gocryptfs", "--zerokey", "--cpuprofile", "/tmp/gcfs.cpu", cipherDir, plainDir)
c := exec.Command("./gocryptfs", "--zerokey", cipherDir, plainDir)
c.Stdout = os.Stdout
c.Stderr = os.Stderr
@@ -43,7 +48,7 @@ func TestMain(m *testing.M) {
r := m.Run()
- fu.Run()
+ unmount()
os.Exit(r)
}
@@ -142,7 +147,7 @@ func BenchmarkStreamRead(t *testing.B) {
if t.N > mb {
// Grow file so we can satisfy the test
- fmt.Printf("Growing file to %d MB\n", t.N)
+ fmt.Printf("Growing file to %d MB... ", t.N)
f2, err := os.OpenFile(fn, os.O_WRONLY | os.O_APPEND, 0666)
if err != nil {
fmt.Println(err)
@@ -156,6 +161,7 @@ func BenchmarkStreamRead(t *testing.B) {
}
}
f2.Close()
+ fmt.Printf("done\n")
}
file, err := os.Open(plainDir + "BenchmarkWrite")