/
profile.go
76 lines (65 loc) · 2.84 KB
/
profile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package testsetups
//revive:disable:dot-imports
import (
"time"
. "github.com/onsi/gomega"
"golang.org/x/sync/errgroup"
"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
reportModel "github.com/smartcontractkit/chainlink-testing-framework/testreporters"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/testreporters"
)
// ChainlinkProfileTest runs a piece of code on Chainlink nodes with PPROF enabled, then downloads the PPROF results
type ChainlinkProfileTest struct {
Inputs ChainlinkProfileTestInputs
TestReporter testreporters.ChainlinkProfileTestReporter
env *environment.Environment
c blockchain.EVMClient
}
// ChainlinkProfileTestInputs are the inputs necessary to run a profiling tests
type ChainlinkProfileTestInputs struct {
ProfileFunction func(*client.ChainlinkClient)
ProfileDuration time.Duration
ChainlinkNodes []*client.ChainlinkK8sClient
}
// NewChainlinkProfileTest prepares a new keeper Chainlink profiling test to be run
func NewChainlinkProfileTest(inputs ChainlinkProfileTestInputs) *ChainlinkProfileTest {
return &ChainlinkProfileTest{
Inputs: inputs,
}
}
// Setup prepares contracts for the test
func (c *ChainlinkProfileTest) Setup(env *environment.Environment) {
c.ensureInputValues()
c.env = env
}
// Run runs the profiling test
func (c *ChainlinkProfileTest) Run() {
profileGroup := new(errgroup.Group)
for ni, cl := range c.Inputs.ChainlinkNodes {
chainlinkNode := cl
nodeIndex := ni
profileGroup.Go(func() error {
profileResults, err := chainlinkNode.Profile(c.Inputs.ProfileDuration, c.Inputs.ProfileFunction)
profileResults.NodeIndex = nodeIndex
if err != nil {
return err
}
c.TestReporter.Results = append(c.TestReporter.Results, profileResults)
return nil
})
}
Expect(profileGroup.Wait()).ShouldNot(HaveOccurred(), "Error while gathering chainlink Profile tests")
}
// Networks returns the networks that the test is running on
func (c *ChainlinkProfileTest) TearDownVals() (*environment.Environment, []*client.ChainlinkK8sClient, reportModel.TestReporter, blockchain.EVMClient) {
return c.env, c.Inputs.ChainlinkNodes, &c.TestReporter, c.c
}
// ensureValues ensures that all values needed to run the test are present
func (c *ChainlinkProfileTest) ensureInputValues() {
Expect(c.Inputs.ProfileFunction).ShouldNot(BeNil(), "Forgot to provide a function to profile")
Expect(c.Inputs.ProfileDuration.Seconds()).Should(BeNumerically(">=", 1), "Time to profile should be at least 1 second")
Expect(c.Inputs.ChainlinkNodes).ShouldNot(BeNil(), "Chainlink nodes you want to profile should be provided")
Expect(len(c.Inputs.ChainlinkNodes)).Should(BeNumerically(">", 0), "No Chainlink nodes provided to profile")
}