Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Dokumentationsanwendung
Auf dieser Seite wird erläutert, wie Sie mit Cloud Shell Beispiele aus dem GitHub-Repository golang-samples/profiler herunterladen und ausführen. Sie können diese Beispiele auch außerhalb vonGoogle Cloudausführen. Weitere Konfigurationsschritte, die in diesem Fall erforderlich sind, finden Sie unter Profilerstellung für Code außerhalb von Google Cloud.
Durch Ausführen dieser Programme lassen sich schnell Profildaten erstellen, mithilfe derer Sie sich mit den Funktionen der Cloud Profiler-Oberfläche vertraut machen können.
Sie können auch Ihre Kopie dieser Beispiele bearbeiten, eine erneute Bereitstellung veranlassen und die Auswirkungen Ihrer Änderungen über die Cloud Profiler-Oberfläche analysieren.
Hinweise
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.
Klicken Sie oben auf der Google Cloud Console-Seite für Ihr Projekt auf Cloud Shell aktivieren:
Im unteren Bereich der Konsole wird ein neuer Frame für die Cloud Shell-Sitzung geöffnet, in dem zwei Meldungen und eine Eingabeaufforderung angezeigt werden. Die erste Meldung enthält das Google Cloud -Projekt für Ihre Cloud Shell-Sitzung. In der zweiten Meldung wird erklärt, wie Sie das Sitzungsprojekt ändern können.
Die Initialisierung der Shell-Sitzung kann einige Sekunden dauern.
Programm zur Profilerstellung abrufen
Rufen Sie in Cloud Shell das Paket mit den Go-Beispielen ab:
Das Beispiel profiler_quickstart ist zum Ausführen des Dienstes hello-profiler konfiguriert. Die Kurzanleitung zu Profiler verwendet dieses Beispiel.
So starten Sie hello-profiler:
Wechseln Sie in das Verzeichnis profiler_quickstart:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart
Starten Sie den Dienst mit dem folgenden Befehl:
gorunmain.go
Die Meldung profiler has started wird einige Sekunden nach dem Start des Dienstes in Ihrer Cloud Shell-Sitzung angezeigt. Bei jedem Hochladen eines Profils in Ihr Google Cloud-Projekt werden neue Meldungen angezeigt.
Drücken Sie Ctrl+C, um den Dienst zu beenden.
hotapp
Im Beispiel hotapp wird eine Endlosschleife verwendet, die zwei Funktionen und dann den Go-Planer aufruft. Das Beispiel unterstützt das Setzen des Flags -local_work. Wenn dieses Flag true ist, wird einzelnen Funktionen Arbeit in Form von Schleifen hinzugefügt. Diese Option ist standardmäßig auf false eingestellt.
So führen Sie das hotapp-Beispiel aus:
Wechseln Sie in das Verzeichnis hotapp:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
Starten Sie den Dienst mit dem folgenden Befehl:
gorunmain.go
Wenn Sie Profildaten generieren möchten, die mit den Daten in der Cloud Profiler-Dokumentation übereinstimmen, verwenden Sie den folgenden Aufruf:
Die Meldung profiler has started wird einige Sekunden nach dem Start des Dienstes in Ihrer Cloud Shell-Sitzung angezeigt. Bei jedem Hochladen eines Profils in Ihr Google Cloud-Projekt werden neue Meldungen angezeigt.
Drücken Sie Ctrl+C, um den Dienst zu beenden.
Im Abschnitt zum Vergleichen von Profilen wurden zwei verschiedene Deployments von docdemo-service verwendet. In einem Deployment wurden skew und version wie zuvor beschrieben festgelegt. Im zweiten Deployment wurde skew auf 25 und version auf 1.25.0 gesetzt.
Fehlerbehebung
Wenn Sie nach dem Start des Dienstes die Fehlermeldung erhalten, dass die Berechtigung verweigert wurde, finden Sie entsprechende Informationen unter Fehler bei der Google Cloud -Projektkonfiguration.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)."]]