Cloud Profiler API v2 - Package cloud.google.com/go/cloudprofiler/apiv2 (v0.4.6)

Beta

This library is covered by thePre-GA Offerings Terms of the Terms of Service. Pre-GA libraries might have limited support, and changes to pre-GA libraries might not be compatible with other pre-GA versions. For more information, see thelaunch stage descriptions.

Note: To get more information about this package, such as access to older versions, viewthis package on pkg.go.dev.

Package cloudprofiler is an auto-generated package for theCloud Profiler API.

Manages continuous profiling information.

NOTE:Thispackageisinbeta.Itisnotstable,andmaybesubjecttochanges.

General documentation

For information that is relevant for all client libraries please referencehttps://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on thispage includes:

Example usage

To get started with this package, create a client.

// go get cloud.google.com/go/cloudprofiler/apiv2@latestctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()

The client will use your default application credentials. Clients should be reused instead of created as needed.The methods of Client are safe for concurrent use by multiple goroutines.The returned client must be Closed when it is done being used.

Using the Client

The following is an example of making an API call with the newly created client, mentioned above.

req:=&cloudprofilerpb.CreateOfflineProfileRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#CreateOfflineProfileRequest.}resp,err:=c.CreateOfflineProfile(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp

Use of Context

The ctx passed to NewProfilerClient is used for authentication requests andfor creating the underlying connection, but is not used for subsequent calls.Individual methods on the client use the ctx given to them.

To close the open connection, use the Close() method.

Functions

func DefaultAuthScopes

funcDefaultAuthScopes()[]string

DefaultAuthScopes reports the default set of authentication scopes to use with this package.

ExportCallOptions

typeExportCallOptionsstruct{ListProfiles[]gax.CallOption}

ExportCallOptions contains the retry settings for each method of ExportClient.

ExportClient

typeExportClientstruct{// The call options for this service.CallOptions*ExportCallOptions// contains filtered or unexported fields}

ExportClient is a client for interacting with Cloud Profiler API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Service allows existing Cloud Profiler customers to export their profile dataout of Google Cloud.

func NewExportClient

funcNewExportClient(ctxcontext.Context,opts...option.ClientOption)(*ExportClient,error)

NewExportClient creates a new export service client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.

Service allows existing Cloud Profiler customers to export their profile dataout of Google Cloud.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewExportClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewExportRESTClient

funcNewExportRESTClient(ctxcontext.Context,opts...option.ClientOption)(*ExportClient,error)

NewExportRESTClient creates a new export service rest client.

Service allows existing Cloud Profiler customers to export their profile dataout of Google Cloud.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewExportRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*ExportClient) Close

func(c*ExportClient)Close()error

Close closes the connection to the API service. The user should invoke this whenthe client is no longer required.

func (*ExportClient) Connection (deprecated)

func(c*ExportClient)Connection()*grpc.ClientConn

Connection returns a connection to the API service.

Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.

func (*ExportClient) ListProfiles

ListProfiles lists profiles which have been collected so far and for which the callerhas permission to view.

Examples

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2"cloudprofilerpb"cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb""google.golang.org/api/iterator")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewExportClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&cloudprofilerpb.ListProfilesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#ListProfilesRequest.}it:=c.ListProfiles(ctx,req)for{resp,err:=it.Next()iferr==iterator.Done{break}iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp// If you need to access the underlying RPC response,// you can do so by casting the `Response` as below.// Otherwise, remove this line. Only populated after// first call to Next(). Not safe for concurrent access._=it.Response.(*cloudprofilerpb.ListProfilesResponse)}}
all
packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2"cloudprofilerpb"cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewExportClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&cloudprofilerpb.ListProfilesRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#ListProfilesRequest.}forresp,err:=rangec.ListProfiles(ctx,req).All(){iferr!=nil{// TODO: Handle error and break/return/continue. Iteration will stop after any error.}// TODO: Use resp._=resp}}

ProfileIterator

typeProfileIteratorstruct{// Response is the raw response for the current page.// It must be cast to the RPC response type.// Calling Next() or InternalFetch() updates this value.Responseinterface{}// InternalFetch is for use by the Google Cloud Libraries only.// It is not part of the stable interface of this package.//// InternalFetch returns results from a single call to the underlying RPC.// The number of results is no greater than pageSize.// If there are no more results, nextPageToken is empty and err is nil.InternalFetchfunc(pageSizeint,pageTokenstring)(results[]*cloudprofilerpb.Profile,nextPageTokenstring,errerror)// contains filtered or unexported fields}

ProfileIterator manages a stream of *cloudprofilerpb.Profile.

func (*ProfileIterator) All

func(it*ProfileIterator)All()iter.Seq2[*cloudprofilerpb.Profile,error]

All returns an iterator. If an error is returned by the iterator, theiterator will stop after that iteration.

func (*ProfileIterator) Next

Next returns the next result. Its second return value is iterator.Done if there are no moreresults. Once Next returns Done, all subsequent calls will return Done.

func (*ProfileIterator) PageInfo

func(it*ProfileIterator)PageInfo()*iterator.PageInfo

PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.

ProfilerCallOptions

typeProfilerCallOptionsstruct{CreateProfile[]gax.CallOptionCreateOfflineProfile[]gax.CallOptionUpdateProfile[]gax.CallOption}

ProfilerCallOptions contains the retry settings for each method of ProfilerClient.

ProfilerClient

typeProfilerClientstruct{// The call options for this service.CallOptions*ProfilerCallOptions// contains filtered or unexported fields}

ProfilerClient is a client for interacting with Cloud Profiler API.Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.

Manage the collection of continuous profiling data provided by profilingagents running in the cloud or by an offline provider of profiling data.

The APIs listed in this service are intended for use within our profileragents only.

func NewProfilerClient

funcNewProfilerClient(ctxcontext.Context,opts...option.ClientOption)(*ProfilerClient,error)

NewProfilerClient creates a new profiler service client based on gRPC.The returned client must be Closed when it is done being used to clean up its underlying connections.

Manage the collection of continuous profiling data provided by profilingagents running in the cloud or by an offline provider of profiling data.

The APIs listed in this service are intended for use within our profileragents only.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func NewProfilerRESTClient

funcNewProfilerRESTClient(ctxcontext.Context,opts...option.ClientOption)(*ProfilerClient,error)

NewProfilerRESTClient creates a new profiler service rest client.

Manage the collection of continuous profiling data provided by profilingagents running in the cloud or by an offline provider of profiling data.

The APIs listed in this service are intended for use within our profileragents only.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerRESTClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()// TODO: Use client._=c}

func (*ProfilerClient) Close

func(c*ProfilerClient)Close()error

Close closes the connection to the API service. The user should invoke this whenthe client is no longer required.

func (*ProfilerClient) Connection (deprecated)

func(c*ProfilerClient)Connection()*grpc.ClientConn

Connection returns a connection to the API service.

Deprecated: Connections are now pooled so this method does not alwaysreturn the same resource.

func (*ProfilerClient) CreateOfflineProfile

CreateOfflineProfile createOfflineProfile creates a new profile resource in the offlinemode. The client provides the profile to create along with the profilebytes, the server records it.

Direct use of this API is discouraged, please use a supportedprofileragent (athttps://cloud.google.com/profiler/docs/about-profiler#profiling_agent)instead for profile collection.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2"cloudprofilerpb"cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&cloudprofilerpb.CreateOfflineProfileRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#CreateOfflineProfileRequest.}resp,err:=c.CreateOfflineProfile(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*ProfilerClient) CreateProfile

CreateProfile createProfile creates a new profile resource in the online mode.

Direct use of this API is discouraged, please use a supportedprofileragent (athttps://cloud.google.com/profiler/docs/about-profiler#profiling_agent)instead for profile collection.

The server ensures that the new profiles are created at a constant rate perdeployment, so the creation request may hang for some time until the nextprofile session is available.

The request may fail with ABORTED error if the creation is not availablewithin ~1m, the response will indicate the duration of the backoff theclient should take before attempting creating a profile again. The backoffduration is returned in google.rpc.RetryInfo extension on the responsestatus. To a gRPC client, the extension will be return as abinary-serialized proto in the trailing metadata item named“google.rpc.retryinfo-bin”.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2"cloudprofilerpb"cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&cloudprofilerpb.CreateProfileRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#CreateProfileRequest.}resp,err:=c.CreateProfile(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

func (*ProfilerClient) UpdateProfile

UpdateProfile updateProfile updates the profile bytes and labels on the profile resourcecreated in the online mode. Updating the bytes for profiles created in theoffline mode is currently not supported: the profile content must beprovided at the time of the profile creation.

Direct use of this API is discouraged, please use a supportedprofileragent (athttps://cloud.google.com/profiler/docs/about-profiler#profiling_agent)instead for profile collection.

Example

packagemainimport("context"cloudprofiler"cloud.google.com/go/cloudprofiler/apiv2"cloudprofilerpb"cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb")funcmain(){ctx:=context.Background()// This snippet has been automatically generated and should be regarded as a code template only.// It will require modifications to work:// - It may require correct/in-range values for request initialization.// - It may require specifying regional endpoints when creating the service client as shown in://   https://pkg.go.dev/cloud.google.com/go#hdr-Client_Optionsc,err:=cloudprofiler.NewProfilerClient(ctx)iferr!=nil{// TODO: Handle error.}deferc.Close()req:=&cloudprofilerpb.UpdateProfileRequest{// TODO: Fill request struct fields.// See https://pkg.go.dev/cloud.google.com/go/cloudprofiler/apiv2/cloudprofilerpb#UpdateProfileRequest.}resp,err:=c.UpdateProfile(ctx,req)iferr!=nil{// TODO: Handle error.}// TODO: Use resp._=resp}

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.