Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Aplikasi dokumentasi
Halaman ini memberikan panduan tentang cara menggunakan Cloud Shell untuk mendownload dan menjalankan contoh dari repositori golang-samples/profiler GitHub. Anda juga dapat menjalankan contoh ini di luar
Google Cloud. Untuk langkah-langkah konfigurasi tambahan yang diperlukan dalam kasus ini, lihat Membuat profil aplikasi yang berjalan di luar Google Cloud.
Jika memilih untuk menjalankan program ini, Anda dapat membuat data pembuatan profil dengan cepat yang dapat digunakan untuk menjelajahi kemampuan antarmuka Cloud Profiler.
Anda juga dapat mengubah salinan contoh ini, lalu men-deploy ulang dan menganalisis dampak perubahan Anda menggunakan antarmuka Cloud Profiler.
Sebelum memulai
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.
Di bagian atas halaman konsol untuk project Anda, klik
Activate Cloud Shell: Google Cloud
Sesi Cloud Shell akan terbuka di dalam frame baru di bagian bawah konsol dan menampilkan dua pesan serta perintah command line. Pesan pertama mencantumkan project untuk sesi Cloud Shell Anda. Google Cloud Pesan kedua memberi tahu Anda cara mengubah project sesi.
Perlu waktu beberapa detik hingga sesi shell diinisialisasi:
Pengambilan paket memerlukan waktu beberapa saat hingga selesai.
profiler_quickstart
Contoh profiler_quickstart dikonfigurasi untuk menjalankan layanan hello-profiler. Panduan memulai profiler
menggunakan contoh ini.
Untuk memulai hello-profiler, lakukan hal berikut:
Ubah ke direktori profiler_quickstart:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/profiler_quickstart
Mulai layanan dengan menjalankan perintah berikut:
gorunmain.go
Pesan profiler has started ditampilkan di sesi Cloud Shell
beberapa detik setelah Anda memulai layanan. Pesan baru ditampilkan setiap kali profil diupload ke project Google CloudAnda.
Untuk menghentikan layanan, masukkan Ctrl-C.
hotapp
Contoh hotapp menggunakan loop tak terbatas yang memanggil dua fungsi, lalu penjadwal Go. Contoh ini mendukung setelan flag -local_work. Jika tanda ini adalah true, pekerjaan, dalam bentuk loop for, ditambahkan ke setiap fungsi. Secara default, tanda ini disetel ke false.
Untuk menjalankan contoh hotapp, lakukan hal berikut:
Ubah ke direktori hotapp:
cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
Mulai layanan dengan menjalankan perintah berikut:
gorunmain.go
Jika Anda ingin membuat data profil yang konsisten dengan
data yang ditampilkan dalam dokumentasi Cloud Profiler,
gunakan pemanggilan berikut:
Pesan profiler has started ditampilkan di sesi Cloud Shell
beberapa detik setelah Anda memulai layanan. Pesan baru ditampilkan setiap kali profil diupload ke project Google CloudAnda.
Untuk menghentikan layanan, masukkan Ctrl-C.
Bagian tentang membandingkan profil menggunakan
dua deployment docdemo-service yang berbeda. Dalam satu deployment, skew dan version ditetapkan seperti yang dijelaskan sebelumnya. Dalam deployment kedua, skew disetel ke 25 dan version disetel ke 1.25.0.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-02 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)."]]