Skip to content

Commit

Permalink
turn on profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhoonbang committed Nov 1, 2024
1 parent 57ad825 commit 5cecea6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
43 changes: 43 additions & 0 deletions core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ package core
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"

Check failure on line 7 in core/main.go

View workflow job for this annotation

GitHub Actions / lint

G108: Profiling endpoint is automatically exposed on /debug/pprof (gosec)
"os"
"runtime"
"runtime/debug"
"time"

"github.com/Masterminds/semver/v3"

Expand All @@ -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)))

Check failure on line 54 in core/main.go

View workflow job for this annotation

GitHub Actions / lint

G115: integer overflow conversion uint64 -> int64 (gosec)

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))

Check failure on line 70 in core/main.go

View workflow job for this annotation

GitHub Actions / lint

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
}()
recovery.ReportPanics(func() {
app := cmd.NewApp(newProductionClient())
if err := app.Run(os.Args); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241101190515-1f8bf8a78b1f
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.20241101190515-1f8bf8a78b1f h1:r8MoMkiiliZbuBrbiEVdLvVnKNUKs003SEBLLvMzKrw=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241101190515-1f8bf8a78b1f/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=
Expand Down

0 comments on commit 5cecea6

Please sign in to comment.