mirror of
https://github.com/luxfi/coreth.git
synced 2026-10-30 17:00:51 +00:00
- Update vm to v1.0.30 (simplified SameChain API) - Update threshold to v1.5.5 (Signature.UnmarshalBinary) - Fix AveragerHeap usage (not generic) - Fix Header.Number access (Number.Uint64() not NumberU64()) - Use rpc.Serve instead of rpc/chain.Serve (ZAP transport)
85 lines
2.2 KiB
Go
85 lines
2.2 KiB
Go
// Copyright (C) 2019-2025, Lux Industries, Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package evm
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/luxfi/coreth/plugin/evm/client"
|
|
log "github.com/luxfi/log"
|
|
"github.com/luxfi/metric/profiler"
|
|
"github.com/luxfi/vm/api"
|
|
)
|
|
|
|
// Admin is the API service for admin API calls
|
|
type Admin struct {
|
|
vm *VM
|
|
profiler profiler.Profiler
|
|
}
|
|
|
|
func NewAdminService(vm *VM, performanceDir string) *Admin {
|
|
return &Admin{
|
|
vm: vm,
|
|
profiler: profiler.New(performanceDir),
|
|
}
|
|
}
|
|
|
|
// StartCPUProfiler starts a cpu profile writing to the specified file
|
|
func (p *Admin) StartCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
|
|
log.Info("Admin: StartCPUProfiler called")
|
|
|
|
p.vm.runtime.Lock.Lock()
|
|
defer p.vm.runtime.Lock.Unlock()
|
|
|
|
return p.profiler.StartCPUProfiler()
|
|
}
|
|
|
|
// StopCPUProfiler stops the cpu profile
|
|
func (p *Admin) StopCPUProfiler(r *http.Request, _ *struct{}, _ *api.EmptyReply) error {
|
|
log.Info("Admin: StopCPUProfiler called")
|
|
|
|
p.vm.runtime.Lock.Lock()
|
|
defer p.vm.runtime.Lock.Unlock()
|
|
|
|
return p.profiler.StopCPUProfiler()
|
|
}
|
|
|
|
// MemoryProfile runs a memory profile writing to the specified file
|
|
func (p *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
|
|
log.Info("Admin: MemoryProfile called")
|
|
|
|
p.vm.runtime.Lock.Lock()
|
|
defer p.vm.runtime.Lock.Unlock()
|
|
|
|
return p.profiler.MemoryProfile()
|
|
}
|
|
|
|
// LockProfile runs a mutex profile writing to the specified file
|
|
func (p *Admin) LockProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
|
|
log.Info("Admin: LockProfile called")
|
|
|
|
p.vm.runtime.Lock.Lock()
|
|
defer p.vm.runtime.Lock.Unlock()
|
|
|
|
return p.profiler.LockProfile()
|
|
}
|
|
|
|
func (p *Admin) SetLogLevel(_ *http.Request, args *client.SetLogLevelArgs, reply *api.EmptyReply) error {
|
|
log.Info("EVM: SetLogLevel called", "logLevel", args.Level)
|
|
|
|
p.vm.runtime.Lock.Lock()
|
|
defer p.vm.runtime.Lock.Unlock()
|
|
|
|
if err := p.vm.logger.SetLogLevel(args.Level); err != nil {
|
|
return fmt.Errorf("failed to parse log level: %w ", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (p *Admin) GetVMConfig(_ *http.Request, _ *struct{}, reply *client.ConfigReply) error {
|
|
reply.Config = &p.vm.config
|
|
return nil
|
|
}
|