github.com/dim4egster/coreth@v0.10.2/plugin/evm/admin.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  	"fmt"
     8  	"net/http"
     9  
    10  	"github.com/dim4egster/qmallgo/api"
    11  	"github.com/dim4egster/qmallgo/utils/profiler"
    12  	"github.com/ethereum/go-ethereum/log"
    13  )
    14  
    15  // Admin is the API service for admin API calls
    16  type Admin struct {
    17  	vm       *VM
    18  	profiler profiler.Profiler
    19  }
    20  
    21  func NewAdminService(vm *VM, performanceDir string) *Admin {
    22  	return &Admin{
    23  		vm:       vm,
    24  		profiler: profiler.New(performanceDir),
    25  	}
    26  }
    27  
    28  // StartCPUProfiler starts a cpu profile writing to the specified file
    29  func (p *Admin) StartCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
    30  	log.Info("Admin: StartCPUProfiler called")
    31  
    32  	return p.profiler.StartCPUProfiler()
    33  }
    34  
    35  // StopCPUProfiler stops the cpu profile
    36  func (p *Admin) StopCPUProfiler(r *http.Request, _ *struct{}, _ *api.EmptyReply) error {
    37  	log.Info("Admin: StopCPUProfiler called")
    38  
    39  	return p.profiler.StopCPUProfiler()
    40  }
    41  
    42  // MemoryProfile runs a memory profile writing to the specified file
    43  func (p *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
    44  	log.Info("Admin: MemoryProfile called")
    45  
    46  	return p.profiler.MemoryProfile()
    47  }
    48  
    49  // LockProfile runs a mutex profile writing to the specified file
    50  func (p *Admin) LockProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
    51  	log.Info("Admin: LockProfile called")
    52  
    53  	return p.profiler.LockProfile()
    54  }
    55  
    56  type SetLogLevelArgs struct {
    57  	Level string `json:"level"`
    58  }
    59  
    60  func (p *Admin) SetLogLevel(_ *http.Request, args *SetLogLevelArgs, reply *api.EmptyReply) error {
    61  	log.Info("EVM: SetLogLevel called", "logLevel", args.Level)
    62  	if err := p.vm.logger.SetLogLevel(args.Level); err != nil {
    63  		return fmt.Errorf("failed to parse log level: %w ", err)
    64  	}
    65  	return nil
    66  }
    67  
    68  type ConfigReply struct {
    69  	Config *Config `json:"config"`
    70  }
    71  
    72  func (p *Admin) GetVMConfig(_ *http.Request, _ *struct{}, reply *ConfigReply) error {
    73  	reply.Config = &p.vm.config
    74  	return nil
    75  }