Skip to content

Commit

Permalink
adds gnark/profile that outputs pprof compatible circuit profiling …
Browse files Browse the repository at this point in the history
…data (Consensys#352)

* feat: added profile/ to output pprof style constraint profiler

* feat: gnark/profile allows multiple overlapping profiling sessions

* feat: added profile.Top()

* feat: added profile.NbConstraints()

* docs: added package level profile example

* style: code cleaning

* fix: fix CI trim path for test purposes

* fix: fix previous commit

* style: coherent options in gnark/profile
  • Loading branch information
gbotrel authored Aug 3, 2022
1 parent 34e16a3 commit e8ae5d6
Show file tree
Hide file tree
Showing 11 changed files with 3,429 additions and 1 deletion.
2 changes: 2 additions & 0 deletions frontend/cs/r1cs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
tinyfieldr1cs "github.com/consensys/gnark/internal/tinyfield/cs"
"github.com/consensys/gnark/internal/utils"
"github.com/consensys/gnark/logger"
"github.com/consensys/gnark/profile"
)

// NewBuilder returns a new R1CS compiler
Expand Down Expand Up @@ -174,6 +175,7 @@ func newR1C(_l, _r, _o frontend.Variable) compiled.R1C {
}

func (system *r1cs) addConstraint(r1c compiled.R1C, debugID ...int) {
profile.RecordConstraint()
system.Constraints = append(system.Constraints, r1c)
if len(debugID) > 0 {
system.MDebug[len(system.Constraints)-1] = debugID[0]
Expand Down
3 changes: 2 additions & 1 deletion frontend/cs/scs/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
tinyfieldr1cs "github.com/consensys/gnark/internal/tinyfield/cs"
"github.com/consensys/gnark/internal/utils"
"github.com/consensys/gnark/logger"
"github.com/consensys/gnark/profile"
)

func NewBuilder(field *big.Int, config frontend.CompileConfig) (frontend.Builder, error) {
Expand Down Expand Up @@ -87,7 +88,7 @@ func newBuilder(field *big.Int, config frontend.CompileConfig) *scs {
// addPlonkConstraint creates a constraint of the for al+br+clr+k=0
//func (system *SparseR1CS) addPlonkConstraint(l, r, o frontend.Variable, cidl, cidr, cidm1, cidm2, cido, k int, debugID ...int) {
func (system *scs) addPlonkConstraint(l, r, o compiled.Term, cidl, cidr, cidm1, cidm2, cido, k int, debugID ...int) {

profile.RecordConstraint()
if len(debugID) > 0 {
system.MDebug[len(system.Constraints)] = debugID[0]
} else if debug.Debug {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/consensys/gnark-crypto v0.7.1-0.20220603201101-938eff486457
github.com/fxamacker/cbor/v2 v2.2.0
github.com/google/go-cmp v0.5.8
github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1
github.com/leanovate/gopter v0.2.9
github.com/rs/zerolog v1.26.1
github.com/stretchr/testify v1.7.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ github.com/fxamacker/cbor/v2 v2.2.0/go.mod h1:TA1xS00nchWmaBnEIxPSE5oHLuJBAVvqrt
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1 h1:8pyqKJvrJqUYaKS851Ule26pwWvey6IDMiczaBLDKLQ=
github.com/google/pprof v0.0.0-20220729232143-a41b82acbcb1/go.mod h1:gSuNB+gJaOiQKLEZ+q+PK9Mq3SOzhRcw2GsGS/FhYDk=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
Loading

0 comments on commit e8ae5d6

Please sign in to comment.