Skip to content

Commit

Permalink
Merge pull request #105 from TIBCOSoftware/cpu-mem-profiling-support
Browse files Browse the repository at this point in the history
Added profiling support in main.go template
  • Loading branch information
vijaynalawade authored Apr 25, 2018
2 parents a29304a + a81fb4c commit 80636ce
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ import (
"os"
"os/signal"
"syscall"
"runtime/pprof"
"flag"
"runtime"
"github.com/TIBCOSoftware/flogo-lib/app"
"github.com/TIBCOSoftware/flogo-lib/engine"
"github.com/TIBCOSoftware/flogo-lib/logger"
)
var log = logger.GetLogger("main-engine")
var cpuprofile = flag.String("cpuprofile", "", "Writes CPU profiling for the current process to the specified file")
var memprofile = flag.String("memprofile", "", "Writes memory profiling for the current process to the specified file")
var (
cp app.ConfigProvider
)
Expand All @@ -68,6 +72,17 @@ func main() {
fmt.Println(err.Error())
os.Exit(1)
}
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create CPU profiling file due to error - %s", err.Error()))
os.Exit(1)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
e, err := engine.New(app)
if err != nil {
Expand All @@ -87,6 +102,21 @@ func main() {
e.Stop()
if *memprofile != "" {
f, err := os.Create(*memprofile)
if err != nil {
fmt.Println(fmt.Sprintf("Failed to create memory profiling file due to error - %s", err.Error()))
os.Exit(1)
}
runtime.GC() // get up-to-date statistics
if err := pprof.WriteHeapProfile(f); err != nil {
fmt.Println(fmt.Sprintf("Failed to write memory profiling data to file due to error - %s", err.Error()))
os.Exit(1)
}
f.Close()
}
os.Exit(code)
}
Expand Down

0 comments on commit 80636ce

Please sign in to comment.