Add --cpuprofile flag

This commit is contained in:
Jakob Unterwurzacher 2015-09-18 22:14:07 +02:00
parent e84c1e3741
commit 8fe5ec7381
2 changed files with 25 additions and 9 deletions

18
main.go
View File

@ -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){

View File

@ -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")