Skip to content

Commit

Permalink
Merge #2897
Browse files Browse the repository at this point in the history
2897: [Profiler] move out of ./utils/debug to ./module/profiler r=SaveTheRbtz a=SaveTheRbtz

While here added a comment.  Noop otherwise.

Issue: https://github.com/dapperlabs/flow-go/issues/6310

Co-authored-by: Alexey Ivanov <[email protected]>
  • Loading branch information
bors[bot] and SaveTheRbtz authored Jul 29, 2022
2 parents d19fa03 + 02a9932 commit bc69bde
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions admin/commands/common/set_profiler_enabled.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
)
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions utils/debug/profiler.go → module/profiler/profiler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package debug
package profiler

import (
"context"
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package debug_test
package profiler_test

import (
"os"
Expand All @@ -8,15 +8,15 @@ 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"
)

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

0 comments on commit bc69bde

Please sign in to comment.