Add --cpuprofile flag
This commit is contained in:
parent
e84c1e3741
commit
8fe5ec7381
18
main.go
18
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"runtime/pprof"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -73,7 +74,19 @@ func main() {
|
|||||||
flag.BoolVar(&fusedebug, "fusedebug", false, "Enable fuse library debug output")
|
flag.BoolVar(&fusedebug, "fusedebug", false, "Enable fuse library debug output")
|
||||||
flag.BoolVar(&init, "init", false, "Initialize encrypted directory")
|
flag.BoolVar(&init, "init", false, "Initialize encrypted directory")
|
||||||
flag.BoolVar(&zerokey, "zerokey", false, "Use all-zero dummy master key")
|
flag.BoolVar(&zerokey, "zerokey", false, "Use all-zero dummy master key")
|
||||||
|
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
|
||||||
|
|
||||||
flag.Parse()
|
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 {
|
if debug {
|
||||||
cryptfs.Debug.Enable()
|
cryptfs.Debug.Enable()
|
||||||
cryptfs.Debug.Printf("Debug output enabled\n")
|
cryptfs.Debug.Printf("Debug output enabled\n")
|
||||||
@ -102,7 +115,7 @@ func main() {
|
|||||||
key := make([]byte, cryptfs.KEY_LEN)
|
key := make([]byte, cryptfs.KEY_LEN)
|
||||||
if zerokey {
|
if zerokey {
|
||||||
fmt.Printf("Zerokey mode active: using all-zero dummy master key.\n")
|
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 {
|
} else {
|
||||||
cfname := filepath.Join(cipherdir, cryptfs.ConfDefaultName)
|
cfname := filepath.Join(cipherdir, cryptfs.ConfDefaultName)
|
||||||
_, err = os.Stat(cfname)
|
_, err = os.Stat(cfname)
|
||||||
@ -218,9 +231,6 @@ func cluefsFrontend(key []byte, cipherdir string, mountpoint string) {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(ERREXIT_MOUNT2)
|
os.Exit(ERREXIT_MOUNT2)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are done
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool){
|
func pathfsFrontend(key []byte, cipherdir string, mountpoint string, debug bool){
|
||||||
|
16
main_test.go
16
main_test.go
@ -16,12 +16,16 @@ const tmpDir = "main_test_tmp/"
|
|||||||
const plainDir = tmpDir + "plain/"
|
const plainDir = tmpDir + "plain/"
|
||||||
const cipherDir = tmpDir + "cipher/"
|
const cipherDir = tmpDir + "cipher/"
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func unmount() error {
|
||||||
|
|
||||||
fu := exec.Command("fusermount", "-u", plainDir)
|
fu := exec.Command("fusermount", "-u", plainDir)
|
||||||
fu.Stdout = os.Stdout
|
fu.Stdout = os.Stdout
|
||||||
fu.Stderr = os.Stderr
|
fu.Stderr = os.Stderr
|
||||||
fu.Run()
|
return fu.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMain(m *testing.M) {
|
||||||
|
|
||||||
|
unmount()
|
||||||
os.RemoveAll(tmpDir)
|
os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
err := os.MkdirAll(plainDir, 0777)
|
err := os.MkdirAll(plainDir, 0777)
|
||||||
@ -34,6 +38,7 @@ func TestMain(m *testing.M) {
|
|||||||
panic("Could not create cipherDir")
|
panic("Could not create cipherDir")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//c := exec.Command("./gocryptfs", "--zerokey", "--cpuprofile", "/tmp/gcfs.cpu", cipherDir, plainDir)
|
||||||
c := exec.Command("./gocryptfs", "--zerokey", cipherDir, plainDir)
|
c := exec.Command("./gocryptfs", "--zerokey", cipherDir, plainDir)
|
||||||
c.Stdout = os.Stdout
|
c.Stdout = os.Stdout
|
||||||
c.Stderr = os.Stderr
|
c.Stderr = os.Stderr
|
||||||
@ -43,7 +48,7 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
r := m.Run()
|
r := m.Run()
|
||||||
|
|
||||||
fu.Run()
|
unmount()
|
||||||
os.Exit(r)
|
os.Exit(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +147,7 @@ func BenchmarkStreamRead(t *testing.B) {
|
|||||||
|
|
||||||
if t.N > mb {
|
if t.N > mb {
|
||||||
// Grow file so we can satisfy the test
|
// 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)
|
f2, err := os.OpenFile(fn, os.O_WRONLY | os.O_APPEND, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@ -156,6 +161,7 @@ func BenchmarkStreamRead(t *testing.B) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
f2.Close()
|
f2.Close()
|
||||||
|
fmt.Printf("done\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.Open(plainDir + "BenchmarkWrite")
|
file, err := os.Open(plainDir + "BenchmarkWrite")
|
||||||
|
Loading…
Reference in New Issue
Block a user