Lingkungan standar Python App Engine

Menunjukkan cara melakukan inisialisasi Cloud Profiler dengan Python di lingkungan standar App Engine.

Contoh kode

Python

Untuk mengetahui informasi selengkapnya, lihat dokumentasi referensi Profiler Python API.

Untuk melakukan autentikasi ke Profiler, siapkan Kredensial Default Aplikasi. Untuk mengetahui informasi selengkapnya, baca Menyiapkan autentikasi untuk lingkungan pengembangan lokal.

import googlecloudprofiler

# Profiler initialization. It starts a daemon thread which continuously
# collects and uploads profiles. Best done as early as possible.
try:
    # service and service_version can be automatically inferred when
    # running on App Engine. project_id must be set if not running
    # on GCP.
    googlecloudprofiler.start(verbose=3)
except (ValueError, NotImplementedError) as exc:
    print(exc)  # Handle errors here

Langkah berikutnya

Untuk menelusuri dan memfilter contoh kode untuk produk Google Cloud lainnya, lihat Google Cloud browser contoh.