memory.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. // Package memory provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Memory domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package memory
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // GetDOMCountersParams retruns current DOM object counters.
  12. type GetDOMCountersParams struct{}
  13. // GetDOMCounters retruns current DOM object counters.
  14. //
  15. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getDOMCounters
  16. func GetDOMCounters() *GetDOMCountersParams {
  17. return &GetDOMCountersParams{}
  18. }
  19. // GetDOMCountersReturns return values.
  20. type GetDOMCountersReturns struct {
  21. Documents int64 `json:"documents,omitempty,omitzero"`
  22. Nodes int64 `json:"nodes,omitempty,omitzero"`
  23. JsEventListeners int64 `json:"jsEventListeners,omitempty,omitzero"`
  24. }
  25. // Do executes Memory.getDOMCounters against the provided context.
  26. //
  27. // returns:
  28. //
  29. // documents
  30. // nodes
  31. // jsEventListeners
  32. func (p *GetDOMCountersParams) Do(ctx context.Context) (documents int64, nodes int64, jsEventListeners int64, err error) {
  33. // execute
  34. var res GetDOMCountersReturns
  35. err = cdp.Execute(ctx, CommandGetDOMCounters, nil, &res)
  36. if err != nil {
  37. return 0, 0, 0, err
  38. }
  39. return res.Documents, res.Nodes, res.JsEventListeners, nil
  40. }
  41. // GetDOMCountersForLeakDetectionParams retruns DOM object counters after
  42. // preparing renderer for leak detection.
  43. type GetDOMCountersForLeakDetectionParams struct{}
  44. // GetDOMCountersForLeakDetection retruns DOM object counters after preparing
  45. // renderer for leak detection.
  46. //
  47. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getDOMCountersForLeakDetection
  48. func GetDOMCountersForLeakDetection() *GetDOMCountersForLeakDetectionParams {
  49. return &GetDOMCountersForLeakDetectionParams{}
  50. }
  51. // GetDOMCountersForLeakDetectionReturns return values.
  52. type GetDOMCountersForLeakDetectionReturns struct {
  53. Counters []*DOMCounter `json:"counters,omitempty,omitzero"` // DOM object counters.
  54. }
  55. // Do executes Memory.getDOMCountersForLeakDetection against the provided context.
  56. //
  57. // returns:
  58. //
  59. // counters - DOM object counters.
  60. func (p *GetDOMCountersForLeakDetectionParams) Do(ctx context.Context) (counters []*DOMCounter, err error) {
  61. // execute
  62. var res GetDOMCountersForLeakDetectionReturns
  63. err = cdp.Execute(ctx, CommandGetDOMCountersForLeakDetection, nil, &res)
  64. if err != nil {
  65. return nil, err
  66. }
  67. return res.Counters, nil
  68. }
  69. // PrepareForLeakDetectionParams prepares for leak detection by terminating
  70. // workers, stopping spellcheckers, dropping non-essential internal caches,
  71. // running garbage collections, etc.
  72. type PrepareForLeakDetectionParams struct{}
  73. // PrepareForLeakDetection prepares for leak detection by terminating
  74. // workers, stopping spellcheckers, dropping non-essential internal caches,
  75. // running garbage collections, etc.
  76. //
  77. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-prepareForLeakDetection
  78. func PrepareForLeakDetection() *PrepareForLeakDetectionParams {
  79. return &PrepareForLeakDetectionParams{}
  80. }
  81. // Do executes Memory.prepareForLeakDetection against the provided context.
  82. func (p *PrepareForLeakDetectionParams) Do(ctx context.Context) (err error) {
  83. return cdp.Execute(ctx, CommandPrepareForLeakDetection, nil, nil)
  84. }
  85. // ForciblyPurgeJavaScriptMemoryParams simulate OomIntervention by purging V8
  86. // memory.
  87. type ForciblyPurgeJavaScriptMemoryParams struct{}
  88. // ForciblyPurgeJavaScriptMemory simulate OomIntervention by purging V8
  89. // memory.
  90. //
  91. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-forciblyPurgeJavaScriptMemory
  92. func ForciblyPurgeJavaScriptMemory() *ForciblyPurgeJavaScriptMemoryParams {
  93. return &ForciblyPurgeJavaScriptMemoryParams{}
  94. }
  95. // Do executes Memory.forciblyPurgeJavaScriptMemory against the provided context.
  96. func (p *ForciblyPurgeJavaScriptMemoryParams) Do(ctx context.Context) (err error) {
  97. return cdp.Execute(ctx, CommandForciblyPurgeJavaScriptMemory, nil, nil)
  98. }
  99. // SetPressureNotificationsSuppressedParams enable/disable suppressing memory
  100. // pressure notifications in all processes.
  101. type SetPressureNotificationsSuppressedParams struct {
  102. Suppressed bool `json:"suppressed"` // If true, memory pressure notifications will be suppressed.
  103. }
  104. // SetPressureNotificationsSuppressed enable/disable suppressing memory
  105. // pressure notifications in all processes.
  106. //
  107. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-setPressureNotificationsSuppressed
  108. //
  109. // parameters:
  110. //
  111. // suppressed - If true, memory pressure notifications will be suppressed.
  112. func SetPressureNotificationsSuppressed(suppressed bool) *SetPressureNotificationsSuppressedParams {
  113. return &SetPressureNotificationsSuppressedParams{
  114. Suppressed: suppressed,
  115. }
  116. }
  117. // Do executes Memory.setPressureNotificationsSuppressed against the provided context.
  118. func (p *SetPressureNotificationsSuppressedParams) Do(ctx context.Context) (err error) {
  119. return cdp.Execute(ctx, CommandSetPressureNotificationsSuppressed, p, nil)
  120. }
  121. // SimulatePressureNotificationParams simulate a memory pressure notification
  122. // in all processes.
  123. type SimulatePressureNotificationParams struct {
  124. Level PressureLevel `json:"level"` // Memory pressure level of the notification.
  125. }
  126. // SimulatePressureNotification simulate a memory pressure notification in
  127. // all processes.
  128. //
  129. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-simulatePressureNotification
  130. //
  131. // parameters:
  132. //
  133. // level - Memory pressure level of the notification.
  134. func SimulatePressureNotification(level PressureLevel) *SimulatePressureNotificationParams {
  135. return &SimulatePressureNotificationParams{
  136. Level: level,
  137. }
  138. }
  139. // Do executes Memory.simulatePressureNotification against the provided context.
  140. func (p *SimulatePressureNotificationParams) Do(ctx context.Context) (err error) {
  141. return cdp.Execute(ctx, CommandSimulatePressureNotification, p, nil)
  142. }
  143. // StartSamplingParams start collecting native memory profile.
  144. type StartSamplingParams struct {
  145. SamplingInterval int64 `json:"samplingInterval,omitempty,omitzero"` // Average number of bytes between samples.
  146. SuppressRandomness bool `json:"suppressRandomness"` // Do not randomize intervals between samples.
  147. }
  148. // StartSampling start collecting native memory profile.
  149. //
  150. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-startSampling
  151. //
  152. // parameters:
  153. func StartSampling() *StartSamplingParams {
  154. return &StartSamplingParams{
  155. SuppressRandomness: false,
  156. }
  157. }
  158. // WithSamplingInterval average number of bytes between samples.
  159. func (p StartSamplingParams) WithSamplingInterval(samplingInterval int64) *StartSamplingParams {
  160. p.SamplingInterval = samplingInterval
  161. return &p
  162. }
  163. // WithSuppressRandomness do not randomize intervals between samples.
  164. func (p StartSamplingParams) WithSuppressRandomness(suppressRandomness bool) *StartSamplingParams {
  165. p.SuppressRandomness = suppressRandomness
  166. return &p
  167. }
  168. // Do executes Memory.startSampling against the provided context.
  169. func (p *StartSamplingParams) Do(ctx context.Context) (err error) {
  170. return cdp.Execute(ctx, CommandStartSampling, p, nil)
  171. }
  172. // StopSamplingParams stop collecting native memory profile.
  173. type StopSamplingParams struct{}
  174. // StopSampling stop collecting native memory profile.
  175. //
  176. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-stopSampling
  177. func StopSampling() *StopSamplingParams {
  178. return &StopSamplingParams{}
  179. }
  180. // Do executes Memory.stopSampling against the provided context.
  181. func (p *StopSamplingParams) Do(ctx context.Context) (err error) {
  182. return cdp.Execute(ctx, CommandStopSampling, nil, nil)
  183. }
  184. // GetAllTimeSamplingProfileParams retrieve native memory allocations profile
  185. // collected since renderer process startup.
  186. type GetAllTimeSamplingProfileParams struct{}
  187. // GetAllTimeSamplingProfile retrieve native memory allocations profile
  188. // collected since renderer process startup.
  189. //
  190. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getAllTimeSamplingProfile
  191. func GetAllTimeSamplingProfile() *GetAllTimeSamplingProfileParams {
  192. return &GetAllTimeSamplingProfileParams{}
  193. }
  194. // GetAllTimeSamplingProfileReturns return values.
  195. type GetAllTimeSamplingProfileReturns struct {
  196. Profile *SamplingProfile `json:"profile,omitempty,omitzero"`
  197. }
  198. // Do executes Memory.getAllTimeSamplingProfile against the provided context.
  199. //
  200. // returns:
  201. //
  202. // profile
  203. func (p *GetAllTimeSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
  204. // execute
  205. var res GetAllTimeSamplingProfileReturns
  206. err = cdp.Execute(ctx, CommandGetAllTimeSamplingProfile, nil, &res)
  207. if err != nil {
  208. return nil, err
  209. }
  210. return res.Profile, nil
  211. }
  212. // GetBrowserSamplingProfileParams retrieve native memory allocations profile
  213. // collected since browser process startup.
  214. type GetBrowserSamplingProfileParams struct{}
  215. // GetBrowserSamplingProfile retrieve native memory allocations profile
  216. // collected since browser process startup.
  217. //
  218. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getBrowserSamplingProfile
  219. func GetBrowserSamplingProfile() *GetBrowserSamplingProfileParams {
  220. return &GetBrowserSamplingProfileParams{}
  221. }
  222. // GetBrowserSamplingProfileReturns return values.
  223. type GetBrowserSamplingProfileReturns struct {
  224. Profile *SamplingProfile `json:"profile,omitempty,omitzero"`
  225. }
  226. // Do executes Memory.getBrowserSamplingProfile against the provided context.
  227. //
  228. // returns:
  229. //
  230. // profile
  231. func (p *GetBrowserSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
  232. // execute
  233. var res GetBrowserSamplingProfileReturns
  234. err = cdp.Execute(ctx, CommandGetBrowserSamplingProfile, nil, &res)
  235. if err != nil {
  236. return nil, err
  237. }
  238. return res.Profile, nil
  239. }
  240. // GetSamplingProfileParams retrieve native memory allocations profile
  241. // collected since last startSampling call.
  242. type GetSamplingProfileParams struct{}
  243. // GetSamplingProfile retrieve native memory allocations profile collected
  244. // since last startSampling call.
  245. //
  246. // See: https://chromedevtools.github.io/devtools-protocol/tot/Memory#method-getSamplingProfile
  247. func GetSamplingProfile() *GetSamplingProfileParams {
  248. return &GetSamplingProfileParams{}
  249. }
  250. // GetSamplingProfileReturns return values.
  251. type GetSamplingProfileReturns struct {
  252. Profile *SamplingProfile `json:"profile,omitempty,omitzero"`
  253. }
  254. // Do executes Memory.getSamplingProfile against the provided context.
  255. //
  256. // returns:
  257. //
  258. // profile
  259. func (p *GetSamplingProfileParams) Do(ctx context.Context) (profile *SamplingProfile, err error) {
  260. // execute
  261. var res GetSamplingProfileReturns
  262. err = cdp.Execute(ctx, CommandGetSamplingProfile, nil, &res)
  263. if err != nil {
  264. return nil, err
  265. }
  266. return res.Profile, nil
  267. }
  268. // Command names.
  269. const (
  270. CommandGetDOMCounters = "Memory.getDOMCounters"
  271. CommandGetDOMCountersForLeakDetection = "Memory.getDOMCountersForLeakDetection"
  272. CommandPrepareForLeakDetection = "Memory.prepareForLeakDetection"
  273. CommandForciblyPurgeJavaScriptMemory = "Memory.forciblyPurgeJavaScriptMemory"
  274. CommandSetPressureNotificationsSuppressed = "Memory.setPressureNotificationsSuppressed"
  275. CommandSimulatePressureNotification = "Memory.simulatePressureNotification"
  276. CommandStartSampling = "Memory.startSampling"
  277. CommandStopSampling = "Memory.stopSampling"
  278. CommandGetAllTimeSamplingProfile = "Memory.getAllTimeSamplingProfile"
  279. CommandGetBrowserSamplingProfile = "Memory.getBrowserSamplingProfile"
  280. CommandGetSamplingProfile = "Memory.getSamplingProfile"
  281. )