gitlab.com/flarenetwork/coreth@v0.1.1/plugin/evm/performance.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package evm
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/ava-labs/avalanchego/utils/profiler"
    10  	"github.com/ethereum/go-ethereum/log"
    11  )
    12  
    13  // Performance is the API service for coreth performance
    14  type Performance struct {
    15  	profiler profiler.Profiler
    16  }
    17  
    18  func NewPerformanceService(dir string) *Performance {
    19  	return &Performance{
    20  		profiler: profiler.New(dir),
    21  	}
    22  }
    23  
    24  // StartCPUProfiler starts a cpu profile writing to the specified file
    25  func (p *Performance) StartCPUProfiler(ctx context.Context) (bool, error) {
    26  	log.Info("Admin: StartCPUProfiler called")
    27  
    28  	err := p.profiler.StartCPUProfiler()
    29  	return err == nil, err
    30  }
    31  
    32  // StopCPUProfiler stops the cpu profile
    33  func (p *Performance) StopCPUProfiler(ctx context.Context) (bool, error) {
    34  	log.Info("Admin: StopCPUProfiler called")
    35  
    36  	err := p.profiler.StopCPUProfiler()
    37  	return err == nil, err
    38  }
    39  
    40  // MemoryProfile runs a memory profile writing to the specified file
    41  func (p *Performance) MemoryProfile(ctx context.Context) (bool, error) {
    42  	log.Info("Admin: MemoryProfile called")
    43  
    44  	err := p.profiler.MemoryProfile()
    45  	return err == nil, err
    46  }
    47  
    48  // LockProfile runs a mutex profile writing to the specified file
    49  func (p *Performance) LockProfile(ctx context.Context) (bool, error) {
    50  	log.Info("Admin: LockProfile called")
    51  
    52  	err := p.profiler.LockProfile()
    53  	return err == nil, err
    54  }