forked from chromedp/cdproto
/
memory.go
284 lines (240 loc) · 9.86 KB
/
memory.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
// Package memory provides the Chrome DevTools Protocol
// commands, types, and events for the Memory domain.
//
// Generated by the cdproto-gen command.
package memory
// Code generated by cdproto-gen. DO NOT EDIT.
import (
"context"
"github.com/c12o16h1/cdproto/cdp"
)
// GetDOMCountersParams [no description].
type GetDOMCountersParams struct{}
// GetDOMCounters [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getDOMCounters
func GetDOMCounters() *GetDOMCountersParams {
return &GetDOMCountersParams{}
}
// GetDOMCountersReturns return values.
type GetDOMCountersReturns struct {
Documents int64 `json:"documents,omitempty"`
Nodes int64 `json:"nodes,omitempty"`
JsEventListeners int64 `json:"jsEventListeners,omitempty"`
}
// Do executes Memory.getDOMCounters against the provided context.
//
// returns:
// documents
// nodes
// jsEventListeners
func (p *GetDOMCountersParams) Do(ctx context.Context) (documents int64, nodes int64, jsEventListeners int64, err error) {
// execute
var res GetDOMCountersReturns
err = cdp.Execute(ctx, CommandGetDOMCounters, nil, &res)
if err != nil {
return 0, 0, 0, err
}
return res.Documents, res.Nodes, res.JsEventListeners, nil
}
// PrepareForLeakDetectionParams [no description].
type PrepareForLeakDetectionParams struct{}
// PrepareForLeakDetection [no description].
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-prepareForLeakDetection
func PrepareForLeakDetection() *PrepareForLeakDetectionParams {
return &PrepareForLeakDetectionParams{}
}
// Do executes Memory.prepareForLeakDetection against the provided context.
func (p *PrepareForLeakDetectionParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandPrepareForLeakDetection, nil, nil)
}
// ForciblyPurgeJavaScriptMemoryParams simulate OomIntervention by purging V8
// memory.
type ForciblyPurgeJavaScriptMemoryParams struct{}
// ForciblyPurgeJavaScriptMemory simulate OomIntervention by purging V8
// memory.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-forciblyPurgeJavaScriptMemory
func ForciblyPurgeJavaScriptMemory() *ForciblyPurgeJavaScriptMemoryParams {
return &ForciblyPurgeJavaScriptMemoryParams{}
}
// Do executes Memory.forciblyPurgeJavaScriptMemory against the provided context.
func (p *ForciblyPurgeJavaScriptMemoryParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandForciblyPurgeJavaScriptMemory, nil, nil)
}
// SetPressureNotificationsSuppressedParams enable/disable suppressing memory
// pressure notifications in all processes.
type SetPressureNotificationsSuppressedParams struct {
Suppressed bool `json:"suppressed"` // If true, memory pressure notifications will be suppressed.
}
// SetPressureNotificationsSuppressed enable/disable suppressing memory
// pressure notifications in all processes.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-setPressureNotificationsSuppressed
//
// parameters:
// suppressed - If true, memory pressure notifications will be suppressed.
func SetPressureNotificationsSuppressed(suppressed bool) *SetPressureNotificationsSuppressedParams {
return &SetPressureNotificationsSuppressedParams{
Suppressed: suppressed,
}
}
// Do executes Memory.setPressureNotificationsSuppressed against the provided context.
func (p *SetPressureNotificationsSuppressedParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandSetPressureNotificationsSuppressed, p, nil)
}
// SimulatePressureNotificationParams simulate a memory pressure notification
// in all processes.
type SimulatePressureNotificationParams struct {
Level PressureLevel `json:"level"` // Memory pressure level of the notification.
}
// SimulatePressureNotification simulate a memory pressure notification in
// all processes.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-simulatePressureNotification
//
// parameters:
// level - Memory pressure level of the notification.
func SimulatePressureNotification(level PressureLevel) *SimulatePressureNotificationParams {
return &SimulatePressureNotificationParams{
Level: level,
}
}
// Do executes Memory.simulatePressureNotification against the provided context.
func (p *SimulatePressureNotificationParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandSimulatePressureNotification, p, nil)
}
// StartSamplingParams start collecting native memory profile.
type StartSamplingParams struct {
SamplingInterval int64 `json:"samplingInterval,omitempty"` // Average number of bytes between samples.
SuppressRandomness bool `json:"suppressRandomness,omitempty"` // Do not randomize intervals between samples.
}
// StartSampling start collecting native memory profile.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-startSampling
//
// parameters:
func StartSampling() *StartSamplingParams {
return &StartSamplingParams{}
}
// WithSamplingInterval average number of bytes between samples.
func (p StartSamplingParams) WithSamplingInterval(samplingInterval int64) *StartSamplingParams {
p.SamplingInterval = samplingInterval
return &p
}
// WithSuppressRandomness do not randomize intervals between samples.
func (p StartSamplingParams) WithSuppressRandomness(suppressRandomness bool) *StartSamplingParams {
p.SuppressRandomness = suppressRandomness
return &p
}
// Do executes Memory.startSampling against the provided context.
func (p *StartSamplingParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandStartSampling, p, nil)
}
// StopSamplingParams stop collecting native memory profile.
type StopSamplingParams struct{}
// StopSampling stop collecting native memory profile.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-stopSampling
func StopSampling() *StopSamplingParams {
return &StopSamplingParams{}
}
// Do executes Memory.stopSampling against the provided context.
func (p *StopSamplingParams) Do(ctx context.Context) (err error) {
return cdp.Execute(ctx, CommandStopSampling, nil, nil)
}
// GetAllTimeSamplingProfileParams retrieve native memory allocations profile
// collected since renderer process startup.
type GetAllTimeSamplingProfileParams struct{}
// GetAllTimeSamplingProfile retrieve native memory allocations profile
// collected since renderer process startup.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getAllTimeSamplingProfile
func GetAllTimeSamplingProfile() *GetAllTimeSamplingProfileParams {
return &GetAllTimeSamplingProfileParams{}
}
// GetAllTimeSamplingProfileReturns return values.
type GetAllTimeSamplingProfileReturns struct {
Profile *SamplingProfile `json:"profile,omitempty"`
}
// Do executes Memory.getAllTimeSamplingProfile against the provided context.
//
// returns:
// profile
func (p *GetAllTimeSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
// execute
var res GetAllTimeSamplingProfileReturns
err = cdp.Execute(ctx, CommandGetAllTimeSamplingProfile, nil, &res)
if err != nil {
return nil, err
}
return res.Profile, nil
}
// GetBrowserSamplingProfileParams retrieve native memory allocations profile
// collected since browser process startup.
type GetBrowserSamplingProfileParams struct{}
// GetBrowserSamplingProfile retrieve native memory allocations profile
// collected since browser process startup.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getBrowserSamplingProfile
func GetBrowserSamplingProfile() *GetBrowserSamplingProfileParams {
return &GetBrowserSamplingProfileParams{}
}
// GetBrowserSamplingProfileReturns return values.
type GetBrowserSamplingProfileReturns struct {
Profile *SamplingProfile `json:"profile,omitempty"`
}
// Do executes Memory.getBrowserSamplingProfile against the provided context.
//
// returns:
// profile
func (p *GetBrowserSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
// execute
var res GetBrowserSamplingProfileReturns
err = cdp.Execute(ctx, CommandGetBrowserSamplingProfile, nil, &res)
if err != nil {
return nil, err
}
return res.Profile, nil
}
// GetSamplingProfileParams retrieve native memory allocations profile
// collected since last startSampling call.
type GetSamplingProfileParams struct{}
// GetSamplingProfile retrieve native memory allocations profile collected
// since last startSampling call.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getSamplingProfile
func GetSamplingProfile() *GetSamplingProfileParams {
return &GetSamplingProfileParams{}
}
// GetSamplingProfileReturns return values.
type GetSamplingProfileReturns struct {
Profile *SamplingProfile `json:"profile,omitempty"`
}
// Do executes Memory.getSamplingProfile against the provided context.
//
// returns:
// profile
func (p *GetSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
// execute
var res GetSamplingProfileReturns
err = cdp.Execute(ctx, CommandGetSamplingProfile, nil, &res)
if err != nil {
return nil, err
}
return res.Profile, nil
}
// Command names.
const (
CommandGetDOMCounters = "Memory.getDOMCounters"
CommandPrepareForLeakDetection = "Memory.prepareForLeakDetection"
CommandForciblyPurgeJavaScriptMemory = "Memory.forciblyPurgeJavaScriptMemory"
CommandSetPressureNotificationsSuppressed = "Memory.setPressureNotificationsSuppressed"
CommandSimulatePressureNotification = "Memory.simulatePressureNotification"
CommandStartSampling = "Memory.startSampling"
CommandStopSampling = "Memory.stopSampling"
CommandGetAllTimeSamplingProfile = "Memory.getAllTimeSamplingProfile"
CommandGetBrowserSamplingProfile = "Memory.getBrowserSamplingProfile"
CommandGetSamplingProfile = "Memory.getSamplingProfile"
)