From b8d69e777d3bbe51843812d4a31e067ed646ed10 Mon Sep 17 00:00:00 2001 From: jinhoonbang Date: Wed, 30 Oct 2024 16:04:25 -0700 Subject: [PATCH] turn on profiler --- core/main.go | 43 +++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/core/main.go b/core/main.go index 4ff013d9c96..a21a8d0c066 100644 --- a/core/main.go +++ b/core/main.go @@ -3,7 +3,12 @@ package core import ( "fmt" "log" + "net/http" + _ "net/http/pprof" "os" + "runtime" + "runtime/debug" + "time" "github.com/Masterminds/semver/v3" @@ -25,7 +30,45 @@ func init() { } } +// Helper function to convert bytes to megabytes +func bToMb(b uint64) uint64 { + return b / 1024 / 1024 +} + +func printGCStats() { + for { + // Create MemStats and GCStats structs to hold stats data + var memStats runtime.MemStats + var gcStats debug.GCStats + + // Read memory statistics + runtime.ReadMemStats(&memStats) + debug.ReadGCStats(&gcStats) + + // Print memory allocation and GC details + log.Printf("Alloc = %v MiB", bToMb(memStats.Alloc)) + log.Printf("TotalAlloc = %v MiB", bToMb(memStats.TotalAlloc)) + log.Printf("Sys = %v MiB", bToMb(memStats.Sys)) + log.Printf("NumGC = %v", memStats.NumGC) + log.Printf("PauseTotalNs = %v", memStats.PauseTotalNs) + log.Printf("LastGC = %v", time.Unix(0, int64(memStats.LastGC))) + + log.Printf("GC Last Run: %v", gcStats.LastGC) + log.Printf("GC NumGC: %v", gcStats.NumGC) + log.Printf("GC PauseTotal: %v", gcStats.PauseTotal) + log.Printf("GC Pause history (last few GCs): %v", gcStats.Pause) + + // Sleep for the specified interval + time.Sleep(5 * time.Minute) // Adjust interval as needed + } +} + func Main() (code int) { + go printGCStats() // Run printGCStats in a separate goroutine + go func() { + log.Println("Starting pprof server on :6060") + log.Println(http.ListenAndServe(":6060", nil)) + }() recovery.ReportPanics(func() { app := cmd.NewApp(newProductionClient()) if err := app.Run(os.Args); err != nil { diff --git a/go.mod b/go.mod index 4f836787f67..c526544c906 100644 --- a/go.mod +++ b/go.mod @@ -76,7 +76,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.27 github.com/smartcontractkit/chainlink-automation v0.8.0 github.com/smartcontractkit/chainlink-ccip v0.0.0-20241014104242-9227e5c976a7 - github.com/smartcontractkit/chainlink-common v0.3.1-0.20241016235738-9ba7522206c3 + github.com/smartcontractkit/chainlink-common v0.3.1-0.20241101202308-e11c3552f2b5 github.com/smartcontractkit/chainlink-cosmos v0.5.1 github.com/smartcontractkit/chainlink-data-streams v0.1.0 github.com/smartcontractkit/chainlink-feeds v0.1.1 diff --git a/go.sum b/go.sum index 385aaca7a4a..61395784406 100644 --- a/go.sum +++ b/go.sum @@ -1057,8 +1057,8 @@ github.com/smartcontractkit/chainlink-automation v0.8.0 h1:hFz2EHU06bkEfhcqhK8Jd github.com/smartcontractkit/chainlink-automation v0.8.0/go.mod h1:ObdjDfgGIaiE48Bb3yYcx1CeGBm392WlEw92U83LlUA= github.com/smartcontractkit/chainlink-ccip v0.0.0-20241014104242-9227e5c976a7 h1:aMG3BllvgeL/vsqkebuAhWoIWOnitKnN1VxibdzGnYo= github.com/smartcontractkit/chainlink-ccip v0.0.0-20241014104242-9227e5c976a7/go.mod h1:H4BTXnZBhwRdsAFjqWZpB1/f3IZnuB/Ql7pXPmokzXg= -github.com/smartcontractkit/chainlink-common v0.3.1-0.20241016235738-9ba7522206c3 h1:kx/oGE7fgbzIUJAX+l+rN7HuEiOCHWaSwWnsNuGcYZs= -github.com/smartcontractkit/chainlink-common v0.3.1-0.20241016235738-9ba7522206c3/go.mod h1:tsGgeEJc5SUSlfVGSX0wR0EkRU3pM58D6SKF97V68ko= +github.com/smartcontractkit/chainlink-common v0.3.1-0.20241101202308-e11c3552f2b5 h1:E82sW2Rg6JjO7UrHtluz+HWB8LG2wouMgeYEu8wORus= +github.com/smartcontractkit/chainlink-common v0.3.1-0.20241101202308-e11c3552f2b5/go.mod h1:tsGgeEJc5SUSlfVGSX0wR0EkRU3pM58D6SKF97V68ko= github.com/smartcontractkit/chainlink-cosmos v0.5.1 h1:2xeZWh+4/w7xalTdAu8jqgFuxZ291aYTEwZhlQEv/BY= github.com/smartcontractkit/chainlink-cosmos v0.5.1/go.mod h1:c1wUtVxXUqW4PzuCQhuHaBDZFv9XAQjhKTqam7GLGIU= github.com/smartcontractkit/chainlink-data-streams v0.1.0 h1:wcRJRm7eqfbgN+Na+GjAe0/IUn6XwmSagFHqIWHHBGk=