profiler.go 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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"` // 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,omitempty"` // Collect accurate call counts beyond simple 'covered' or 'not covered'.
  102. Detailed bool `json:"detailed,omitempty"` // Collect block-based coverage.
  103. AllowTriggeredUpdates bool `json:"allowTriggeredUpdates,omitempty"` // 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. }
  115. // WithCallCount collect accurate call counts beyond simple 'covered' or 'not
  116. // covered'.
  117. func (p StartPreciseCoverageParams) WithCallCount(callCount bool) *StartPreciseCoverageParams {
  118. p.CallCount = callCount
  119. return &p
  120. }
  121. // WithDetailed collect block-based coverage.
  122. func (p StartPreciseCoverageParams) WithDetailed(detailed bool) *StartPreciseCoverageParams {
  123. p.Detailed = detailed
  124. return &p
  125. }
  126. // WithAllowTriggeredUpdates allow the backend to send updates on its own
  127. // initiative.
  128. func (p StartPreciseCoverageParams) WithAllowTriggeredUpdates(allowTriggeredUpdates bool) *StartPreciseCoverageParams {
  129. p.AllowTriggeredUpdates = allowTriggeredUpdates
  130. return &p
  131. }
  132. // StartPreciseCoverageReturns return values.
  133. type StartPreciseCoverageReturns struct {
  134. Timestamp float64 `json:"timestamp,omitempty"` // Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  135. }
  136. // Do executes Profiler.startPreciseCoverage against the provided context.
  137. //
  138. // returns:
  139. //
  140. // timestamp - Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  141. func (p *StartPreciseCoverageParams) Do(ctx context.Context) (timestamp float64, err error) {
  142. // execute
  143. var res StartPreciseCoverageReturns
  144. err = cdp.Execute(ctx, CommandStartPreciseCoverage, p, &res)
  145. if err != nil {
  146. return 0, err
  147. }
  148. return res.Timestamp, nil
  149. }
  150. // StopParams [no description].
  151. type StopParams struct{}
  152. // Stop [no description].
  153. //
  154. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-stop
  155. func Stop() *StopParams {
  156. return &StopParams{}
  157. }
  158. // StopReturns return values.
  159. type StopReturns struct {
  160. Profile *Profile `json:"profile,omitempty"` // Recorded profile.
  161. }
  162. // Do executes Profiler.stop against the provided context.
  163. //
  164. // returns:
  165. //
  166. // profile - Recorded profile.
  167. func (p *StopParams) Do(ctx context.Context) (profile *Profile, err error) {
  168. // execute
  169. var res StopReturns
  170. err = cdp.Execute(ctx, CommandStop, nil, &res)
  171. if err != nil {
  172. return nil, err
  173. }
  174. return res.Profile, nil
  175. }
  176. // StopPreciseCoverageParams disable precise code coverage. Disabling
  177. // releases unnecessary execution count records and allows executing optimized
  178. // code.
  179. type StopPreciseCoverageParams struct{}
  180. // StopPreciseCoverage disable precise code coverage. Disabling releases
  181. // unnecessary execution count records and allows executing optimized code.
  182. //
  183. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-stopPreciseCoverage
  184. func StopPreciseCoverage() *StopPreciseCoverageParams {
  185. return &StopPreciseCoverageParams{}
  186. }
  187. // Do executes Profiler.stopPreciseCoverage against the provided context.
  188. func (p *StopPreciseCoverageParams) Do(ctx context.Context) (err error) {
  189. return cdp.Execute(ctx, CommandStopPreciseCoverage, nil, nil)
  190. }
  191. // TakePreciseCoverageParams collect coverage data for the current isolate,
  192. // and resets execution counters. Precise code coverage needs to have started.
  193. type TakePreciseCoverageParams struct{}
  194. // TakePreciseCoverage collect coverage data for the current isolate, and
  195. // resets execution counters. Precise code coverage needs to have started.
  196. //
  197. // See: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#method-takePreciseCoverage
  198. func TakePreciseCoverage() *TakePreciseCoverageParams {
  199. return &TakePreciseCoverageParams{}
  200. }
  201. // TakePreciseCoverageReturns return values.
  202. type TakePreciseCoverageReturns struct {
  203. Result []*ScriptCoverage `json:"result,omitempty"` // Coverage data for the current isolate.
  204. Timestamp float64 `json:"timestamp,omitempty"` // Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  205. }
  206. // Do executes Profiler.takePreciseCoverage against the provided context.
  207. //
  208. // returns:
  209. //
  210. // result - Coverage data for the current isolate.
  211. // timestamp - Monotonically increasing time (in seconds) when the coverage update was taken in the backend.
  212. func (p *TakePreciseCoverageParams) Do(ctx context.Context) (result []*ScriptCoverage, timestamp float64, err error) {
  213. // execute
  214. var res TakePreciseCoverageReturns
  215. err = cdp.Execute(ctx, CommandTakePreciseCoverage, nil, &res)
  216. if err != nil {
  217. return nil, 0, err
  218. }
  219. return res.Result, res.Timestamp, nil
  220. }
  221. // Command names.
  222. const (
  223. CommandDisable = "Profiler.disable"
  224. CommandEnable = "Profiler.enable"
  225. CommandGetBestEffortCoverage = "Profiler.getBestEffortCoverage"
  226. CommandSetSamplingInterval = "Profiler.setSamplingInterval"
  227. CommandStart = "Profiler.start"
  228. CommandStartPreciseCoverage = "Profiler.startPreciseCoverage"
  229. CommandStop = "Profiler.stop"
  230. CommandStopPreciseCoverage = "Profiler.stopPreciseCoverage"
  231. CommandTakePreciseCoverage = "Profiler.takePreciseCoverage"
  232. )