heapprofiler.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. // Package heapprofiler provides the Chrome DevTools Protocol
  2. // commands, types, and events for the HeapProfiler domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package heapprofiler
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. "github.com/chromedp/cdproto/runtime"
  11. )
  12. // AddInspectedHeapObjectParams enables console to refer to the node with
  13. // given id via $x (see Command Line API for more details $x functions).
  14. type AddInspectedHeapObjectParams struct {
  15. HeapObjectID HeapSnapshotObjectID `json:"heapObjectId"` // Heap snapshot object id to be accessible by means of $x command line API.
  16. }
  17. // AddInspectedHeapObject enables console to refer to the node with given id
  18. // via $x (see Command Line API for more details $x functions).
  19. //
  20. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-addInspectedHeapObject
  21. //
  22. // parameters:
  23. //
  24. // heapObjectID - Heap snapshot object id to be accessible by means of $x command line API.
  25. func AddInspectedHeapObject(heapObjectID HeapSnapshotObjectID) *AddInspectedHeapObjectParams {
  26. return &AddInspectedHeapObjectParams{
  27. HeapObjectID: heapObjectID,
  28. }
  29. }
  30. // Do executes HeapProfiler.addInspectedHeapObject against the provided context.
  31. func (p *AddInspectedHeapObjectParams) Do(ctx context.Context) (err error) {
  32. return cdp.Execute(ctx, CommandAddInspectedHeapObject, p, nil)
  33. }
  34. // CollectGarbageParams [no description].
  35. type CollectGarbageParams struct{}
  36. // CollectGarbage [no description].
  37. //
  38. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-collectGarbage
  39. func CollectGarbage() *CollectGarbageParams {
  40. return &CollectGarbageParams{}
  41. }
  42. // Do executes HeapProfiler.collectGarbage against the provided context.
  43. func (p *CollectGarbageParams) Do(ctx context.Context) (err error) {
  44. return cdp.Execute(ctx, CommandCollectGarbage, nil, nil)
  45. }
  46. // DisableParams [no description].
  47. type DisableParams struct{}
  48. // Disable [no description].
  49. //
  50. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-disable
  51. func Disable() *DisableParams {
  52. return &DisableParams{}
  53. }
  54. // Do executes HeapProfiler.disable against the provided context.
  55. func (p *DisableParams) Do(ctx context.Context) (err error) {
  56. return cdp.Execute(ctx, CommandDisable, nil, nil)
  57. }
  58. // EnableParams [no description].
  59. type EnableParams struct{}
  60. // Enable [no description].
  61. //
  62. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-enable
  63. func Enable() *EnableParams {
  64. return &EnableParams{}
  65. }
  66. // Do executes HeapProfiler.enable against the provided context.
  67. func (p *EnableParams) Do(ctx context.Context) (err error) {
  68. return cdp.Execute(ctx, CommandEnable, nil, nil)
  69. }
  70. // GetHeapObjectIDParams [no description].
  71. type GetHeapObjectIDParams struct {
  72. ObjectID runtime.RemoteObjectID `json:"objectId"` // Identifier of the object to get heap object id for.
  73. }
  74. // GetHeapObjectID [no description].
  75. //
  76. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-getHeapObjectId
  77. //
  78. // parameters:
  79. //
  80. // objectID - Identifier of the object to get heap object id for.
  81. func GetHeapObjectID(objectID runtime.RemoteObjectID) *GetHeapObjectIDParams {
  82. return &GetHeapObjectIDParams{
  83. ObjectID: objectID,
  84. }
  85. }
  86. // GetHeapObjectIDReturns return values.
  87. type GetHeapObjectIDReturns struct {
  88. HeapSnapshotObjectID HeapSnapshotObjectID `json:"heapSnapshotObjectId,omitempty,omitzero"` // Id of the heap snapshot object corresponding to the passed remote object id.
  89. }
  90. // Do executes HeapProfiler.getHeapObjectId against the provided context.
  91. //
  92. // returns:
  93. //
  94. // heapSnapshotObjectID - Id of the heap snapshot object corresponding to the passed remote object id.
  95. func (p *GetHeapObjectIDParams) Do(ctx context.Context) (heapSnapshotObjectID HeapSnapshotObjectID, err error) {
  96. // execute
  97. var res GetHeapObjectIDReturns
  98. err = cdp.Execute(ctx, CommandGetHeapObjectID, p, &res)
  99. if err != nil {
  100. return "", err
  101. }
  102. return res.HeapSnapshotObjectID, nil
  103. }
  104. // GetObjectByHeapObjectIDParams [no description].
  105. type GetObjectByHeapObjectIDParams struct {
  106. ObjectID HeapSnapshotObjectID `json:"objectId"`
  107. ObjectGroup string `json:"objectGroup,omitempty,omitzero"` // Symbolic group name that can be used to release multiple objects.
  108. }
  109. // GetObjectByHeapObjectID [no description].
  110. //
  111. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-getObjectByHeapObjectId
  112. //
  113. // parameters:
  114. //
  115. // objectID
  116. func GetObjectByHeapObjectID(objectID HeapSnapshotObjectID) *GetObjectByHeapObjectIDParams {
  117. return &GetObjectByHeapObjectIDParams{
  118. ObjectID: objectID,
  119. }
  120. }
  121. // WithObjectGroup symbolic group name that can be used to release multiple
  122. // objects.
  123. func (p GetObjectByHeapObjectIDParams) WithObjectGroup(objectGroup string) *GetObjectByHeapObjectIDParams {
  124. p.ObjectGroup = objectGroup
  125. return &p
  126. }
  127. // GetObjectByHeapObjectIDReturns return values.
  128. type GetObjectByHeapObjectIDReturns struct {
  129. Result *runtime.RemoteObject `json:"result,omitempty,omitzero"` // Evaluation result.
  130. }
  131. // Do executes HeapProfiler.getObjectByHeapObjectId against the provided context.
  132. //
  133. // returns:
  134. //
  135. // result - Evaluation result.
  136. func (p *GetObjectByHeapObjectIDParams) Do(ctx context.Context) (result *runtime.RemoteObject, err error) {
  137. // execute
  138. var res GetObjectByHeapObjectIDReturns
  139. err = cdp.Execute(ctx, CommandGetObjectByHeapObjectID, p, &res)
  140. if err != nil {
  141. return nil, err
  142. }
  143. return res.Result, nil
  144. }
  145. // GetSamplingProfileParams [no description].
  146. type GetSamplingProfileParams struct{}
  147. // GetSamplingProfile [no description].
  148. //
  149. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-getSamplingProfile
  150. func GetSamplingProfile() *GetSamplingProfileParams {
  151. return &GetSamplingProfileParams{}
  152. }
  153. // GetSamplingProfileReturns return values.
  154. type GetSamplingProfileReturns struct {
  155. Profile *SamplingHeapProfile `json:"profile,omitempty,omitzero"` // Return the sampling profile being collected.
  156. }
  157. // Do executes HeapProfiler.getSamplingProfile against the provided context.
  158. //
  159. // returns:
  160. //
  161. // profile - Return the sampling profile being collected.
  162. func (p *GetSamplingProfileParams) Do(ctx context.Context) (profile *SamplingHeapProfile, err error) {
  163. // execute
  164. var res GetSamplingProfileReturns
  165. err = cdp.Execute(ctx, CommandGetSamplingProfile, nil, &res)
  166. if err != nil {
  167. return nil, err
  168. }
  169. return res.Profile, nil
  170. }
  171. // StartSamplingParams [no description].
  172. type StartSamplingParams struct {
  173. SamplingInterval float64 `json:"samplingInterval,omitempty,omitzero"` // Average sample interval in bytes. Poisson distribution is used for the intervals. The default value is 32768 bytes.
  174. IncludeObjectsCollectedByMajorGC bool `json:"includeObjectsCollectedByMajorGC"` // By default, the sampling heap profiler reports only objects which are still alive when the profile is returned via getSamplingProfile or stopSampling, which is useful for determining what functions contribute the most to steady-state memory usage. This flag instructs the sampling heap profiler to also include information about objects discarded by major GC, which will show which functions cause large temporary memory usage or long GC pauses.
  175. IncludeObjectsCollectedByMinorGC bool `json:"includeObjectsCollectedByMinorGC"` // By default, the sampling heap profiler reports only objects which are still alive when the profile is returned via getSamplingProfile or stopSampling, which is useful for determining what functions contribute the most to steady-state memory usage. This flag instructs the sampling heap profiler to also include information about objects discarded by minor GC, which is useful when tuning a latency-sensitive application for minimal GC activity.
  176. }
  177. // StartSampling [no description].
  178. //
  179. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-startSampling
  180. //
  181. // parameters:
  182. func StartSampling() *StartSamplingParams {
  183. return &StartSamplingParams{
  184. IncludeObjectsCollectedByMajorGC: false,
  185. IncludeObjectsCollectedByMinorGC: false,
  186. }
  187. }
  188. // WithSamplingInterval average sample interval in bytes. Poisson
  189. // distribution is used for the intervals. The default value is 32768 bytes.
  190. func (p StartSamplingParams) WithSamplingInterval(samplingInterval float64) *StartSamplingParams {
  191. p.SamplingInterval = samplingInterval
  192. return &p
  193. }
  194. // WithIncludeObjectsCollectedByMajorGC by default, the sampling heap
  195. // profiler reports only objects which are still alive when the profile is
  196. // returned via getSamplingProfile or stopSampling, which is useful for
  197. // determining what functions contribute the most to steady-state memory usage.
  198. // This flag instructs the sampling heap profiler to also include information
  199. // about objects discarded by major GC, which will show which functions cause
  200. // large temporary memory usage or long GC pauses.
  201. func (p StartSamplingParams) WithIncludeObjectsCollectedByMajorGC(includeObjectsCollectedByMajorGC bool) *StartSamplingParams {
  202. p.IncludeObjectsCollectedByMajorGC = includeObjectsCollectedByMajorGC
  203. return &p
  204. }
  205. // WithIncludeObjectsCollectedByMinorGC by default, the sampling heap
  206. // profiler reports only objects which are still alive when the profile is
  207. // returned via getSamplingProfile or stopSampling, which is useful for
  208. // determining what functions contribute the most to steady-state memory usage.
  209. // This flag instructs the sampling heap profiler to also include information
  210. // about objects discarded by minor GC, which is useful when tuning a
  211. // latency-sensitive application for minimal GC activity.
  212. func (p StartSamplingParams) WithIncludeObjectsCollectedByMinorGC(includeObjectsCollectedByMinorGC bool) *StartSamplingParams {
  213. p.IncludeObjectsCollectedByMinorGC = includeObjectsCollectedByMinorGC
  214. return &p
  215. }
  216. // Do executes HeapProfiler.startSampling against the provided context.
  217. func (p *StartSamplingParams) Do(ctx context.Context) (err error) {
  218. return cdp.Execute(ctx, CommandStartSampling, p, nil)
  219. }
  220. // StartTrackingHeapObjectsParams [no description].
  221. type StartTrackingHeapObjectsParams struct {
  222. TrackAllocations bool `json:"trackAllocations"`
  223. }
  224. // StartTrackingHeapObjects [no description].
  225. //
  226. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-startTrackingHeapObjects
  227. //
  228. // parameters:
  229. func StartTrackingHeapObjects() *StartTrackingHeapObjectsParams {
  230. return &StartTrackingHeapObjectsParams{
  231. TrackAllocations: false,
  232. }
  233. }
  234. // WithTrackAllocations [no description].
  235. func (p StartTrackingHeapObjectsParams) WithTrackAllocations(trackAllocations bool) *StartTrackingHeapObjectsParams {
  236. p.TrackAllocations = trackAllocations
  237. return &p
  238. }
  239. // Do executes HeapProfiler.startTrackingHeapObjects against the provided context.
  240. func (p *StartTrackingHeapObjectsParams) Do(ctx context.Context) (err error) {
  241. return cdp.Execute(ctx, CommandStartTrackingHeapObjects, p, nil)
  242. }
  243. // StopSamplingParams [no description].
  244. type StopSamplingParams struct{}
  245. // StopSampling [no description].
  246. //
  247. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-stopSampling
  248. func StopSampling() *StopSamplingParams {
  249. return &StopSamplingParams{}
  250. }
  251. // StopSamplingReturns return values.
  252. type StopSamplingReturns struct {
  253. Profile *SamplingHeapProfile `json:"profile,omitempty,omitzero"` // Recorded sampling heap profile.
  254. }
  255. // Do executes HeapProfiler.stopSampling against the provided context.
  256. //
  257. // returns:
  258. //
  259. // profile - Recorded sampling heap profile.
  260. func (p *StopSamplingParams) Do(ctx context.Context) (profile *SamplingHeapProfile, err error) {
  261. // execute
  262. var res StopSamplingReturns
  263. err = cdp.Execute(ctx, CommandStopSampling, nil, &res)
  264. if err != nil {
  265. return nil, err
  266. }
  267. return res.Profile, nil
  268. }
  269. // StopTrackingHeapObjectsParams [no description].
  270. type StopTrackingHeapObjectsParams struct {
  271. ReportProgress bool `json:"reportProgress"` // If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken when the tracking is stopped.
  272. CaptureNumericValue bool `json:"captureNumericValue"` // If true, numerical values are included in the snapshot
  273. ExposeInternals bool `json:"exposeInternals"` // If true, exposes internals of the snapshot.
  274. }
  275. // StopTrackingHeapObjects [no description].
  276. //
  277. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-stopTrackingHeapObjects
  278. //
  279. // parameters:
  280. func StopTrackingHeapObjects() *StopTrackingHeapObjectsParams {
  281. return &StopTrackingHeapObjectsParams{
  282. ReportProgress: false,
  283. CaptureNumericValue: false,
  284. ExposeInternals: false,
  285. }
  286. }
  287. // WithReportProgress if true 'reportHeapSnapshotProgress' events will be
  288. // generated while snapshot is being taken when the tracking is stopped.
  289. func (p StopTrackingHeapObjectsParams) WithReportProgress(reportProgress bool) *StopTrackingHeapObjectsParams {
  290. p.ReportProgress = reportProgress
  291. return &p
  292. }
  293. // WithCaptureNumericValue if true, numerical values are included in the
  294. // snapshot.
  295. func (p StopTrackingHeapObjectsParams) WithCaptureNumericValue(captureNumericValue bool) *StopTrackingHeapObjectsParams {
  296. p.CaptureNumericValue = captureNumericValue
  297. return &p
  298. }
  299. // WithExposeInternals if true, exposes internals of the snapshot.
  300. func (p StopTrackingHeapObjectsParams) WithExposeInternals(exposeInternals bool) *StopTrackingHeapObjectsParams {
  301. p.ExposeInternals = exposeInternals
  302. return &p
  303. }
  304. // Do executes HeapProfiler.stopTrackingHeapObjects against the provided context.
  305. func (p *StopTrackingHeapObjectsParams) Do(ctx context.Context) (err error) {
  306. return cdp.Execute(ctx, CommandStopTrackingHeapObjects, p, nil)
  307. }
  308. // TakeHeapSnapshotParams [no description].
  309. type TakeHeapSnapshotParams struct {
  310. ReportProgress bool `json:"reportProgress"` // If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken.
  311. CaptureNumericValue bool `json:"captureNumericValue"` // If true, numerical values are included in the snapshot
  312. ExposeInternals bool `json:"exposeInternals"` // If true, exposes internals of the snapshot.
  313. }
  314. // TakeHeapSnapshot [no description].
  315. //
  316. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-takeHeapSnapshot
  317. //
  318. // parameters:
  319. func TakeHeapSnapshot() *TakeHeapSnapshotParams {
  320. return &TakeHeapSnapshotParams{
  321. ReportProgress: false,
  322. CaptureNumericValue: false,
  323. ExposeInternals: false,
  324. }
  325. }
  326. // WithReportProgress if true 'reportHeapSnapshotProgress' events will be
  327. // generated while snapshot is being taken.
  328. func (p TakeHeapSnapshotParams) WithReportProgress(reportProgress bool) *TakeHeapSnapshotParams {
  329. p.ReportProgress = reportProgress
  330. return &p
  331. }
  332. // WithCaptureNumericValue if true, numerical values are included in the
  333. // snapshot.
  334. func (p TakeHeapSnapshotParams) WithCaptureNumericValue(captureNumericValue bool) *TakeHeapSnapshotParams {
  335. p.CaptureNumericValue = captureNumericValue
  336. return &p
  337. }
  338. // WithExposeInternals if true, exposes internals of the snapshot.
  339. func (p TakeHeapSnapshotParams) WithExposeInternals(exposeInternals bool) *TakeHeapSnapshotParams {
  340. p.ExposeInternals = exposeInternals
  341. return &p
  342. }
  343. // Do executes HeapProfiler.takeHeapSnapshot against the provided context.
  344. func (p *TakeHeapSnapshotParams) Do(ctx context.Context) (err error) {
  345. return cdp.Execute(ctx, CommandTakeHeapSnapshot, p, nil)
  346. }
  347. // Command names.
  348. const (
  349. CommandAddInspectedHeapObject = "HeapProfiler.addInspectedHeapObject"
  350. CommandCollectGarbage = "HeapProfiler.collectGarbage"
  351. CommandDisable = "HeapProfiler.disable"
  352. CommandEnable = "HeapProfiler.enable"
  353. CommandGetHeapObjectID = "HeapProfiler.getHeapObjectId"
  354. CommandGetObjectByHeapObjectID = "HeapProfiler.getObjectByHeapObjectId"
  355. CommandGetSamplingProfile = "HeapProfiler.getSamplingProfile"
  356. CommandStartSampling = "HeapProfiler.startSampling"
  357. CommandStartTrackingHeapObjects = "HeapProfiler.startTrackingHeapObjects"
  358. CommandStopSampling = "HeapProfiler.stopSampling"
  359. CommandStopTrackingHeapObjects = "HeapProfiler.stopTrackingHeapObjects"
  360. CommandTakeHeapSnapshot = "HeapProfiler.takeHeapSnapshot"
  361. )