tracing.go 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // Package tracing provides the Chrome DevTools Protocol
  2. // commands, types, and events for the Tracing domain.
  3. //
  4. // Generated by the cdproto-gen command.
  5. package tracing
  6. // Code generated by cdproto-gen. DO NOT EDIT.
  7. import (
  8. "context"
  9. "github.com/chromedp/cdproto/cdp"
  10. )
  11. // EndParams stop trace events collection.
  12. type EndParams struct{}
  13. // End stop trace events collection.
  14. //
  15. // See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-end
  16. func End() *EndParams {
  17. return &EndParams{}
  18. }
  19. // Do executes Tracing.end against the provided context.
  20. func (p *EndParams) Do(ctx context.Context) (err error) {
  21. return cdp.Execute(ctx, CommandEnd, nil, nil)
  22. }
  23. // GetCategoriesParams gets supported tracing categories.
  24. type GetCategoriesParams struct{}
  25. // GetCategories gets supported tracing categories.
  26. //
  27. // See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-getCategories
  28. func GetCategories() *GetCategoriesParams {
  29. return &GetCategoriesParams{}
  30. }
  31. // GetCategoriesReturns return values.
  32. type GetCategoriesReturns struct {
  33. Categories []string `json:"categories,omitempty,omitzero"` // A list of supported tracing categories.
  34. }
  35. // Do executes Tracing.getCategories against the provided context.
  36. //
  37. // returns:
  38. //
  39. // categories - A list of supported tracing categories.
  40. func (p *GetCategoriesParams) Do(ctx context.Context) (categories []string, err error) {
  41. // execute
  42. var res GetCategoriesReturns
  43. err = cdp.Execute(ctx, CommandGetCategories, nil, &res)
  44. if err != nil {
  45. return nil, err
  46. }
  47. return res.Categories, nil
  48. }
  49. // RecordClockSyncMarkerParams record a clock sync marker in the trace.
  50. type RecordClockSyncMarkerParams struct {
  51. SyncID string `json:"syncId"` // The ID of this clock sync marker
  52. }
  53. // RecordClockSyncMarker record a clock sync marker in the trace.
  54. //
  55. // See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-recordClockSyncMarker
  56. //
  57. // parameters:
  58. //
  59. // syncID - The ID of this clock sync marker
  60. func RecordClockSyncMarker(syncID string) *RecordClockSyncMarkerParams {
  61. return &RecordClockSyncMarkerParams{
  62. SyncID: syncID,
  63. }
  64. }
  65. // Do executes Tracing.recordClockSyncMarker against the provided context.
  66. func (p *RecordClockSyncMarkerParams) Do(ctx context.Context) (err error) {
  67. return cdp.Execute(ctx, CommandRecordClockSyncMarker, p, nil)
  68. }
  69. // RequestMemoryDumpParams request a global memory dump.
  70. type RequestMemoryDumpParams struct {
  71. Deterministic bool `json:"deterministic"` // Enables more deterministic results by forcing garbage collection
  72. LevelOfDetail MemoryDumpLevelOfDetail `json:"levelOfDetail,omitempty,omitzero"` // Specifies level of details in memory dump. Defaults to "detailed".
  73. }
  74. // RequestMemoryDump request a global memory dump.
  75. //
  76. // See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-requestMemoryDump
  77. //
  78. // parameters:
  79. func RequestMemoryDump() *RequestMemoryDumpParams {
  80. return &RequestMemoryDumpParams{
  81. Deterministic: false,
  82. }
  83. }
  84. // WithDeterministic enables more deterministic results by forcing garbage
  85. // collection.
  86. func (p RequestMemoryDumpParams) WithDeterministic(deterministic bool) *RequestMemoryDumpParams {
  87. p.Deterministic = deterministic
  88. return &p
  89. }
  90. // WithLevelOfDetail specifies level of details in memory dump. Defaults to
  91. // "detailed".
  92. func (p RequestMemoryDumpParams) WithLevelOfDetail(levelOfDetail MemoryDumpLevelOfDetail) *RequestMemoryDumpParams {
  93. p.LevelOfDetail = levelOfDetail
  94. return &p
  95. }
  96. // RequestMemoryDumpReturns return values.
  97. type RequestMemoryDumpReturns struct {
  98. DumpGUID string `json:"dumpGuid,omitempty,omitzero"` // GUID of the resulting global memory dump.
  99. Success bool `json:"success"` // True iff the global memory dump succeeded.
  100. }
  101. // Do executes Tracing.requestMemoryDump against the provided context.
  102. //
  103. // returns:
  104. //
  105. // dumpGUID - GUID of the resulting global memory dump.
  106. // success - True iff the global memory dump succeeded.
  107. func (p *RequestMemoryDumpParams) Do(ctx context.Context) (dumpGUID string, success bool, err error) {
  108. // execute
  109. var res RequestMemoryDumpReturns
  110. err = cdp.Execute(ctx, CommandRequestMemoryDump, p, &res)
  111. if err != nil {
  112. return "", false, err
  113. }
  114. return res.DumpGUID, res.Success, nil
  115. }
  116. // StartParams start trace events collection.
  117. type StartParams struct {
  118. BufferUsageReportingInterval float64 `json:"bufferUsageReportingInterval,omitempty,omitzero"` // If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
  119. TransferMode TransferMode `json:"transferMode,omitempty,omitzero"` // Whether to report trace events as series of dataCollected events or to save trace to a stream (defaults to ReportEvents).
  120. StreamFormat StreamFormat `json:"streamFormat,omitempty,omitzero"` // Trace data format to use. This only applies when using ReturnAsStream transfer mode (defaults to json).
  121. StreamCompression StreamCompression `json:"streamCompression,omitempty,omitzero"` // Compression format to use. This only applies when using ReturnAsStream transfer mode (defaults to none)
  122. TraceConfig *TraceConfig `json:"traceConfig,omitempty,omitzero"`
  123. PerfettoConfig string `json:"perfettoConfig,omitempty,omitzero"` // Base64-encoded serialized perfetto.protos.TraceConfig protobuf message When specified, the parameters categories, options, traceConfig are ignored.
  124. TracingBackend Backend `json:"tracingBackend,omitempty,omitzero"` // Backend type (defaults to auto)
  125. }
  126. // Start start trace events collection.
  127. //
  128. // See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-start
  129. //
  130. // parameters:
  131. func Start() *StartParams {
  132. return &StartParams{}
  133. }
  134. // WithBufferUsageReportingInterval if set, the agent will issue bufferUsage
  135. // events at this interval, specified in milliseconds.
  136. func (p StartParams) WithBufferUsageReportingInterval(bufferUsageReportingInterval float64) *StartParams {
  137. p.BufferUsageReportingInterval = bufferUsageReportingInterval
  138. return &p
  139. }
  140. // WithTransferMode whether to report trace events as series of dataCollected
  141. // events or to save trace to a stream (defaults to ReportEvents).
  142. func (p StartParams) WithTransferMode(transferMode TransferMode) *StartParams {
  143. p.TransferMode = transferMode
  144. return &p
  145. }
  146. // WithStreamFormat trace data format to use. This only applies when using
  147. // ReturnAsStream transfer mode (defaults to json).
  148. func (p StartParams) WithStreamFormat(streamFormat StreamFormat) *StartParams {
  149. p.StreamFormat = streamFormat
  150. return &p
  151. }
  152. // WithStreamCompression compression format to use. This only applies when
  153. // using ReturnAsStream transfer mode (defaults to none).
  154. func (p StartParams) WithStreamCompression(streamCompression StreamCompression) *StartParams {
  155. p.StreamCompression = streamCompression
  156. return &p
  157. }
  158. // WithTraceConfig [no description].
  159. func (p StartParams) WithTraceConfig(traceConfig *TraceConfig) *StartParams {
  160. p.TraceConfig = traceConfig
  161. return &p
  162. }
  163. // WithPerfettoConfig base64-encoded serialized perfetto.protos.TraceConfig
  164. // protobuf message When specified, the parameters categories, options,
  165. // traceConfig are ignored.
  166. func (p StartParams) WithPerfettoConfig(perfettoConfig string) *StartParams {
  167. p.PerfettoConfig = perfettoConfig
  168. return &p
  169. }
  170. // WithTracingBackend backend type (defaults to auto).
  171. func (p StartParams) WithTracingBackend(tracingBackend Backend) *StartParams {
  172. p.TracingBackend = tracingBackend
  173. return &p
  174. }
  175. // Do executes Tracing.start against the provided context.
  176. func (p *StartParams) Do(ctx context.Context) (err error) {
  177. return cdp.Execute(ctx, CommandStart, p, nil)
  178. }
  179. // Command names.
  180. const (
  181. CommandEnd = "Tracing.end"
  182. CommandGetCategories = "Tracing.getCategories"
  183. CommandRecordClockSyncMarker = "Tracing.recordClockSyncMarker"
  184. CommandRequestMemoryDump = "Tracing.requestMemoryDump"
  185. CommandStart = "Tracing.start"
  186. )