heapprofiler.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407
  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"` // 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"` // 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"` // 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"` // 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"` // Average sample interval in bytes. Poisson distribution is used for the intervals. The default value is 32768 bytes.
  174. IncludeObjectsCollectedByMajorGC bool `json:"includeObjectsCollectedByMajorGC,omitempty"` // 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,omitempty"` // 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. }
  185. // WithSamplingInterval average sample interval in bytes. Poisson
  186. // distribution is used for the intervals. The default value is 32768 bytes.
  187. func (p StartSamplingParams) WithSamplingInterval(samplingInterval float64) *StartSamplingParams {
  188. p.SamplingInterval = samplingInterval
  189. return &p
  190. }
  191. // WithIncludeObjectsCollectedByMajorGC by default, the sampling heap
  192. // profiler reports only objects which are still alive when the profile is
  193. // returned via getSamplingProfile or stopSampling, which is useful for
  194. // determining what functions contribute the most to steady-state memory usage.
  195. // This flag instructs the sampling heap profiler to also include information
  196. // about objects discarded by major GC, which will show which functions cause
  197. // large temporary memory usage or long GC pauses.
  198. func (p StartSamplingParams) WithIncludeObjectsCollectedByMajorGC(includeObjectsCollectedByMajorGC bool) *StartSamplingParams {
  199. p.IncludeObjectsCollectedByMajorGC = includeObjectsCollectedByMajorGC
  200. return &p
  201. }
  202. // WithIncludeObjectsCollectedByMinorGC by default, the sampling heap
  203. // profiler reports only objects which are still alive when the profile is
  204. // returned via getSamplingProfile or stopSampling, which is useful for
  205. // determining what functions contribute the most to steady-state memory usage.
  206. // This flag instructs the sampling heap profiler to also include information
  207. // about objects discarded by minor GC, which is useful when tuning a
  208. // latency-sensitive application for minimal GC activity.
  209. func (p StartSamplingParams) WithIncludeObjectsCollectedByMinorGC(includeObjectsCollectedByMinorGC bool) *StartSamplingParams {
  210. p.IncludeObjectsCollectedByMinorGC = includeObjectsCollectedByMinorGC
  211. return &p
  212. }
  213. // Do executes HeapProfiler.startSampling against the provided context.
  214. func (p *StartSamplingParams) Do(ctx context.Context) (err error) {
  215. return cdp.Execute(ctx, CommandStartSampling, p, nil)
  216. }
  217. // StartTrackingHeapObjectsParams [no description].
  218. type StartTrackingHeapObjectsParams struct {
  219. TrackAllocations bool `json:"trackAllocations,omitempty"`
  220. }
  221. // StartTrackingHeapObjects [no description].
  222. //
  223. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-startTrackingHeapObjects
  224. //
  225. // parameters:
  226. func StartTrackingHeapObjects() *StartTrackingHeapObjectsParams {
  227. return &StartTrackingHeapObjectsParams{}
  228. }
  229. // WithTrackAllocations [no description].
  230. func (p StartTrackingHeapObjectsParams) WithTrackAllocations(trackAllocations bool) *StartTrackingHeapObjectsParams {
  231. p.TrackAllocations = trackAllocations
  232. return &p
  233. }
  234. // Do executes HeapProfiler.startTrackingHeapObjects against the provided context.
  235. func (p *StartTrackingHeapObjectsParams) Do(ctx context.Context) (err error) {
  236. return cdp.Execute(ctx, CommandStartTrackingHeapObjects, p, nil)
  237. }
  238. // StopSamplingParams [no description].
  239. type StopSamplingParams struct{}
  240. // StopSampling [no description].
  241. //
  242. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-stopSampling
  243. func StopSampling() *StopSamplingParams {
  244. return &StopSamplingParams{}
  245. }
  246. // StopSamplingReturns return values.
  247. type StopSamplingReturns struct {
  248. Profile *SamplingHeapProfile `json:"profile,omitempty"` // Recorded sampling heap profile.
  249. }
  250. // Do executes HeapProfiler.stopSampling against the provided context.
  251. //
  252. // returns:
  253. //
  254. // profile - Recorded sampling heap profile.
  255. func (p *StopSamplingParams) Do(ctx context.Context) (profile *SamplingHeapProfile, err error) {
  256. // execute
  257. var res StopSamplingReturns
  258. err = cdp.Execute(ctx, CommandStopSampling, nil, &res)
  259. if err != nil {
  260. return nil, err
  261. }
  262. return res.Profile, nil
  263. }
  264. // StopTrackingHeapObjectsParams [no description].
  265. type StopTrackingHeapObjectsParams struct {
  266. ReportProgress bool `json:"reportProgress,omitempty"` // If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken when the tracking is stopped.
  267. CaptureNumericValue bool `json:"captureNumericValue,omitempty"` // If true, numerical values are included in the snapshot
  268. ExposeInternals bool `json:"exposeInternals,omitempty"` // If true, exposes internals of the snapshot.
  269. }
  270. // StopTrackingHeapObjects [no description].
  271. //
  272. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-stopTrackingHeapObjects
  273. //
  274. // parameters:
  275. func StopTrackingHeapObjects() *StopTrackingHeapObjectsParams {
  276. return &StopTrackingHeapObjectsParams{}
  277. }
  278. // WithReportProgress if true 'reportHeapSnapshotProgress' events will be
  279. // generated while snapshot is being taken when the tracking is stopped.
  280. func (p StopTrackingHeapObjectsParams) WithReportProgress(reportProgress bool) *StopTrackingHeapObjectsParams {
  281. p.ReportProgress = reportProgress
  282. return &p
  283. }
  284. // WithCaptureNumericValue if true, numerical values are included in the
  285. // snapshot.
  286. func (p StopTrackingHeapObjectsParams) WithCaptureNumericValue(captureNumericValue bool) *StopTrackingHeapObjectsParams {
  287. p.CaptureNumericValue = captureNumericValue
  288. return &p
  289. }
  290. // WithExposeInternals if true, exposes internals of the snapshot.
  291. func (p StopTrackingHeapObjectsParams) WithExposeInternals(exposeInternals bool) *StopTrackingHeapObjectsParams {
  292. p.ExposeInternals = exposeInternals
  293. return &p
  294. }
  295. // Do executes HeapProfiler.stopTrackingHeapObjects against the provided context.
  296. func (p *StopTrackingHeapObjectsParams) Do(ctx context.Context) (err error) {
  297. return cdp.Execute(ctx, CommandStopTrackingHeapObjects, p, nil)
  298. }
  299. // TakeHeapSnapshotParams [no description].
  300. type TakeHeapSnapshotParams struct {
  301. ReportProgress bool `json:"reportProgress,omitempty"` // If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken.
  302. CaptureNumericValue bool `json:"captureNumericValue,omitempty"` // If true, numerical values are included in the snapshot
  303. ExposeInternals bool `json:"exposeInternals,omitempty"` // If true, exposes internals of the snapshot.
  304. }
  305. // TakeHeapSnapshot [no description].
  306. //
  307. // See: https://chromedevtools.github.io/devtools-protocol/tot/HeapProfiler#method-takeHeapSnapshot
  308. //
  309. // parameters:
  310. func TakeHeapSnapshot() *TakeHeapSnapshotParams {
  311. return &TakeHeapSnapshotParams{}
  312. }
  313. // WithReportProgress if true 'reportHeapSnapshotProgress' events will be
  314. // generated while snapshot is being taken.
  315. func (p TakeHeapSnapshotParams) WithReportProgress(reportProgress bool) *TakeHeapSnapshotParams {
  316. p.ReportProgress = reportProgress
  317. return &p
  318. }
  319. // WithCaptureNumericValue if true, numerical values are included in the
  320. // snapshot.
  321. func (p TakeHeapSnapshotParams) WithCaptureNumericValue(captureNumericValue bool) *TakeHeapSnapshotParams {
  322. p.CaptureNumericValue = captureNumericValue
  323. return &p
  324. }
  325. // WithExposeInternals if true, exposes internals of the snapshot.
  326. func (p TakeHeapSnapshotParams) WithExposeInternals(exposeInternals bool) *TakeHeapSnapshotParams {
  327. p.ExposeInternals = exposeInternals
  328. return &p
  329. }
  330. // Do executes HeapProfiler.takeHeapSnapshot against the provided context.
  331. func (p *TakeHeapSnapshotParams) Do(ctx context.Context) (err error) {
  332. return cdp.Execute(ctx, CommandTakeHeapSnapshot, p, nil)
  333. }
  334. // Command names.
  335. const (
  336. CommandAddInspectedHeapObject = "HeapProfiler.addInspectedHeapObject"
  337. CommandCollectGarbage = "HeapProfiler.collectGarbage"
  338. CommandDisable = "HeapProfiler.disable"
  339. CommandEnable = "HeapProfiler.enable"
  340. CommandGetHeapObjectID = "HeapProfiler.getHeapObjectId"
  341. CommandGetObjectByHeapObjectID = "HeapProfiler.getObjectByHeapObjectId"
  342. CommandGetSamplingProfile = "HeapProfiler.getSamplingProfile"
  343. CommandStartSampling = "HeapProfiler.startSampling"
  344. CommandStartTrackingHeapObjects = "HeapProfiler.startTrackingHeapObjects"
  345. CommandStopSampling = "HeapProfiler.stopSampling"
  346. CommandStopTrackingHeapObjects = "HeapProfiler.stopTrackingHeapObjects"
  347. CommandTakeHeapSnapshot = "HeapProfiler.takeHeapSnapshot"
  348. )