Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Performance] move out of ./utils/debug to ./module/profiler #2897

Merged
merged 1 commit into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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