App Engine-Standardumgebung für Python

Erläutert, wie Sie Cloud Profiler mit Python in der App Engine-Standardumgebung initialisieren.

Codebeispiel

Python

Weitere Informationen finden Sie in der Referenzdokumentation zur Profiler API für Python.

Richten Sie zur Authentifizierung bei Profiler Standardanmeldedaten für Anwendungen ein. Weitere Informationen finden Sie unter Authentifizierung für eine lokale Entwicklungsumgebung einrichten.

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

Nächste Schritte

Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.