Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Solicitação de documentação
Esta página fornece orientações sobre como usar o Cloud Shell para fazer o download de amostras do repositório golang-samples/profiler do GitHub e executá-las. Essas amostras também podem ser executadas fora doGoogle Cloud. Para esse caso, veja as etapas de configuração adicionais necessárias em Como criar perfis de aplicativos em execução fora do Google Cloud.
Se você optar por executar esses programas, poderá criar rapidamente dados de criação de perfil que podem ser usados para explorar os recursos da interface do Cloud Profiler.
Também é possível modificar sua cópia dessas amostras e reimplantar e analisar o impacto das alterações usando a interface do Cloud Profiler.
Antes de começar
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Na parte de cima da página do console do Google Cloud do projeto, clique em
Ativar o Cloud Shell:
Uma sessão do Cloud Shell é aberta dentro de um novo frame na parte inferior do console e exibe duas mensagens e um prompt de linha de comando. A primeira mensagem lista o projeto Google Cloud para sua sessão do Cloud Shell. A segunda mensagem informa como alterar o projeto da sessão.
A inicialização da sessão do shell pode levar alguns segundos:
Criar o perfil de um programa
No Cloud Shell, recupere o pacote de amostras do Go:
A recuperação do pacote leva algum tempo para ser concluída.
profiler_quickstart
A amostra profiler_quickstart está configurada para executar o serviço hello-profiler. O Guia de início rápido do Profiler usa essa amostra.
Para iniciar hello-profiler:
Altere para o diretório profiler_quickstart:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart
Inicie o serviço executando o seguinte comando:
gorunmain.go
A mensagem profiler has started é exibida na sessão do Cloud Shell alguns segundos após iniciar o serviço. Novas mensagens são exibidas sempre que um perfil é enviado para seu projeto do Google Cloud.
Para interromper o serviço, digite Ctrl-C.
hotapp
A amostra hotapp usa um loop infinito que chama duas funções e, em seguida, o programador do Go. A amostra é compatível com a configuração da sinalização -local_work. Quando essa sinalização é true, o trabalho, na forma de loops, é adicionado a funções individuais. Por padrão, essa sinalização é definida como false.
Para executar a amostra hotapp:
Altere para o diretório hotapp:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
Inicie o serviço executando o seguinte comando:
gorunmain.go
Se quiser gerar dados de perfil consistentes com os dados mostrados na documentação do Cloud Profiler, use a seguinte invocação:
A mensagem profiler has started é exibida na sessão do Cloud Shell alguns segundos após iniciar o serviço. Novas mensagens são exibidas sempre que um perfil é enviado para seu projeto do Google Cloud.
Para interromper o serviço, digite Ctrl-C.
A seção sobre comparação de perfis usou duas implantações diferentes do docdemo-service. Na primeira implantação, skew e version foram definidos conforme descrito anteriormente. Na segunda, o skew foi definido como 25, e o version foi definido como 1.25.0.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[],[],null,["# Documentation application\n=========================\n\nThis page provides guidance on using Cloud Shell to download\nand run samples from the GitHub\n[golang-samples/profiler](https://github.com/GoogleCloudPlatform/golang-samples/tree/master/profiler)\nrepository. You can also run these samples outside of\nGoogle Cloud. For the additional configuration steps required in this case,\nsee [Profiling applications running outside of Google Cloud](/profiler/docs/profiling-external).\n\nIf you choose to run these programs, you can quickly create profiling data that\nyou can use to explore the capabilities of the Cloud Profiler interface.\nYou can also modify your copy of these samples, then redeploy and analyze the\nimpact of your changes using the Cloud Profiler interface.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Cloud Profiler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com&redirect=https://console.cloud.google.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n\n\n Enable the Cloud Profiler API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com&redirect=https://console.cloud.google.com)\n\n\u003cbr /\u003e\n\nStart Cloud Shell\n-----------------\n\nAt the top of the Google Cloud console page for your project, click\n**Activate Cloud Shell**:\n\nA Cloud Shell session opens inside a new frame at the bottom of the\nconsole and displays two messages and a command-line prompt. The first\nmessage lists the Google Cloud project for your Cloud Shell\nsession. The second message tells you how to change the session project.\nIt can take a few seconds for the shell session to be initialized:\n\nGet a program to profile\n------------------------\n\nFrom Cloud Shell, retrieve the package of Go samples: \n\n git clone https://github.com/GoogleCloudPlatform/golang-samples.git\n\nThe package retrieval takes a few moments to complete.\n\n### profiler_quickstart\n\nThe sample `profiler_quickstart` is configured to run the `hello-profiler`\nservice. The [Profiler quickstart](/profiler/docs/measure-app-performance)\nuses this sample.\n\nTo start `hello-profiler`, do the following:\n\n1. Change to the `profiler_quickstart` directory:\n\n cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart\n\n2. Start the service by running the following command:\n\n go run main.go\n\nThe message `profiler has started` is displayed in your Cloud Shell\nsession a few seconds after you start the service. New messages are displayed\neach time a profile is uploaded to your Google Cloud\nproject.\n\nTo stop the service, enter Ctrl-C.\n\n### hotapp\n\nThe sample `hotapp` uses an infinite loop that calls two functions, and then\nthe Go scheduler. The sample supports setting the flag `-local_work`. When this\nflag is `true`, work, in the form of for loops, is added to individual\nfunctions. By default, this flag is set to `false`.\n\nTo run the `hotapp` sample, do the following:\n\n1. Change to the `hotapp` directory:\n\n cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp\n\n2. Start the service by running the following command:\n\n go run main.go\n\n If you wish to generate profile data that is consistent with\n data shown in the Cloud Profiler documentation,\n then use the following invocation: \n\n go run main.go -service=docdemo-service -local_work -skew=75 -version=1.75.0\n\nThe message `profiler has started` is displayed in your Cloud Shell\nsession a few seconds after you start the service. New messages are displayed\neach time a profile is uploaded to your Google Cloud\nproject.\n\nTo stop the service, enter Ctrl-C.\n\nThe section on [comparing profiles](/profiler/docs/comparing-profiles) used\ntwo different deployments of the `docdemo-service`. In one deployment, the\n`skew` and `version` were set as previously described. In the second\ndeployment, the `skew` was set to `25` and the `version` was set to `1.25.0`.\n\nTroubleshooting\n---------------\n\nIf you receive a permission denied error message after starting the service,\nsee\n[Errors with your Google Cloud project configuration](/profiler/docs/troubleshooting#errors-configuration)."]]