mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 19:30:44 +00:00
eth/tracers/native: make opcode counter array
This commit is contained in:
parent
e54f7a1f8b
commit
fe5ad101e8
2 changed files with 4 additions and 10 deletions
|
|
@ -195,7 +195,7 @@ func Transition(ctx *cli.Context) error {
|
||||||
// Configure opcode counter
|
// Configure opcode counter
|
||||||
var counter *native.OpcodeCounter
|
var counter *native.OpcodeCounter
|
||||||
if ctx.IsSet(OpcodeCountFlag.Name) && ctx.String(OpcodeCountFlag.Name) != "" {
|
if ctx.IsSet(OpcodeCountFlag.Name) && ctx.String(OpcodeCountFlag.Name) != "" {
|
||||||
counter = native.NewOpcodeCounter()
|
counter = new(native.OpcodeCounter)
|
||||||
if vmConfig.Tracer != nil {
|
if vmConfig.Tracer != nil {
|
||||||
// If we have an existing tracer, multiplex with the opcode tracer
|
// If we have an existing tracer, multiplex with the opcode tracer
|
||||||
tExisting := tracers.Tracer{Hooks: vmConfig.Tracer}
|
tExisting := tracers.Tracer{Hooks: vmConfig.Tracer}
|
||||||
|
|
|
||||||
|
|
@ -23,19 +23,13 @@ import (
|
||||||
|
|
||||||
// OpcodeCounter is a simple tracer that counts how many times each opcode is executed.
|
// OpcodeCounter is a simple tracer that counts how many times each opcode is executed.
|
||||||
type OpcodeCounter struct {
|
type OpcodeCounter struct {
|
||||||
counts map[vm.OpCode]uint64
|
counts [256]uint64
|
||||||
}
|
|
||||||
|
|
||||||
func NewOpcodeCounter() *OpcodeCounter {
|
|
||||||
return &OpcodeCounter{
|
|
||||||
counts: make(map[vm.OpCode]uint64),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *OpcodeCounter) Hooks() *tracing.Hooks {
|
func (c *OpcodeCounter) Hooks() *tracing.Hooks {
|
||||||
return &tracing.Hooks{
|
return &tracing.Hooks{
|
||||||
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
OnOpcode: func(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
|
||||||
c.counts[vm.OpCode(op)]++
|
c.counts[op]++
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +38,7 @@ func (c *OpcodeCounter) Hooks() *tracing.Hooks {
|
||||||
func (c *OpcodeCounter) Results() map[string]uint64 {
|
func (c *OpcodeCounter) Results() map[string]uint64 {
|
||||||
out := make(map[string]uint64, len(c.counts))
|
out := make(map[string]uint64, len(c.counts))
|
||||||
for op, count := range c.counts {
|
for op, count := range c.counts {
|
||||||
out[op.String()] = count
|
out[vm.OpCode(op).String()] = count
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue