Lingkungan fleksibel Python App Engine

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

Contoh kode

Python

Untuk informasi selengkapnya, lihat dokumentasi referensi Profiler Python API.

Untuk mengautentikasi 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 selanjutnya

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