profiler.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // Package profiler provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Profiler domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package profiler
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // DisableParams [no description].
  12. type DisableParams struct{}
  13. // Disable [no description].
  14. //
  15. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-disable
  16. func Disable() *DisableParams {
  17. return &DisableParams{}
  18. }
  19. // Do executes Profiler.disable against the provided context.
  20. func (p *DisableParams) Do(ctx context.Context) (err error) {
  21. return cdp.Execute(ctx, CommandDisable, nil, nil)
  22. }
  23. // EnableParams [no description].
  24. type EnableParams struct{}
  25. // Enable [no description].
  26. //
  27. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-enable
  28. func Enable() *EnableParams {
  29. return &EnableParams{}
  30. }
  31. // Do executes Profiler.enable against the provided context.
  32. func (p *EnableParams) Do(ctx context.Context) (err error) {
  33. return cdp.Execute(ctx, CommandEnable, nil, nil)
  34. }
  35. // GetBestEffortCoverageParams collect coverage data for the current isolate.
  36. // The coverage data may be incomplete due to garbage collection.
  37. type GetBestEffortCoverageParams struct{}
  38. // GetBestEffortCoverage collect coverage data for the current isolate. The
  39. // coverage data may be incomplete due to garbage collection.
  40. //
  41. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-getBestEffortCoverage
  42. func GetBestEffortCoverage() *GetBestEffortCoverageParams {
  43. return &GetBestEffortCoverageParams{}
  44. }
  45. // GetBestEffortCoverageReturns return values.
  46. type GetBestEffortCoverageReturns struct {
  47. Result []*ScriptCoverage `json:"result,omitempty,omitzero"` // Coverage data for the current isolate.
  48. }
  49. // Do executes Profiler.getBestEffortCoverage against the provided context.
  50. //
  51. // returns:
  52. //
  53. // result - Coverage data for the current isolate.
  54. func (p *GetBestEffortCoverageParams) Do(ctx context.Context) (result []*ScriptCoverage, err error) {
  55. // execute
  56. var res GetBestEffortCoverageReturns
  57. err = cdp.Execute(ctx, CommandGetBestEffortCoverage, nil, &res)
  58. if err != nil {
  59. return nil, err
  60. }
  61. return res.Result, nil
  62. }
  63. // SetSamplingIntervalParams changes CPU profiler sampling interval. Must be
  64. // called before CPU profiles recording started.
  65. type SetSamplingIntervalParams struct {
  66. Interval int64 `json:"interval"` // New sampling interval in microseconds.
  67. }
  68. // SetSamplingInterval changes CPU profiler sampling interval. Must be called
  69. // before CPU profiles recording started.
  70. //
  71. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-setSamplingInterval
  72. //
  73. // parameters:
  74. //
  75. // interval - New sampling interval in microseconds.
  76. func SetSamplingInterval(interval int64) *SetSamplingIntervalParams {
  77. return &SetSamplingIntervalParams{
  78. Interval: interval,
  79. }
  80. }
  81. // Do executes Profiler.setSamplingInterval against the provided context.
  82. func (p *SetSamplingIntervalParams) Do(ctx context.Context) (err error) {
  83. return cdp.Execute(ctx, CommandSetSamplingInterval, p, nil)
  84. }
  85. // StartParams [no description].
  86. type StartParams struct{}
  87. // Start [no description].
  88. //
  89. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-start
  90. func Start() *StartParams {
  91. return &StartParams{}
  92. }
  93. // Do executes Profiler.start against the provided context.
  94. func (p *StartParams) Do(ctx context.Context) (err error) {
  95. return cdp.Execute(ctx, CommandStart, nil, nil)
  96. }
  97. // StartPreciseCoverageParams enable precise code coverage. Coverage data for
  98. // JavaScript executed before enabling precise code coverage may be incomplete.
  99. // Enabling prevents running optimized code and resets execution counters.
  100. type StartPreciseCoverageParams struct {
  101. CallCount bool `json:"callCount"` // Collect accurate call counts beyond simple 'covered' or 'not covered'.
  102. Detailed bool `json:"detailed"` // Collect block-based coverage.
  103. AllowTriggeredUpdates bool `json:"allowTriggeredUpdates"` // Allow the backend to send updates on its own initiative
  104. }
  105. // StartPreciseCoverage enable precise code coverage. Coverage data for
  106. // JavaScript executed before enabling precise code coverage may be incomplete.
  107. // Enabling prevents running optimized code and resets execution counters.
  108. //
  109. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-startPreciseCoverage
  110. //
  111. // parameters:
  112. func StartPreciseCoverage() *StartPreciseCoverageParams {
  113. return &StartPreciseCoverageParams{
  114. CallCount: false,
  115. Detailed: false,
  116. AllowTriggeredUpdates: false,
  117. }
  118. }
  119. // WithCallCount collect accurate call counts beyond simple 'covered' or 'not
  120. // covered'.
  121. func (p StartPreciseCoverageParams) WithCallCount(callCount bool) *StartPreciseCoverageParams {
  122. p.CallCount = callCount
  123. return &p
  124. }
  125. // WithDetailed collect block-based coverage.
  126. func (p StartPreciseCoverageParams) WithDetailed(detailed bool) *StartPreciseCoverageParams {
  127. p.Detailed = detailed
  128. return &p
  129. }
  130. // WithAllowTriggeredUpdates allow the backend to send updates on its own
  131. // initiative.
  132. func (p StartPreciseCoverageParams) WithAllowTriggeredUpdates(allowTriggeredUpdates bool) *StartPreciseCoverageParams {
  133. p.AllowTriggeredUpdates = allowTriggeredUpdates
  134. return &p
  135. }
  136. // StartPreciseCoverageReturns return values.
  137. type StartPreciseCoverageReturns struct {
  138. Timestamp float64 `json:"timestamp,omitempty,omitzero"` // Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  139. }
  140. // Do executes Profiler.startPreciseCoverage against the provided context.
  141. //
  142. // returns:
  143. //
  144. // timestamp - Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  145. func (p *StartPreciseCoverageParams) Do(ctx context.Context) (timestamp float64, err error) {
  146. // execute
  147. var res StartPreciseCoverageReturns
  148. err = cdp.Execute(ctx, CommandStartPreciseCoverage, p, &res)
  149. if err != nil {
  150. return 0, err
  151. }
  152. return res.Timestamp, nil
  153. }
  154. // StopParams [no description].
  155. type StopParams struct{}
  156. // Stop [no description].
  157. //
  158. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-stop
  159. func Stop() *StopParams {
  160. return &StopParams{}
  161. }
  162. // StopReturns return values.
  163. type StopReturns struct {
  164. Profile *Profile `json:"profile,omitempty,omitzero"` // Recorded profile.
  165. }
  166. // Do executes Profiler.stop against the provided context.
  167. //
  168. // returns:
  169. //
  170. // profile - Recorded profile.
  171. func (p *StopParams) Do(ctx context.Context) (profile *Profile, err error) {
  172. // execute
  173. var res StopReturns
  174. err = cdp.Execute(ctx, CommandStop, nil, &res)
  175. if err != nil {
  176. return nil, err
  177. }
  178. return res.Profile, nil
  179. }
  180. // StopPreciseCoverageParams disable precise code coverage. Disabling
  181. // releases unnecessary execution count records and allows executing optimized
  182. // code.
  183. type StopPreciseCoverageParams struct{}
  184. // StopPreciseCoverage disable precise code coverage. Disabling releases
  185. // unnecessary execution count records and allows executing optimized code.
  186. //
  187. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-stopPreciseCoverage
  188. func StopPreciseCoverage() *StopPreciseCoverageParams {
  189. return &StopPreciseCoverageParams{}
  190. }
  191. // Do executes Profiler.stopPreciseCoverage against the provided context.
  192. func (p *StopPreciseCoverageParams) Do(ctx context.Context) (err error) {
  193. return cdp.Execute(ctx, CommandStopPreciseCoverage, nil, nil)
  194. }
  195. // TakePreciseCoverageParams collect coverage data for the current isolate,
  196. // and resets execution counters. Precise code coverage needs to have started.
  197. type TakePreciseCoverageParams struct{}
  198. // TakePreciseCoverage collect coverage data for the current isolate, and
  199. // resets execution counters. Precise code coverage needs to have started.
  200. //
  201. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-takePreciseCoverage
  202. func TakePreciseCoverage() *TakePreciseCoverageParams {
  203. return &TakePreciseCoverageParams{}
  204. }
  205. // TakePreciseCoverageReturns return values.
  206. type TakePreciseCoverageReturns struct {
  207. Result []*ScriptCoverage `json:"result,omitempty,omitzero"` // Coverage data for the current isolate.
  208. Timestamp float64 `json:"timestamp,omitempty,omitzero"` // Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  209. }
  210. // Do executes Profiler.takePreciseCoverage against the provided context.
  211. //
  212. // returns:
  213. //
  214. // result - Coverage data for the current isolate.
  215. // timestamp - Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  216. func (p *TakePreciseCoverageParams) Do(ctx context.Context) (result []*ScriptCoverage, timestamp float64, err error) {
  217. // execute
  218. var res TakePreciseCoverageReturns
  219. err = cdp.Execute(ctx, CommandTakePreciseCoverage, nil, &res)
  220. if err != nil {
  221. return nil, 0, err
  222. }
  223. return res.Result, res.Timestamp, nil
  224. }
  225. // Command names.
  226. const (
  227. CommandDisable = "Profiler.disable"
  228. CommandEnable = "Profiler.enable"
  229. CommandGetBestEffortCoverage = "Profiler.getBestEffortCoverage"
  230. CommandSetSamplingInterval = "Profiler.setSamplingInterval"
  231. CommandStart = "Profiler.start"
  232. CommandStartPreciseCoverage = "Profiler.startPreciseCoverage"
  233. CommandStop = "Profiler.stop"
  234. CommandStopPreciseCoverage = "Profiler.stopPreciseCoverage"
  235. CommandTakePreciseCoverage = "Profiler.takePreciseCoverage"
  236. )