| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package heapprofiler |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
import ( |
| 10 |
"context" |
| 11 |
|
| 12 |
"github.com/chromedp/cdproto/cdp" |
| 13 |
"github.com/chromedp/cdproto/runtime" |
| 14 |
) |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
type AddInspectedHeapObjectParams struct { |
| 19 |
HeapObjectID HeapSnapshotObjectID `json:"heapObjectId"` |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
func AddInspectedHeapObject(heapObjectID HeapSnapshotObjectID) *AddInspectedHeapObjectParams { |
| 31 |
return &AddInspectedHeapObjectParams{ |
| 32 |
HeapObjectID: heapObjectID, |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
func (p *AddInspectedHeapObjectParams) Do(ctx context.Context) (err error) { |
| 38 |
return cdp.Execute(ctx, CommandAddInspectedHeapObject, p, nil) |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
type CollectGarbageParams struct{} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
func CollectGarbage() *CollectGarbageParams { |
| 48 |
return &CollectGarbageParams{} |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
func (p *CollectGarbageParams) Do(ctx context.Context) (err error) { |
| 53 |
return cdp.Execute(ctx, CommandCollectGarbage, nil, nil) |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
type DisableParams struct{} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
func Disable() *DisableParams { |
| 63 |
return &DisableParams{} |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
func (p *DisableParams) Do(ctx context.Context) (err error) { |
| 68 |
return cdp.Execute(ctx, CommandDisable, nil, nil) |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
type EnableParams struct{} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
func Enable() *EnableParams { |
| 78 |
return &EnableParams{} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
func (p *EnableParams) Do(ctx context.Context) (err error) { |
| 83 |
return cdp.Execute(ctx, CommandEnable, nil, nil) |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
type GetHeapObjectIDParams struct { |
| 88 |
ObjectID runtime.RemoteObjectID `json:"objectId"` |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
func GetHeapObjectID(objectID runtime.RemoteObjectID) *GetHeapObjectIDParams { |
| 99 |
return &GetHeapObjectIDParams{ |
| 100 |
ObjectID: objectID, |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
type GetHeapObjectIDReturns struct { |
| 106 |
HeapSnapshotObjectID HeapSnapshotObjectID `json:"heapSnapshotObjectId,omitempty,omitzero"` |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
func (p *GetHeapObjectIDParams) Do(ctx context.Context) (heapSnapshotObjectID HeapSnapshotObjectID, err error) { |
| 115 |
|
| 116 |
var res GetHeapObjectIDReturns |
| 117 |
err = cdp.Execute(ctx, CommandGetHeapObjectID, p, &res) |
| 118 |
if err != nil { |
| 119 |
return "", err |
| 120 |
} |
| 121 |
|
| 122 |
return res.HeapSnapshotObjectID, nil |
| 123 |
} |
| 124 |
|
| 125 |
|
| 126 |
type GetObjectByHeapObjectIDParams struct { |
| 127 |
ObjectID HeapSnapshotObjectID `json:"objectId"` |
| 128 |
ObjectGroup string `json:"objectGroup,omitempty,omitzero"` |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
func GetObjectByHeapObjectID(objectID HeapSnapshotObjectID) *GetObjectByHeapObjectIDParams { |
| 139 |
return &GetObjectByHeapObjectIDParams{ |
| 140 |
ObjectID: objectID, |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
func (p GetObjectByHeapObjectIDParams) WithObjectGroup(objectGroup string) *GetObjectByHeapObjectIDParams { |
| 147 |
p.ObjectGroup = objectGroup |
| 148 |
return &p |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
type GetObjectByHeapObjectIDReturns struct { |
| 153 |
Result *runtime.RemoteObject `json:"result,omitempty,omitzero"` |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
func (p *GetObjectByHeapObjectIDParams) Do(ctx context.Context) (result *runtime.RemoteObject, err error) { |
| 162 |
|
| 163 |
var res GetObjectByHeapObjectIDReturns |
| 164 |
err = cdp.Execute(ctx, CommandGetObjectByHeapObjectID, p, &res) |
| 165 |
if err != nil { |
| 166 |
return nil, err |
| 167 |
} |
| 168 |
|
| 169 |
return res.Result, nil |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
type GetSamplingProfileParams struct{} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
func GetSamplingProfile() *GetSamplingProfileParams { |
| 179 |
return &GetSamplingProfileParams{} |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
type GetSamplingProfileReturns struct { |
| 184 |
Profile *SamplingHeapProfile `json:"profile,omitempty,omitzero"` |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
func (p *GetSamplingProfileParams) Do(ctx context.Context) (profile *SamplingHeapProfile, err error) { |
| 193 |
|
| 194 |
var res GetSamplingProfileReturns |
| 195 |
err = cdp.Execute(ctx, CommandGetSamplingProfile, nil, &res) |
| 196 |
if err != nil { |
| 197 |
return nil, err |
| 198 |
} |
| 199 |
|
| 200 |
return res.Profile, nil |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
type StartSamplingParams struct { |
| 205 |
SamplingInterval float64 `json:"samplingInterval,omitempty,omitzero"` |
| 206 |
IncludeObjectsCollectedByMajorGC bool `json:"includeObjectsCollectedByMajorGC"` |
| 207 |
IncludeObjectsCollectedByMinorGC bool `json:"includeObjectsCollectedByMinorGC"` |
| 208 |
} |
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
func StartSampling() *StartSamplingParams { |
| 216 |
return &StartSamplingParams{ |
| 217 |
IncludeObjectsCollectedByMajorGC: false, |
| 218 |
IncludeObjectsCollectedByMinorGC: false, |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
func (p StartSamplingParams) WithSamplingInterval(samplingInterval float64) *StartSamplingParams { |
| 225 |
p.SamplingInterval = samplingInterval |
| 226 |
return &p |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
func (p StartSamplingParams) WithIncludeObjectsCollectedByMajorGC(includeObjectsCollectedByMajorGC bool) *StartSamplingParams { |
| 237 |
p.IncludeObjectsCollectedByMajorGC = includeObjectsCollectedByMajorGC |
| 238 |
return &p |
| 239 |
} |
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
func (p StartSamplingParams) WithIncludeObjectsCollectedByMinorGC(includeObjectsCollectedByMinorGC bool) *StartSamplingParams { |
| 249 |
p.IncludeObjectsCollectedByMinorGC = includeObjectsCollectedByMinorGC |
| 250 |
return &p |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
func (p *StartSamplingParams) Do(ctx context.Context) (err error) { |
| 255 |
return cdp.Execute(ctx, CommandStartSampling, p, nil) |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
type StartTrackingHeapObjectsParams struct { |
| 260 |
TrackAllocations bool `json:"trackAllocations"` |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
func StartTrackingHeapObjects() *StartTrackingHeapObjectsParams { |
| 269 |
return &StartTrackingHeapObjectsParams{ |
| 270 |
TrackAllocations: false, |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
func (p StartTrackingHeapObjectsParams) WithTrackAllocations(trackAllocations bool) *StartTrackingHeapObjectsParams { |
| 276 |
p.TrackAllocations = trackAllocations |
| 277 |
return &p |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
func (p *StartTrackingHeapObjectsParams) Do(ctx context.Context) (err error) { |
| 282 |
return cdp.Execute(ctx, CommandStartTrackingHeapObjects, p, nil) |
| 283 |
} |
| 284 |
|
| 285 |
|
| 286 |
type StopSamplingParams struct{} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
func StopSampling() *StopSamplingParams { |
| 292 |
return &StopSamplingParams{} |
| 293 |
} |
| 294 |
|
| 295 |
|
| 296 |
type StopSamplingReturns struct { |
| 297 |
Profile *SamplingHeapProfile `json:"profile,omitempty,omitzero"` |
| 298 |
} |
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
func (p *StopSamplingParams) Do(ctx context.Context) (profile *SamplingHeapProfile, err error) { |
| 306 |
|
| 307 |
var res StopSamplingReturns |
| 308 |
err = cdp.Execute(ctx, CommandStopSampling, nil, &res) |
| 309 |
if err != nil { |
| 310 |
return nil, err |
| 311 |
} |
| 312 |
|
| 313 |
return res.Profile, nil |
| 314 |
} |
| 315 |
|
| 316 |
|
| 317 |
type StopTrackingHeapObjectsParams struct { |
| 318 |
ReportProgress bool `json:"reportProgress"` |
| 319 |
CaptureNumericValue bool `json:"captureNumericValue"` |
| 320 |
ExposeInternals bool `json:"exposeInternals"` |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
func StopTrackingHeapObjects() *StopTrackingHeapObjectsParams { |
| 329 |
return &StopTrackingHeapObjectsParams{ |
| 330 |
ReportProgress: false, |
| 331 |
CaptureNumericValue: false, |
| 332 |
ExposeInternals: false, |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
func (p StopTrackingHeapObjectsParams) WithReportProgress(reportProgress bool) *StopTrackingHeapObjectsParams { |
| 339 |
p.ReportProgress = reportProgress |
| 340 |
return &p |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
func (p StopTrackingHeapObjectsParams) WithCaptureNumericValue(captureNumericValue bool) *StopTrackingHeapObjectsParams { |
| 346 |
p.CaptureNumericValue = captureNumericValue |
| 347 |
return &p |
| 348 |
} |
| 349 |
|
| 350 |
|
| 351 |
func (p StopTrackingHeapObjectsParams) WithExposeInternals(exposeInternals bool) *StopTrackingHeapObjectsParams { |
| 352 |
p.ExposeInternals = exposeInternals |
| 353 |
return &p |
| 354 |
} |
| 355 |
|
| 356 |
|
| 357 |
func (p *StopTrackingHeapObjectsParams) Do(ctx context.Context) (err error) { |
| 358 |
return cdp.Execute(ctx, CommandStopTrackingHeapObjects, p, nil) |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
type TakeHeapSnapshotParams struct { |
| 363 |
ReportProgress bool `json:"reportProgress"` |
| 364 |
CaptureNumericValue bool `json:"captureNumericValue"` |
| 365 |
ExposeInternals bool `json:"exposeInternals"` |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
func TakeHeapSnapshot() *TakeHeapSnapshotParams { |
| 374 |
return &TakeHeapSnapshotParams{ |
| 375 |
ReportProgress: false, |
| 376 |
CaptureNumericValue: false, |
| 377 |
ExposeInternals: false, |
| 378 |
} |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
func (p TakeHeapSnapshotParams) WithReportProgress(reportProgress bool) *TakeHeapSnapshotParams { |
| 384 |
p.ReportProgress = reportProgress |
| 385 |
return &p |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
func (p TakeHeapSnapshotParams) WithCaptureNumericValue(captureNumericValue bool) *TakeHeapSnapshotParams { |
| 391 |
p.CaptureNumericValue = captureNumericValue |
| 392 |
return &p |
| 393 |
} |
| 394 |
|
| 395 |
|
| 396 |
func (p TakeHeapSnapshotParams) WithExposeInternals(exposeInternals bool) *TakeHeapSnapshotParams { |
| 397 |
p.ExposeInternals = exposeInternals |
| 398 |
return &p |
| 399 |
} |
| 400 |
|
| 401 |
|
| 402 |
func (p *TakeHeapSnapshotParams) Do(ctx context.Context) (err error) { |
| 403 |
return cdp.Execute(ctx, CommandTakeHeapSnapshot, p, nil) |
| 404 |
} |
| 405 |
|
| 406 |
|
| 407 |
const ( |
| 408 |
CommandAddInspectedHeapObject = "HeapProfiler.addInspectedHeapObject" |
| 409 |
CommandCollectGarbage = "HeapProfiler.collectGarbage" |
| 410 |
CommandDisable = "HeapProfiler.disable" |
| 411 |
CommandEnable = "HeapProfiler.enable" |
| 412 |
CommandGetHeapObjectID = "HeapProfiler.getHeapObjectId" |
| 413 |
CommandGetObjectByHeapObjectID = "HeapProfiler.getObjectByHeapObjectId" |
| 414 |
CommandGetSamplingProfile = "HeapProfiler.getSamplingProfile" |
| 415 |
CommandStartSampling = "HeapProfiler.startSampling" |
| 416 |
CommandStartTrackingHeapObjects = "HeapProfiler.startTrackingHeapObjects" |
| 417 |
CommandStopSampling = "HeapProfiler.stopSampling" |
| 418 |
CommandStopTrackingHeapObjects = "HeapProfiler.stopTrackingHeapObjects" |
| 419 |
CommandTakeHeapSnapshot = "HeapProfiler.takeHeapSnapshot" |
| 420 |
) |