Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Como criar perfis de aplicativos em execução fora do Google Cloud
Nesta página, descrevemos como criar perfis de aplicativos em execução fora do Google Cloud.
Nesse cenário, o aplicativo e o agente do Cloud Profiler são executados fora do Google Cloud, mas você usa a interface do Cloud Profiler para analisar os dados de criação de perfil.
Usar a interface do Profiler para analisar dados de criação de perfil
requer um projeto do Google Cloud . O agente de criação de perfil executado em um local externo precisa ser capaz de enviar os perfis de volta para análise. Para ativar esse processo, é preciso:
Crie um projeto do Google Cloud e ative a API.
conseguir credenciais para o agente usar quando fizer o upload de perfis;
Configure o agente para usar as credenciais e o ID do projetoGoogle Cloud .
Criar um projeto Google Cloud
In the Google Cloud console, on the project selector page,
click Create project to begin creating a new
Google Cloud project.
conceder à conta de serviço o papelroles/cloudprofiler.agent para que ela possa gravar dados de criação de perfil. Por exemplo, usando
a Google Cloud CLI:
No computador em que o agente de criação de perfil será executado, faça o seguinte:
Coloque uma cópia do arquivo que contém a chave JSON que você acabou de criar.
Defina a variável de ambiente GOOGLE_APPLICATION_CREDENTIALS como o nome totalmente qualificado do arquivo que contém a chave JSON.
Essa variável precisa estar visível para o processo que executa o agente de criação de perfil. Portanto, se você usa um script ou Dockerfile para executar o processo, inclua a variável de ambiente neles.
Como usar o Application Default Credentials
Para que o agente use o Application Default Credentials, consiga as credenciais de acesso do usuário por meio de um fluxo da Web. Depois, coloque-as no local designado para a biblioteca do ADC.
Essas credenciais atuam como um proxy de uma conta de serviço.
Para usar as credenciais padrão do aplicativo, execute o seguinte comando da Google Cloud CLI:
gcloud auth application-default login
e siga as etapas mencionadas nele.
Como vincular o agente a um projeto do Google Cloud
O agente de criação de perfil precisa ser configurado para especificar o ID do seu projeto Google Cloud . Assim, ele pode fazer o upload de perfis.
O mecanismo desse processo depende da linguagem.
Especifique uma sinalização complementar de configuração do agente Java, cprof_project_id, na invocação correspondente:
-cprof_project_id=GCP_PROJECT_ID
Quando seu aplicativo não consegue acessar o servidor de metadados do Compute Engine, são exibidas mensagens semelhantes a esta:
Error making HTTP request for 169.254.169.254:80/computeMetadata/v1/instance/zone
Para interromper essas mensagens, adicione -cprof_zone_name=VALUE às sinalizações de configuração do agente e reinicie o aplicativo. Para esse cenário, substitua VALUE por uma string descritiva, como "teste".
[[["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-02 UTC."],[],[],null,["# Profiling applications running outside Google Cloud\n===================================================\n\nThis page describes how to profile applications running outside Google Cloud.\n\nIn this scenario, your application and the Cloud Profiler agent\nrun outside Google Cloud, but you use the Cloud Profiler\ninterface to analyze the profiling data.\n\nUsing the Profiler interface to analyze profiling data\nrequires a Google Cloud project. The profiling agent running elsewhere\nmust be able to send the profiles back for analysis. To enable this, you must:\n\n1. Create a Google Cloud project and enable the API.\n2. Obtain credentials for the profiling agent to use when uploading profiles.\n3. Configure the agent to use the credentials and the ID of the Google Cloud project.\n\nCreate a Google Cloud project\n-----------------------------\n\nIn the Google Cloud console, on the project selector page,\nclick **Create project** to begin creating a new\nGoogle Cloud project.\n\n[Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n\nEnable the Profiler API\n-----------------------\n\n1.\n\n\n Enable the required API.\n\n\n [Enable the API](https://console.cloud.google.com/flows/enableapi?apiid=cloudprofiler.googleapis.com)\n2. \u003cbr /\u003e\n\n If **API enabled** is displayed, then the API is already enabled. If not, click the **Enable** button.\n\n \u003cbr /\u003e\n\nObtain credentials for the agent\n--------------------------------\n\nThere are two ways to obtain credentials for the agent to use:\n\n- Let the agent use a service account with private-key authentication\n- Let the agent use application default credentials (ADC).\n\n### Using service accounts\n\nTo enable the agent to use a service account with private-key authentication,\nyou must:\n\n1. Create a service account. For example, using the Google Cloud CLI:\n\n gcloud iam service-accounts create \u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e --display-name \"my service account\"\n\n See [Creating a service account](/iam/docs/creating-managing-service-accounts#creating_a_service_account) for more information.\n2. Grant the service account the **roles/cloudprofiler.agent**\n [role](/profiler/docs/iam), so that it can write profiling data. For example, using\n the Google Cloud CLI:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eGCP_PROJECT_ID\u003c/span\u003e\u003c/var\u003e \\\n --member serviceAccount:\u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e@\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com \\\n --role roles/cloudprofiler.agent\n\n See [Granting roles to service accounts](/iam/docs/granting-roles-to-service-accounts#granting_access_to_a_service_account_for_a_resource) for more\n information.\n3. Create a JSON key for the service account. For example, using the\n Google Cloud CLI:\n\n gcloud iam service-accounts keys create \\\n ~/key.json \\\n --iam-account \u003cvar translate=\"no\"\u003eMY_SVC_ACCT_ID\u003c/var\u003e@\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e.iam.gserviceaccount.com\n\n See [Creating service account keys](/iam/docs/creating-managing-service-account-keys) for more\n information.\n4. On the machine where the profiling agent will run:\n\n 1. Put a copy of the file containing the JSON key you just created.\n 2. Set the environment variable `GOOGLE_APPLICATION_CREDENTIALS` to the fully qualified name of the file containing the JSON key. This environment variable must be visible to the process running the profiling agent, so if you use a script or Dockerfile to run the process, include the environment variable there.\n\n### Using application default credentials\n\nTo enable the agent to use application default credentials,\nyou obtain user-access credentials via a web flow\nand put them where the Application Default Credentials library expects them.\nThese credentials act as a proxy for a service account.\n\nTo use application default credentials, run the following Google Cloud CLI command: \n\n gcloud auth application-default login\n\nand follow the steps this command guides you through.\n\nLinking the agent to a Google Cloud project\n-------------------------------------------\n\nThe profiling agent must be configured to specify the ID of\nyour Google Cloud project so it can upload profiles.\nThe mechanism for doing this depends on the language. \n\n### Go\n\nSpecify an additional parameter, `ProjectID`, in the `profiler.Config`\nobject described in [Profiling Go applications](/profiler/docs/profiling-go#using-profiler): \n\n profiler.Config{ProjectID: \"\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e\", ...}\n\n### Java\n\nSpecify an additional [Java agent configuration](/profiler/docs/profiling-java#agent_configuration) flag,\n`cprof_project_id`, on the Java invocation: \n\n -cprof_project_id=\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eGCP_PROJECT_ID\u003c/span\u003e\u003c/var\u003e\n\nWhen your application isn't able to access the Compute Engine metadata\nserver, messages similar to the following are displayed: \n\n```sh\n Error making HTTP request for 169.254.169.254:80/computeMetadata/v1/instance/zone\n```\nTo stop these messages, add `-cprof_zone_name=`\u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e to your agent configuration flags and restart your application. For this scenario, replace \u003cvar translate=\"no\"\u003eVALUE\u003c/var\u003e with a descriptive string such as \"test\".\n\n\u003cbr /\u003e\n\n### Node.js\n\nSpecify an additional parameter, `projectID`, in the `serviceContext`\nobject described in [Profiling Node.js applications](/profiler/docs/profiling-nodejs#using-profiler): \n\n projectId: '\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e',\n serviceContext: {\n ...\n }\n\n### Python\n\nSpecify an additional parameter, `project_id`, in the `start`\nmethod call described in [Profiling Python applications](/profiler/docs/profiling-python#using-profiler): \n\n googlecloudprofiler.start(..., project_id='\u003cvar translate=\"no\"\u003eGCP_PROJECT_ID\u003c/var\u003e')\n\nWhat's next\n-----------\n\n- [Select the profiles to analyze](/profiler/docs/selecting-profiles)\n- [Interact with the flame graph](/profiler/docs/interacting-flame-graph)\n- [Filter the flame graph](/profiler/docs/filtering-profiles)\n- [Focus the flame graph](/profiler/docs/focusing-profiles)\n- [Compare profiles](/profiler/docs/comparing-profiles)"]]