/
gperftools.go
65 lines (51 loc) · 1.56 KB
/
gperftools.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
package suites
import (
"net/http"
"strings"
"time"
"github.com/stackrox/collector/integration-tests/pkg/common"
)
type GperftoolsTestSuite struct {
IntegrationTestSuiteBase
}
func (s *GperftoolsTestSuite) SetupSuite() {
if ok, _ := common.ArchSupported("x86_64"); !ok {
return
}
s.StartCollector(false, nil)
}
func (s *GperftoolsTestSuite) TearDownSuite() {
if ok, _ := common.ArchSupported("x86_64"); !ok {
return
}
s.StopCollector()
}
// Verify Gperftools API:
// * turn heap profiling on
// * turn heap profiling off
// * fetch the profile
//
// NOTE: The test will only be performed on supported architectures (only
// x86_64 at the moment).
func (s *GperftoolsTestSuite) TestFetchHeapProfile() {
if ok, arch := common.ArchSupported("x86_64"); !ok {
s.T().Skip("[WARNING]: skip GperftoolsTestSuite on ", arch)
}
var (
response *http.Response
err error
)
heap_api_url := "http://localhost:8080/profile/heap"
data_type := "application/x-www-form-urlencoded"
response, err = http.Post(heap_api_url, data_type, strings.NewReader("on"))
s.Require().NoError(err)
s.Assert().Equal(response.StatusCode, 200, "Failed to start heap profiling")
// Wait a bit to collect something in the heap profile
time.Sleep(1 * time.Second)
response, err = http.Post(heap_api_url, data_type, strings.NewReader("off"))
s.Require().NoError(err)
s.Assert().Equal(response.StatusCode, 200, "Failed to stop heap profiling")
response, err = http.Get(heap_api_url)
s.Require().NoError(err)
s.Assert().Equal(response.StatusCode, 200, "Failed to fetch heap profile")
}