Add Flag to enable cpu profiling

This commit is contained in:
Jan Bader 2020-11-22 01:23:07 +01:00
parent 29fa093184
commit 594a88c3ec

12
main.go
View File

@ -6,9 +6,11 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/pprof"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
@ -21,10 +23,20 @@ var promptForDelete = flag.Bool("delete-prompt", false, "Ask which file to keep
var moveToFolder = flag.String("move-files", "", "Move files to <path> instead of deleting them") var moveToFolder = flag.String("move-files", "", "Move files to <path> instead of deleting them")
var force = flag.Bool("force", false, "Actually delete files. Without this options, the files to be deleted are only printed") var force = flag.Bool("force", false, "Actually delete files. Without this options, the files to be deleted are only printed")
var verbose = flag.Bool("verbose", false, "Output additional information") var verbose = flag.Bool("verbose", false, "Output additional information")
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
func main() { func main() {
flag.Parse() flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
if *verbose { if *verbose {
printConfiguration() printConfiguration()
} }