This is an automated email from the ASF dual-hosted git repository. lujiajing pushed a commit to branch add-pprof in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git
commit e2e0dd1c1aadd718faa36f0c1d16f8a47e9a45f0 Author: Megrez Lu <[email protected]> AuthorDate: Fri Jan 28 09:20:40 2022 +0800 support pprof --- banyand/internal/cmd/standalone.go | 3 ++ banyand/prof/pprof.go | 73 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/banyand/internal/cmd/standalone.go b/banyand/internal/cmd/standalone.go index 5bf1058..4fdb06e 100644 --- a/banyand/internal/cmd/standalone.go +++ b/banyand/internal/cmd/standalone.go @@ -26,6 +26,7 @@ import ( "github.com/apache/skywalking-banyandb/banyand/discovery" "github.com/apache/skywalking-banyandb/banyand/liaison" "github.com/apache/skywalking-banyandb/banyand/metadata" + "github.com/apache/skywalking-banyandb/banyand/prof" "github.com/apache/skywalking-banyandb/banyand/query" "github.com/apache/skywalking-banyandb/banyand/queue" "github.com/apache/skywalking-banyandb/banyand/stream" @@ -68,6 +69,7 @@ func newStandaloneCmd() *cobra.Command { if err != nil { l.Fatal().Err(err).Msg("failed to initiate Endpoint transport layer") } + profSvc := prof.NewProfService() // Meta the run Group units. g.Register( @@ -78,6 +80,7 @@ func newStandaloneCmd() *cobra.Command { streamSvc, q, tcp, + profSvc, ) logging := logger.Logging{} standaloneCmd := &cobra.Command{ diff --git a/banyand/prof/pprof.go b/banyand/prof/pprof.go new file mode 100644 index 0000000..4c8754d --- /dev/null +++ b/banyand/prof/pprof.go @@ -0,0 +1,73 @@ +// Licensed to Apache Software Foundation (ASF) under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Apache Software Foundation (ASF) licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package prof + +import ( + "net/http" + _ "net/http/pprof" + + "github.com/apache/skywalking-banyandb/pkg/logger" + "github.com/apache/skywalking-banyandb/pkg/run" +) + +var ( + _ run.Service = (*pprofService)(nil) + _ run.Config = (*pprofService)(nil) +) + +func NewProfService() run.Service { + return &pprofService{ + stopCh: make(chan struct{}), + } +} + +type pprofService struct { + listenAddr string + stopCh chan struct{} + l *logger.Logger +} + +func (p *pprofService) FlagSet() *run.FlagSet { + flagSet := run.NewFlagSet("prof") + flagSet.StringVar(&p.listenAddr, "pprof-listener-addr", "0.0.0.0:6060", "listen addr for pprof") + return flagSet +} + +func (p *pprofService) Validate() error { + return nil +} + +func (p *pprofService) Name() string { + return "pprof-service" +} + +func (p *pprofService) Serve() error { + p.l = logger.GetLogger(p.Name()) + go func() { + p.l.Info().Str("listenAddr", p.listenAddr).Msg("Start pprof server") + _ = http.ListenAndServe(p.listenAddr, nil) + }() + + <-p.stopCh + + return nil +} + +func (p *pprofService) GracefulStop() { + close(p.stopCh) +}
