summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvin <git@vineetk.net>2024-01-12 19:15:35 -0500
committervin <git@vineetk.net>2024-01-12 19:15:35 -0500
commit4d0051f5165c5455f8780a163cfb225754aaa7d9 (patch)
treeb9d61787261170b5eaf933817c7bea18d56e4897
parent3fbd4dc64502918c91d30632a84110b128cc5b90 (diff)
add cpu profiling support
-rw-r--r--main.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/main.go b/main.go
index 6f97efa..fa99806 100644
--- a/main.go
+++ b/main.go
@@ -5,6 +5,7 @@ import (
5 "fmt" 5 "fmt"
6 "net/http" 6 "net/http"
7 "os" 7 "os"
8 "runtime/pprof"
8) 9)
9 10
10var base_link string 11var base_link string
@@ -22,6 +23,7 @@ func usage() {
22 fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID") 23 fmt.Println(" -F, --listfav\tlists favourited canvas courses with name and ID")
23 fmt.Println(" -v, --verbose\tprints with verbose output") 24 fmt.Println(" -v, --verbose\tprints with verbose output")
24 fmt.Println(" -h, --help\tdisplays this help message") 25 fmt.Println(" -h, --help\tdisplays this help message")
26 fmt.Println(" -p, --profile\twrites cpu profile to a file")
25} 27}
26 28
27func main() { 29func main() {
@@ -32,6 +34,7 @@ func main() {
32 var listall bool 34 var listall bool
33 var listfav bool 35 var listfav bool
34 var help bool 36 var help bool
37 var cpuprofile string
35 38
36 flag.StringVar(&code, "code", "", "5 character attendance code") 39 flag.StringVar(&code, "code", "", "5 character attendance code")
37 flag.StringVar(&code, "c", "", "5 character attendance code") 40 flag.StringVar(&code, "c", "", "5 character attendance code")
@@ -45,9 +48,27 @@ func main() {
45 flag.BoolVar(&verbose, "v", false, "verbose output") 48 flag.BoolVar(&verbose, "v", false, "verbose output")
46 flag.BoolVar(&help, "help", false, "view usage message") 49 flag.BoolVar(&help, "help", false, "view usage message")
47 flag.BoolVar(&help, "h", false, "view usage message") 50 flag.BoolVar(&help, "h", false, "view usage message")
51 flag.StringVar(&cpuprofile, "p", "", "CPU profiling report location")
52 flag.StringVar(&cpuprofile, "profile", "", "CPU profiling report location")
48 53
49 flag.Parse() 54 flag.Parse()
50 55
56 if cpuprofile != "" {
57 cpuf, err := os.Create(cpuprofile)
58 if err != nil {
59 fmt.Println(err)
60 os.Exit(1)
61 }
62 defer cpuf.Close()
63
64 err = pprof.StartCPUProfile(cpuf)
65 if err != nil {
66 fmt.Println(err)
67 os.Exit(1)
68 }
69 defer pprof.StopCPUProfile()
70 }
71
51 if code == "" && course == -1 && !listall && !listfav && !help { 72 if code == "" && course == -1 && !listall && !listfav && !help {
52 usage() 73 usage()
53 os.Exit(1) 74 os.Exit(1)