File: tracing.go

package info (click to toggle)
golang-github-chromedp-cdproto 0.0~git20230109.6b041c6-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 4,584 kB
  • sloc: makefile: 2
file content (216 lines) | stat: -rw-r--r-- 7,989 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Package tracing provides the Chrome DevTools Protocol
// commands, types, and events for the Tracing domain.
//
// Generated by the cdproto-gen command.
package tracing

// Code generated by cdproto-gen. DO NOT EDIT.

import (
	"context"

	"github.com/chromedp/cdproto/cdp"
)

// EndParams stop trace events collection.
type EndParams struct{}

// End stop trace events collection.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-end
func End() *EndParams {
	return &EndParams{}
}

// Do executes Tracing.end against the provided context.
func (p *EndParams) Do(ctx context.Context) (err error) {
	return cdp.Execute(ctx, CommandEnd, nil, nil)
}

// GetCategoriesParams gets supported tracing categories.
type GetCategoriesParams struct{}

// GetCategories gets supported tracing categories.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-getCategories
func GetCategories() *GetCategoriesParams {
	return &GetCategoriesParams{}
}

// GetCategoriesReturns return values.
type GetCategoriesReturns struct {
	Categories []string `json:"categories,omitempty"` // A list of supported tracing categories.
}

// Do executes Tracing.getCategories against the provided context.
//
// returns:
//
//	categories - A list of supported tracing categories.
func (p *GetCategoriesParams) Do(ctx context.Context) (categories []string, err error) {
	// execute
	var res GetCategoriesReturns
	err = cdp.Execute(ctx, CommandGetCategories, nil, &res)
	if err != nil {
		return nil, err
	}

	return res.Categories, nil
}

// RecordClockSyncMarkerParams record a clock sync marker in the trace.
type RecordClockSyncMarkerParams struct {
	SyncID string `json:"syncId"` // The ID of this clock sync marker
}

// RecordClockSyncMarker record a clock sync marker in the trace.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-recordClockSyncMarker
//
// parameters:
//
//	syncID - The ID of this clock sync marker
func RecordClockSyncMarker(syncID string) *RecordClockSyncMarkerParams {
	return &RecordClockSyncMarkerParams{
		SyncID: syncID,
	}
}

// Do executes Tracing.recordClockSyncMarker against the provided context.
func (p *RecordClockSyncMarkerParams) Do(ctx context.Context) (err error) {
	return cdp.Execute(ctx, CommandRecordClockSyncMarker, p, nil)
}

// RequestMemoryDumpParams request a global memory dump.
type RequestMemoryDumpParams struct {
	Deterministic bool                    `json:"deterministic,omitempty"` // Enables more deterministic results by forcing garbage collection
	LevelOfDetail MemoryDumpLevelOfDetail `json:"levelOfDetail,omitempty"` // Specifies level of details in memory dump. Defaults to "detailed".
}

// RequestMemoryDump request a global memory dump.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-requestMemoryDump
//
// parameters:
func RequestMemoryDump() *RequestMemoryDumpParams {
	return &RequestMemoryDumpParams{}
}

// WithDeterministic enables more deterministic results by forcing garbage
// collection.
func (p RequestMemoryDumpParams) WithDeterministic(deterministic bool) *RequestMemoryDumpParams {
	p.Deterministic = deterministic
	return &p
}

// WithLevelOfDetail specifies level of details in memory dump. Defaults to
// "detailed".
func (p RequestMemoryDumpParams) WithLevelOfDetail(levelOfDetail MemoryDumpLevelOfDetail) *RequestMemoryDumpParams {
	p.LevelOfDetail = levelOfDetail
	return &p
}

// RequestMemoryDumpReturns return values.
type RequestMemoryDumpReturns struct {
	DumpGUID string `json:"dumpGuid,omitempty"` // GUID of the resulting global memory dump.
	Success  bool   `json:"success,omitempty"`  // True iff the global memory dump succeeded.
}

// Do executes Tracing.requestMemoryDump against the provided context.
//
// returns:
//
//	dumpGUID - GUID of the resulting global memory dump.
//	success - True iff the global memory dump succeeded.
func (p *RequestMemoryDumpParams) Do(ctx context.Context) (dumpGUID string, success bool, err error) {
	// execute
	var res RequestMemoryDumpReturns
	err = cdp.Execute(ctx, CommandRequestMemoryDump, p, &res)
	if err != nil {
		return "", false, err
	}

	return res.DumpGUID, res.Success, nil
}

// StartParams start trace events collection.
type StartParams struct {
	BufferUsageReportingInterval float64           `json:"bufferUsageReportingInterval,omitempty"` // If set, the agent will issue bufferUsage events at this interval, specified in milliseconds
	TransferMode                 TransferMode      `json:"transferMode,omitempty"`                 // Whether to report trace events as series of dataCollected events or to save trace to a stream (defaults to ReportEvents).
	StreamFormat                 StreamFormat      `json:"streamFormat,omitempty"`                 // Trace data format to use. This only applies when using ReturnAsStream transfer mode (defaults to json).
	StreamCompression            StreamCompression `json:"streamCompression,omitempty"`            // Compression format to use. This only applies when using ReturnAsStream transfer mode (defaults to none)
	TraceConfig                  *TraceConfig      `json:"traceConfig,omitempty"`
	PerfettoConfig               string            `json:"perfettoConfig,omitempty"` // Base64-encoded serialized perfetto.protos.TraceConfig protobuf message When specified, the parameters categories, options, traceConfig are ignored.
	TracingBackend               Backend           `json:"tracingBackend,omitempty"` // Backend type (defaults to auto)
}

// Start start trace events collection.
//
// See: https://chromedevtools.github.io/devtools-protocol/tot/Tracing#method-start
//
// parameters:
func Start() *StartParams {
	return &StartParams{}
}

// WithBufferUsageReportingInterval if set, the agent will issue bufferUsage
// events at this interval, specified in milliseconds.
func (p StartParams) WithBufferUsageReportingInterval(bufferUsageReportingInterval float64) *StartParams {
	p.BufferUsageReportingInterval = bufferUsageReportingInterval
	return &p
}

// WithTransferMode whether to report trace events as series of dataCollected
// events or to save trace to a stream (defaults to ReportEvents).
func (p StartParams) WithTransferMode(transferMode TransferMode) *StartParams {
	p.TransferMode = transferMode
	return &p
}

// WithStreamFormat trace data format to use. This only applies when using
// ReturnAsStream transfer mode (defaults to json).
func (p StartParams) WithStreamFormat(streamFormat StreamFormat) *StartParams {
	p.StreamFormat = streamFormat
	return &p
}

// WithStreamCompression compression format to use. This only applies when
// using ReturnAsStream transfer mode (defaults to none).
func (p StartParams) WithStreamCompression(streamCompression StreamCompression) *StartParams {
	p.StreamCompression = streamCompression
	return &p
}

// WithTraceConfig [no description].
func (p StartParams) WithTraceConfig(traceConfig *TraceConfig) *StartParams {
	p.TraceConfig = traceConfig
	return &p
}

// WithPerfettoConfig base64-encoded serialized perfetto.protos.TraceConfig
// protobuf message When specified, the parameters categories, options,
// traceConfig are ignored.
func (p StartParams) WithPerfettoConfig(perfettoConfig string) *StartParams {
	p.PerfettoConfig = perfettoConfig
	return &p
}

// WithTracingBackend backend type (defaults to auto).
func (p StartParams) WithTracingBackend(tracingBackend Backend) *StartParams {
	p.TracingBackend = tracingBackend
	return &p
}

// Do executes Tracing.start against the provided context.
func (p *StartParams) Do(ctx context.Context) (err error) {
	return cdp.Execute(ctx, CommandStart, p, nil)
}

// Command names.
const (
	CommandEnd                   = "Tracing.end"
	CommandGetCategories         = "Tracing.getCategories"
	CommandRecordClockSyncMarker = "Tracing.recordClockSyncMarker"
	CommandRequestMemoryDump     = "Tracing.requestMemoryDump"
	CommandStart                 = "Tracing.start"
)