Skip to content

Commit

Permalink
Add profiling (and flag for it)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geert-Johan Riemer committed Mar 13, 2014
1 parent 49f8ee3 commit 0a1a3c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*sublime*
/gomatrix
/gomatrix
/gomatrix.prof
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math/rand"
"os"
"os/signal"
"runtime/pprof"
"time"
)

Expand All @@ -19,6 +20,9 @@ var opts struct {

// enable logging
Logging bool `short:"l" long:"log" description:"Enable logging debug messages to ~/.gomatrix-log."`

// enable profiling
Profile string `short:"p" long:"profile" description:"Write profile to given file path"`
}

// array with half width kanas as Go runes
Expand Down Expand Up @@ -85,6 +89,17 @@ func main() {
return
}

// Start profiling (if required)
if len(opts.Profile) > 0 {
f, err := os.Create(opts.Profile)
if err != nil {
fmt.Printf("Error opening profiling file: %s\n", err)
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}

// Juse a println for fun..
fmt.Println("Opening connection to The Matrix.. Please stand by..")

Expand Down Expand Up @@ -245,5 +260,4 @@ func main() {
termbox.Close()
log.Println("stopping gomatrix")
fmt.Println("Thank you for connecting with Morpheus' Matrix API v4.2. Have a nice day!")
os.Exit(0)
}

0 comments on commit 0a1a3c3

Please sign in to comment.