performance.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Package performance provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Performance domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package performance
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // DisableParams disable collecting and reporting metrics.
  12. type DisableParams struct{}
  13. // Disable disable collecting and reporting metrics.
  14. //
  15. // See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-disable
  16. func Disable() *DisableParams {
  17. return &DisableParams{}
  18. }
  19. // Do executes Performance.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 enable collecting and reporting metrics.
  24. type EnableParams struct {
  25. TimeDomain EnableTimeDomain `json:"timeDomain,omitempty,omitzero"` // Time domain to use for collecting and reporting duration metrics.
  26. }
  27. // Enable enable collecting and reporting metrics.
  28. //
  29. // See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-enable
  30. //
  31. // parameters:
  32. func Enable() *EnableParams {
  33. return &EnableParams{}
  34. }
  35. // WithTimeDomain time domain to use for collecting and reporting duration
  36. // metrics.
  37. func (p EnableParams) WithTimeDomain(timeDomain EnableTimeDomain) *EnableParams {
  38. p.TimeDomain = timeDomain
  39. return &p
  40. }
  41. // Do executes Performance.enable against the provided context.
  42. func (p *EnableParams) Do(ctx context.Context) (err error) {
  43. return cdp.Execute(ctx, CommandEnable, p, nil)
  44. }
  45. // GetMetricsParams retrieve current values of run-time metrics.
  46. type GetMetricsParams struct{}
  47. // GetMetrics retrieve current values of run-time metrics.
  48. //
  49. // See: https://chromedevtools.github.io/devtools-protocol/tot/Performance#method-getMetrics
  50. func GetMetrics() *GetMetricsParams {
  51. return &GetMetricsParams{}
  52. }
  53. // GetMetricsReturns return values.
  54. type GetMetricsReturns struct {
  55. Metrics []*Metric `json:"metrics,omitempty,omitzero"` // Current values for run-time metrics.
  56. }
  57. // Do executes Performance.getMetrics against the provided context.
  58. //
  59. // returns:
  60. //
  61. // metrics - Current values for run-time metrics.
  62. func (p *GetMetricsParams) Do(ctx context.Context) (metrics []*Metric, err error) {
  63. // execute
  64. var res GetMetricsReturns
  65. err = cdp.Execute(ctx, CommandGetMetrics, nil, &res)
  66. if err != nil {
  67. return nil, err
  68. }
  69. return res.Metrics, nil
  70. }
  71. // Command names.
  72. const (
  73. CommandDisable = "Performance.disable"
  74. CommandEnable = "Performance.enable"
  75. CommandGetMetrics = "Performance.getMetrics"
  76. )