Add "-memprofile" option

This commit is contained in:
Jakob Unterwurzacher 2016-01-21 23:55:37 +01:00
parent d163169655
commit cec2da3e33
1 changed files with 23 additions and 5 deletions

28
main.go
View File

@ -38,8 +38,9 @@ const (
type argContainer struct { type argContainer struct {
debug, init, zerokey, fusedebug, openssl, passwd, foreground, version, debug, init, zerokey, fusedebug, openssl, passwd, foreground, version,
plaintextnames, quiet, diriv, emenames, gcmiv128 bool plaintextnames, quiet, diriv, emenames, gcmiv128 bool
masterkey, mountpoint, cipherdir, cpuprofile, config, extpass string masterkey, mountpoint, cipherdir, cpuprofile, config, extpass,
notifypid, scryptn int memprofile string
notifypid, scryptn int
} }
var flagSet *flag.FlagSet var flagSet *flag.FlagSet
@ -149,14 +150,14 @@ func main() {
flagSet.BoolVar(&args.passwd, "passwd", false, "Change password") flagSet.BoolVar(&args.passwd, "passwd", false, "Change password")
flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground") flagSet.BoolVar(&args.foreground, "f", false, "Stay in the foreground")
flagSet.BoolVar(&args.version, "version", false, "Print version and exit") flagSet.BoolVar(&args.version, "version", false, "Print version and exit")
flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt "+ flagSet.BoolVar(&args.plaintextnames, "plaintextnames", false, "Do not encrypt file names")
"file names")
flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages") flagSet.BoolVar(&args.quiet, "q", false, "Quiet - silence informational messages")
flagSet.BoolVar(&args.diriv, "diriv", true, "Use per-directory file name IV") flagSet.BoolVar(&args.diriv, "diriv", true, "Use per-directory file name IV")
flagSet.BoolVar(&args.emenames, "emenames", true, "Use EME filename encryption. This option implies diriv.") flagSet.BoolVar(&args.emenames, "emenames", true, "Use EME filename encryption. This option implies diriv.")
flagSet.BoolVar(&args.gcmiv128, "gcmiv128", true, "Use an 128-bit IV for GCM encryption instead of Go's default of 96 bits") flagSet.BoolVar(&args.gcmiv128, "gcmiv128", true, "Use an 128-bit IV for GCM encryption instead of Go's default of 96 bits")
flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key") flagSet.StringVar(&args.masterkey, "masterkey", "", "Mount with explicit master key")
flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file") flagSet.StringVar(&args.cpuprofile, "cpuprofile", "", "Write cpu profile to specified file")
flagSet.StringVar(&args.memprofile, "memprofile", "", "Write memory profile to specified file")
flagSet.StringVar(&args.config, "config", "", "Use specified config file instead of CIPHERDIR/gocryptfs.conf") flagSet.StringVar(&args.config, "config", "", "Use specified config file instead of CIPHERDIR/gocryptfs.conf")
flagSet.StringVar(&args.extpass, "extpass", "", "Use external program for the password prompt") flagSet.StringVar(&args.extpass, "extpass", "", "Use external program for the password prompt")
flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+ flagSet.IntVar(&args.notifypid, "notifypid", 0, "Send USR1 to the specified process after "+
@ -206,15 +207,32 @@ func main() {
} }
// "-cpuprofile" // "-cpuprofile"
if args.cpuprofile != "" { if args.cpuprofile != "" {
cryptfs.Info.Printf("Writing CPU profile to %s", args.cpuprofile)
f, err := os.Create(args.cpuprofile) f, err := os.Create(args.cpuprofile)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
os.Exit(ERREXIT_INIT) os.Exit(ERREXIT_INIT)
} }
cryptfs.Info.Printf("Writing CPU profile to %s", args.cpuprofile)
pprof.StartCPUProfile(f) pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile() defer pprof.StopCPUProfile()
} }
// "-memprofile"
if args.memprofile != "" {
cryptfs.Info.Printf("Writing mem profile to %s", args.memprofile)
f, err := os.Create(args.memprofile)
if err != nil {
fmt.Println(err)
os.Exit(ERREXIT_INIT)
}
defer func() {
pprof.WriteHeapProfile(f)
f.Close()
return
}()
}
if args.cpuprofile != "" || args.memprofile != "" {
fmt.Printf("Note: You must unmount gracefully, otherwise the profile file(s) will stay empty!\n")
}
// "-openssl" // "-openssl"
if args.openssl == false { if args.openssl == false {
cryptfs.Info.Printf("Openssl disabled") cryptfs.Info.Printf("Openssl disabled")