github.com/imran-kn/cilium-fork@v1.6.9/pkg/pprof/pprof.go (about)

     1  // Copyright 2017 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Package pprof enables use of pprof in Cilium
    16  package pprof
    17  
    18  import (
    19  	"net/http"
    20  	_ "net/http/pprof"
    21  
    22  	"github.com/cilium/cilium/pkg/logging"
    23  	"github.com/cilium/cilium/pkg/logging/logfields"
    24  )
    25  
    26  var log = logging.DefaultLogger.WithField(logfields.LogSubsys, "pprof")
    27  
    28  const apiAddress = "localhost:6060"
    29  
    30  // Enable runs an HTTP server to serve the pprof API
    31  func Enable() {
    32  	go func() {
    33  		if err := http.ListenAndServe(apiAddress, nil); err != nil {
    34  			log.WithError(err).Warn("Unable to serve pprof API")
    35  		}
    36  	}()
    37  }