Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics for counter and time spent on a suave precompile #41

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions core/vm/suave.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package vm

import (
"fmt"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/suave/artifacts"
suave "github.com/ethereum/go-ethereum/suave/core"
)

Expand Down Expand Up @@ -51,6 +54,16 @@ func (p *SuavePrecompiledContractWrapper) Run(input []byte) ([]byte, error) {
},
}

if metrics.EnabledExpensive {
precompileName := artifacts.PrecompileAddressToName(p.addr)
metrics.GetOrRegisterMeter("suave/runtime/"+precompileName, nil).Mark(1)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feel free to propose another naming for the metric.


now := time.Now()
defer func() {
metrics.GetOrRegisterTimer("suave/runtime/"+precompileName+"/duration", nil).Update(time.Since(now))
}()
}

switch p.addr {
case isConfidentialAddress:
return (&isConfidentialPrecompile{}).RunConfidential(p.backend, input)
Expand Down
55 changes: 46 additions & 9 deletions suave/artifacts/addresses.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion suave/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,22 @@ import (
"github.com/ethereum/go-ethereum/common"
)

// List of suave precompile addresses
var ( {{range .Functions}}{{.Name}}Addr = common.HexToAddress("{{.Address}}")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same thing is done in #40. Once both things are merged I will consolidate this in a single place.

{{end}}
)

var SuaveMethods = map[string]common.Address{
{{range .Functions}}"{{.Name}}": common.HexToAddress("{{.Address}}"),
{{range .Functions}}"{{.Name}}": {{.Name}}Addr,
{{end}}}

func PrecompileAddressToName(addr common.Address) string {
switch addr { {{range .Functions}}
case {{.Name}}Addr:
return "{{.Name}}"{{end}}
}
return ""
}
`

var suaveLibTemplate = `// SPDX-License-Identifier: UNLICENSED
Expand Down
Loading