From 02a9932efa6bbb73a9215d7f729bb852d611ba33 Mon Sep 17 00:00:00 2001 From: Alexey Ivanov Date: Fri, 29 Jul 2022 13:30:33 -0700 Subject: [PATCH] [Profiler] move out of ./utils/debug to ./module/profiler --- admin/commands/common/set_profiler_enabled.go | 4 ++-- cmd/scaffold.go | 4 ++-- {utils/debug => module/profiler}/profiler.go | 5 +++-- {utils/debug => module/profiler}/profiler_test.go | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) rename {utils/debug => module/profiler}/profiler.go (94%) rename {utils/debug => module/profiler}/profiler_test.go (81%) diff --git a/admin/commands/common/set_profiler_enabled.go b/admin/commands/common/set_profiler_enabled.go index ed2a8f04c0d..c353ba6fa23 100644 --- a/admin/commands/common/set_profiler_enabled.go +++ b/admin/commands/common/set_profiler_enabled.go @@ -6,7 +6,7 @@ import ( "github.com/onflow/flow-go/admin" "github.com/onflow/flow-go/admin/commands" - "github.com/onflow/flow-go/utils/debug" + "github.com/onflow/flow-go/module/profiler" ) var _ commands.AdminCommand = (*SetProfilerEnabledCommand)(nil) @@ -15,7 +15,7 @@ type SetProfilerEnabledCommand struct{} func (s *SetProfilerEnabledCommand) Handler(ctx context.Context, req *admin.CommandRequest) (interface{}, error) { enabled := req.ValidatorData.(bool) - debug.SetProfilerEnabled(enabled) + profiler.SetProfilerEnabled(enabled) return "ok", nil } diff --git a/cmd/scaffold.go b/cmd/scaffold.go index 721e7301a89..91ef786a2ca 100644 --- a/cmd/scaffold.go +++ b/cmd/scaffold.go @@ -38,6 +38,7 @@ import ( "github.com/onflow/flow-go/module/local" "github.com/onflow/flow-go/module/mempool/herocache" "github.com/onflow/flow-go/module/metrics" + "github.com/onflow/flow-go/module/profiler" "github.com/onflow/flow-go/module/synchronization" "github.com/onflow/flow-go/module/trace" "github.com/onflow/flow-go/module/util" @@ -57,7 +58,6 @@ import ( bstorage "github.com/onflow/flow-go/storage/badger" "github.com/onflow/flow-go/storage/badger/operation" sutil "github.com/onflow/flow-go/storage/util" - "github.com/onflow/flow-go/utils/debug" "github.com/onflow/flow-go/utils/io" "github.com/onflow/flow-go/utils/logging" ) @@ -534,7 +534,7 @@ func (fnb *FlowNodeBuilder) initProfiler() { // note: by default the Golang heap profiling rate is on and can be set even if the profiler is NOT enabled runtime.MemProfileRate = fnb.BaseConfig.profilerMemProfileRate - profiler, err := debug.NewAutoProfiler( + profiler, err := profiler.New( fnb.Logger, fnb.BaseConfig.profilerDir, fnb.BaseConfig.profilerInterval, diff --git a/utils/debug/profiler.go b/module/profiler/profiler.go similarity index 94% rename from utils/debug/profiler.go rename to module/profiler/profiler.go index 92f840591a8..c119efed0b2 100644 --- a/utils/debug/profiler.go +++ b/module/profiler/profiler.go @@ -1,4 +1,4 @@ -package debug +package profiler import ( "context" @@ -34,7 +34,8 @@ type AutoProfiler struct { duration time.Duration } -func NewAutoProfiler(log zerolog.Logger, dir string, interval time.Duration, duration time.Duration, enabled bool) (*AutoProfiler, error) { +// New creates a new AutoProfiler instance performing profiling every interval for duration. +func New(log zerolog.Logger, dir string, interval time.Duration, duration time.Duration, enabled bool) (*AutoProfiler, error) { SetProfilerEnabled(enabled) err := os.MkdirAll(dir, os.ModePerm) diff --git a/utils/debug/profiler_test.go b/module/profiler/profiler_test.go similarity index 81% rename from utils/debug/profiler_test.go rename to module/profiler/profiler_test.go index eea2ce17a1e..3ffe389509e 100644 --- a/utils/debug/profiler_test.go +++ b/module/profiler/profiler_test.go @@ -1,4 +1,4 @@ -package debug_test +package profiler_test import ( "os" @@ -8,7 +8,7 @@ import ( "github.com/rs/zerolog" "github.com/stretchr/testify/require" - "github.com/onflow/flow-go/utils/debug" + "github.com/onflow/flow-go/module/profiler" "github.com/onflow/flow-go/utils/unittest" ) @@ -16,7 +16,7 @@ func TestProfiler(t *testing.T) { t.Parallel() t.Run("profilerEnabled", func(t *testing.T) { unittest.RunWithTempDir(t, func(tempDir string) { - p, err := debug.NewAutoProfiler(zerolog.Nop(), tempDir, time.Millisecond*100, time.Millisecond*100, true) + p, err := profiler.New(zerolog.Nop(), tempDir, time.Millisecond*100, time.Millisecond*100, true) require.NoError(t, err) unittest.AssertClosesBefore(t, p.Ready(), 5*time.Second)