-
Notifications
You must be signed in to change notification settings - Fork 5
/
integration_test.go
130 lines (112 loc) · 3.75 KB
/
integration_test.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"testing"
"github.com/tideways/toolkit/xhprof"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestParseWPIndexXhprof(t *testing.T) {
f := xhprof.NewFile("data/wp-index.xhprof", "xhprof")
m, err := f.GetPairCallMap()
require.Nil(t, err)
require.IsType(t, m, new(xhprof.PairCallMap))
require.NotEmpty(t, m.M)
assert.Equal(t, m.M["main()"].WallTime, float32(60572))
assert.Equal(t, m.M["main()"].Count, 1)
assert.Equal(t, m.M["main()"].CpuTime, float32(54683))
assert.Equal(t, m.M["main()"].Memory, float32(2738112))
assert.Equal(t, m.M["main()"].PeakMemory, float32(2596544))
assert.Equal(t, m.M["wp_set_current_user==>setup_userdata"].WallTime, float32(74))
assert.Equal(t, m.M["wp_set_current_user==>setup_userdata"].Count, 1)
assert.Equal(t, m.M["wp_set_current_user==>setup_userdata"].CpuTime, float32(74))
assert.Equal(t, m.M["wp_set_current_user==>setup_userdata"].Memory, float32(4408))
assert.Equal(t, m.M["wp_set_current_user==>setup_userdata"].PeakMemory, float32(328))
p := m.Flatten()
require.IsType(t, p, new(xhprof.Profile))
require.NotEmpty(t, p.Calls)
assert.Equal(t, p.GetMain().WallTime, float32(60572))
c := p.GetCall("is_search")
require.IsType(t, c, new(xhprof.Call))
assert.Equal(t, c.Count, 5)
assert.Equal(t, c.WallTime, float32(5))
assert.Equal(t, c.ExclusiveWallTime, float32(4))
assert.Equal(t, c.CpuTime, float32(5))
assert.Equal(t, c.ExclusiveCpuTime, float32(3))
assert.Equal(t, c.IoTime, float32(1))
assert.Equal(t, c.ExclusiveIoTime, float32(1))
assert.Equal(t, c.Memory, float32(672))
assert.Equal(t, c.ExclusiveMemory, float32(560))
c = p.GetCall("vsprintf")
require.IsType(t, c, new(xhprof.Call))
assert.Equal(t, c.Count, 14)
assert.Equal(t, c.WallTime, float32(18))
assert.Equal(t, c.ExclusiveWallTime, float32(18))
assert.Equal(t, c.CpuTime, float32(17))
assert.Equal(t, c.ExclusiveCpuTime, float32(17))
assert.Equal(t, c.IoTime, float32(2))
assert.Equal(t, c.ExclusiveIoTime, float32(2))
assert.Equal(t, c.Memory, float32(4704))
assert.Equal(t, c.ExclusiveMemory, float32(4704))
}
func TestParseWPIndexCallgrind(t *testing.T) {
expected := xhprof.Profile{
Calls: []*xhprof.Call{
&xhprof.Call{
Name: "main()",
Count: 1,
WallTime: 305039,
ExclusiveWallTime: 54,
IoTime: 305039,
ExclusiveIoTime: 54,
},
&xhprof.Call{
Name: "require::/var/www/wordpress/wp-blog-header.php",
Count: 1,
WallTime: 304981,
ExclusiveWallTime: 86,
IoTime: 304981,
ExclusiveIoTime: 86,
},
},
}
f := xhprof.NewFile("data/cachegrind.out", "callgrind")
profile, err := f.GetProfile()
require.Nil(t, err)
require.NotNil(t, profile)
require.NotNil(t, profile.Main)
assert.EqualValues(t, expected.Calls[0], profile.Main)
for _, c := range profile.Calls {
if c.Name == expected.Calls[1].Name {
assert.EqualValues(t, expected.Calls[1], c)
}
}
}
func TestComputeNearestFamilyWPIndexXhprof(t *testing.T) {
expected := &xhprof.NearestFamily{
Children: &xhprof.PairCallMap{
M: map[string]*xhprof.PairCall{},
},
Parents: &xhprof.PairCallMap{
M: map[string]*xhprof.PairCall{
"wpdb::prepare": &xhprof.PairCall{
WallTime: float32(17),
Count: 11,
},
"get_custom_header": &xhprof.PairCall{
WallTime: float32(1),
Count: 3,
},
},
},
ChildrenCount: 0,
ParentsCount: 14,
}
f := xhprof.NewFile("data/wp-index.xhprof", "xhprof")
m, err := f.GetPairCallMap()
require.Nil(t, err)
require.IsType(t, m, new(xhprof.PairCallMap))
require.NotEmpty(t, m.M)
family := m.ComputeNearestFamily("vsprintf")
require.IsType(t, family, new(xhprof.NearestFamily))
assert.EqualValues(t, expected, family)
}