PollAndLogSerialPort polls serial port 2 of the given GCE instance and
returns when the finishString appears in the serial output of the instance,
or when the context times out. It logs the serial output of the instance
using the specified log function and returns the serial output in the first
return value.
StartInstance starts a GCE Instance with configs specified by inst,
and which runs the startup script specified in inst. If image project
is not specified, it defaults to "debian-cloud". If image family is
not specified, it defaults to "debian-11".
HasFunction returns nil if the function is present, or, if the function is
not present, and error providing more details why the function is not
present.
HasFunctionInFile returns nil if function is present in the specified file, and an
error if the function/file combination is not present in the profile.
HasSourceFile returns nil if the file (or file where the end of the file path
matches the filename) is present in the profile. Or, if the filename is not
present, an error is returned.
QueryProfilesWithZone retrieves profiles of a specific type, from a specific
time range, in a specified zone, associated with a particular service
and project.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eThis page provides documentation for the \u003ccode\u003eproftest\u003c/code\u003e package, focusing on testing profiling agents within Google Cloud environments.\u003c/p\u003e\n"],["\u003cp\u003eThe latest version of the \u003ccode\u003eproftest\u003c/code\u003e package is 0.4.2, and links to older versions, from 0.1.2 to 0.4.1, are also accessible for users.\u003c/p\u003e\n"],["\u003cp\u003eThe package includes functionalities for testing agents on GCE (Google Compute Engine) and GKE (Google Kubernetes Engine), using \u003ccode\u003eGCETestRunner\u003c/code\u003e and \u003ccode\u003eGKETestRunner\u003c/code\u003e, respectively.\u003c/p\u003e\n"],["\u003cp\u003eKey features include the ability to start and delete instances/clusters, check serial output for backoffs, and query profiles using the \u003ccode\u003eTestRunner\u003c/code\u003e struct and it's functions.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eProfileResponse\u003c/code\u003e type allows validation of retrieved profiles, such as checking for the presence of specific functions or files using it's different methods.\u003c/p\u003e\n"]]],[],null,["# Package cloud.google.com/go/profiler/proftest (v0.4.2)\n\nVersion latestkeyboard_arrow_down\n\n- [0.4.2 (latest)](/go/docs/reference/cloud.google.com/go/profiler/latest/proftest)\n- [0.4.1](/go/docs/reference/cloud.google.com/go/profiler/0.4.1/proftest)\n- [0.3.1](/go/docs/reference/cloud.google.com/go/profiler/0.3.1/proftest)\n- [0.2.0](/go/docs/reference/cloud.google.com/go/profiler/0.2.0/proftest)\n- [0.1.2](/go/docs/reference/cloud.google.com/go/profiler/0.1.2/proftest) \n**Note:** To get more information about this package, such as access to older versions, view [this package on pkg.go.dev](https://pkg.go.dev/cloud.google.com/go/profiler/proftest). \n\nVariables\n---------\n\n### BaseStartupTmpl\n\n var BaseStartupTmpl = https://pkg.go.dev/text/template.https://pkg.go.dev/text/template#Must(https://pkg.go.dev/text/template.https://pkg.go.dev/text/template#New(\"startupScript\").Parse(\"\" /* 641 byte string literal not displayed */,\n ))\n\nBaseStartupTmpl is the common part of the startup script that\ncan be shared by multiple tests. \n\nFunctions\n---------\n\n### func CheckSerialOutputForBackoffs\n\n func CheckSerialOutputForBackoffs(output https://pkg.go.dev/builtin#string, numBenchmarks https://pkg.go.dev/builtin#int, serverBackoffSubstring, createProfileSubstring, benchmarkNumPrefix https://pkg.go.dev/builtin#string) https://pkg.go.dev/builtin#error\n\nCheckSerialOutputForBackoffs parses serial port output, and validates that\nserver-specified backoffs were respected by the agent. \n\nClusterConfig\n-------------\n\n type ClusterConfig struct {\n \tProjectID https://pkg.go.dev/builtin#string\n \tZone https://pkg.go.dev/builtin#string\n \tClusterName https://pkg.go.dev/builtin#string\n \tPodName https://pkg.go.dev/builtin#string\n \tImageSourceName https://pkg.go.dev/builtin#string\n \tImageName https://pkg.go.dev/builtin#string\n \tBucket https://pkg.go.dev/builtin#string\n \tDockerfile https://pkg.go.dev/builtin#string\n }\n\nClusterConfig is configuration for starting single GKE cluster for profiling\nagent test case. \n\nGCETestRunner\n-------------\n\n type GCETestRunner struct {\n \t#cloud_google_com_go_profiler_proftest_TestRunner\n \tComputeService *https://pkg.go.dev/google.golang.org/api/compute/v1.https://pkg.go.dev/google.golang.org/api/compute/v1#Service\n }\n\nGCETestRunner supports testing a profiling agent on GCE. \n\n### func (\\*GCETestRunner) DeleteInstance\n\n func (tr *#cloud_google_com_go_profiler_proftest_GCETestRunner) DeleteInstance(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, inst *#cloud_google_com_go_profiler_proftest_InstanceConfig) https://pkg.go.dev/builtin#error\n\nDeleteInstance deletes an instance with project id, name, and zone matched\nby inst. \n\n### func (\\*GCETestRunner) PollAndLogSerialPort\n\n func (tr *#cloud_google_com_go_profiler_proftest_GCETestRunner) PollAndLogSerialPort(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, inst *#cloud_google_com_go_profiler_proftest_InstanceConfig, finishString, errorString https://pkg.go.dev/builtin#string, logf func(https://pkg.go.dev/builtin#string, ...interface{})) (https://pkg.go.dev/builtin#string, https://pkg.go.dev/builtin#error)\n\nPollAndLogSerialPort polls serial port 2 of the given GCE instance and\nreturns when the finishString appears in the serial output of the instance,\nor when the context times out. It logs the serial output of the instance\nusing the specified log function and returns the serial output in the first\nreturn value. \n\n### func (\\*GCETestRunner) StartInstance\n\n func (tr *#cloud_google_com_go_profiler_proftest_GCETestRunner) StartInstance(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, inst *#cloud_google_com_go_profiler_proftest_InstanceConfig) https://pkg.go.dev/builtin#error\n\nStartInstance starts a GCE Instance with configs specified by inst,\nand which runs the startup script specified in inst. If image project\nis not specified, it defaults to \"debian-cloud\". If image family is\nnot specified, it defaults to \"debian-11\". \n\nGKETestRunner\n-------------\n\n type GKETestRunner struct {\n \t#cloud_google_com_go_profiler_proftest_TestRunner\n \tContainerService *https://pkg.go.dev/google.golang.org/api/container/v1.https://pkg.go.dev/google.golang.org/api/container/v1#Service\n \tStorageClient */go/docs/reference/cloud.google.com/go/storage/latest./go/docs/reference/cloud.google.com/go/storage/latest#cloud_google_com_go_storage_Client\n \tDockerfile https://pkg.go.dev/builtin#string\n }\n\nGKETestRunner supports testing a profiling agent on GKE. \n\n### func (\\*GKETestRunner) DeleteClusterAndImage\n\n func (tr *#cloud_google_com_go_profiler_proftest_GKETestRunner) DeleteClusterAndImage(ctx https://pkg.go.dev/context.https://pkg.go.dev/context#Context, cfg *#cloud_google_com_go_profiler_proftest_ClusterConfig) []https://pkg.go.dev/builtin#error\n\nDeleteClusterAndImage deletes cluster and images used to create cluster. \n\nInstanceConfig\n--------------\n\n type InstanceConfig struct {\n \tProjectID https://pkg.go.dev/builtin#string\n \tZone https://pkg.go.dev/builtin#string\n \tName https://pkg.go.dev/builtin#string\n \tStartupScript https://pkg.go.dev/builtin#string\n \tMachineType https://pkg.go.dev/builtin#string\n \tImageProject https://pkg.go.dev/builtin#string\n \tImageFamily https://pkg.go.dev/builtin#string\n \tScopes []https://pkg.go.dev/builtin#string\n }\n\nInstanceConfig is configuration for starting single GCE instance for\nprofiling agent test case. \n\nProfileData\n-----------\n\n type ProfileData struct {\n \tSamples []https://pkg.go.dev/builtin#int32 `json:\"samples\"`\n \tSampleMetrics interface{} `json:\"sampleMetrics\"`\n \tDefaultMetricType https://pkg.go.dev/builtin#string `json:\"defaultMetricType\"`\n \tTreeNodes interface{} `json:\"treeNodes\"`\n \tFunctions functionArray `json:\"functions\"`\n \tSourceFiles sourceFileArray `json:\"sourceFiles\"`\n }\n\nProfileData has data of a single profile. \n\nProfileResponse\n---------------\n\n type ProfileResponse struct {\n \tProfile #cloud_google_com_go_profiler_proftest_ProfileData `json:\"profile\"`\n \tNumProfiles https://pkg.go.dev/builtin#int32 `json:\"numProfiles\"`\n \tDeployments []interface{} `json:\"deployments\"`\n }\n\nProfileResponse contains the response produced when querying profile server. \n\n### func (\\*ProfileResponse) CheckNonEmpty\n\n func (pr *#cloud_google_com_go_profiler_proftest_ProfileResponse) CheckNonEmpty() https://pkg.go.dev/builtin#error\n\nCheckNonEmpty returns nil if the profile has a profiles and deployments\nassociated. Otherwise, returns a desciptive error. \n\n### func (\\*ProfileResponse) HasFunction\n\n func (pr *#cloud_google_com_go_profiler_proftest_ProfileResponse) HasFunction(functionName https://pkg.go.dev/builtin#string) https://pkg.go.dev/builtin#error\n\nHasFunction returns nil if the function is present, or, if the function is\nnot present, and error providing more details why the function is not\npresent. \n\n### func (\\*ProfileResponse) HasFunctionInFile\n\n func (pr *#cloud_google_com_go_profiler_proftest_ProfileResponse) HasFunctionInFile(functionName https://pkg.go.dev/builtin#string, filename https://pkg.go.dev/builtin#string) https://pkg.go.dev/builtin#error\n\nHasFunctionInFile returns nil if function is present in the specified file, and an\nerror if the function/file combination is not present in the profile. \n\n### func (\\*ProfileResponse) HasSourceFile\n\n func (pr *#cloud_google_com_go_profiler_proftest_ProfileResponse) HasSourceFile(filename https://pkg.go.dev/builtin#string) https://pkg.go.dev/builtin#error\n\nHasSourceFile returns nil if the file (or file where the end of the file path\nmatches the filename) is present in the profile. Or, if the filename is not\npresent, an error is returned. \n\nTestRunner\n----------\n\n type TestRunner struct {\n \tClient *https://pkg.go.dev/net/http.https://pkg.go.dev/net/http#Client\n }\n\nTestRunner has common elements used for testing profiling agents on a range\nof environments. \n\n### func (\\*TestRunner) QueryProfiles\n\n func (tr *#cloud_google_com_go_profiler_proftest_TestRunner) QueryProfiles(projectID, service, startTime, endTime, profileType https://pkg.go.dev/builtin#string) (#cloud_google_com_go_profiler_proftest_ProfileResponse, https://pkg.go.dev/builtin#error)\n\nQueryProfiles retrieves profiles of a specific type, from a specific time\nrange, associated with a particular service and project. \n\n### func (\\*TestRunner) QueryProfilesWithZone\n\n func (tr *#cloud_google_com_go_profiler_proftest_TestRunner) QueryProfilesWithZone(projectID, service, startTime, endTime, profileType, zone https://pkg.go.dev/builtin#string) (#cloud_google_com_go_profiler_proftest_ProfileResponse, https://pkg.go.dev/builtin#error)\n\nQueryProfilesWithZone retrieves profiles of a specific type, from a specific\ntime range, in a specified zone, associated with a particular service\nand project."]]