Documentation ¶
Overview ¶
Package profile provides a simple way to generate pprof compatible gnark circuit profile.
Since the gnark frontend compiler is not thread safe and operates in a single go-routine, this package is also NOT thread safe and is meant to be called in the same go-routine.
Example ¶
//go:build !windows package main import ( "fmt" "github.com/BeratOz01/gnark/frontend" "github.com/BeratOz01/gnark/frontend/cs/r1cs" "github.com/BeratOz01/gnark/profile" "github.com/consensys/gnark-crypto/ecc" ) type Circuit struct { A frontend.Variable } func (circuit *Circuit) Define(api frontend.API) error { api.AssertIsEqual(api.Mul(circuit.A, circuit.A), circuit.A) return nil } func main() { // default options generate gnark.pprof in current dir // use pprof as usual (go tool pprof -http=:8080 gnark.pprof) to read the profile file // overlapping profiles are allowed (define profiles inside Define or subfunction to profile // part of the circuit only) p := profile.Start() _, _ = frontend.Compile(ecc.BN254.ScalarField(), r1cs.NewBuilder, &Circuit{}) p.Stop() fmt.Println(p.NbConstraints()) fmt.Println(p.Top()) }
Output: 2 Showing nodes accounting for 2, 100% of 2 total flat flat% sum% cum cum% 1 50.00% 50.00% 2 100% profile_test.(*Circuit).Define profile/profile_test.go:19 1 50.00% 100% 1 50.00% r1cs.(*builder).AssertIsEqual frontend/cs/r1cs/api_assertions.go:37
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RecordConstraint ¶
func RecordConstraint()
RecordConstraint add a sample (with count == 1) to all the active profiling sessions.
Types ¶
type Option ¶
type Option func(*Profile)
Option defines configuration Options for Profile.
func WithNoOutput ¶
func WithNoOutput() Option
WithNoOutput indicates that the profile is not going to be written to disk.
This is equivalent to WithPath("")
type Profile ¶
type Profile struct {
// contains filtered or unexported fields
}
Profile represents an active constraint system profiling session.
func Start ¶
Start creates a new active profiling session. When Stop() is called, this session is removed from active profiling sessions and may be serialized to disk as a pprof compatible file (see ProfilePath option).
All calls to profile.Start() and Stop() are meant to be executed in the same go routine (frontend.Compile).
It is allowed to create multiple overlapping profiling sessions in one circuit.
func (*Profile) NbConstraints ¶
NbConstraints return number of collected samples (constraints) by the profile session
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
graph
Package graph collects a set of samples into a directed graph.
|
Package graph collects a set of samples into a directed graph. |
measurement
Package measurement export utility functions to manipulate/format performance profile sample values.
|
Package measurement export utility functions to manipulate/format performance profile sample values. |
report
Package report summarizes a performance profile into a human-readable report.
|
Package report summarizes a performance profile into a human-readable report. |