Profildaten herunterladen
In diesem Dokument wird beschrieben, wie Sie Ihre Profildaten auf Ihr lokales System herunterladen und wie Sie Profildaten programmatisch mithilfe einer Go-Anwendung abrufen können.
Profile mit der Google Cloud Console herunterladen
Wenn Sie das im Flame-Diagramm angezeigte Profil herunterladen möchten, klicken Sie auf Herunterladen get_app.
Profiler verwendet für die heruntergeladene Datei die folgende Namenskonvention:
profiler_[SERVICE_NAME]_[PROFILE_TYPE]_[FROM_DATE]_[TO_DATE]_[ZONE]_[VERSION].pb.gz
Beispielausdruck:
SERVICE_NAME
enthält Ihre Auswahl für den Service (Dienst).PROFILE_TYPE
enthält Ihre Auswahl für den Profile type (Profiltyp).FROM_DATE
undTO_DATE
enthalten Ihre Zeitraumangaben.ZONE
enthält Ihre Auswahl für Zone.VERSION
enthält Ihre Auswahl für Version.
Beispiel: profiler_docdemo-service_HEAP_2018-04-22T20_25_31Z_2018-05-22T20_25_31Z_us-east1-c.pb.gz
Profile programmatisch herunterladen
Verwenden Sie zum Abrufen von Profildaten die API-Methode ListProfiles
. Das folgende Beispielprogramm in Go veranschaulicht die Verwendung dieser API.
Das Beispielprogramm erstellt einen Ordner im Verzeichnis, aus dem es ausgeführt wird, und generiert eine Reihe nummerierter pprof
-Dateien. Jede Datei hat einen Namen,
ähnlich wie bei profile000042.pb.gz
. Jedes Verzeichnis enthält Profildaten.
und die Metadatendatei metadata.csv
, die Informationen zur
heruntergeladene Dateien.
Das Beispielprogramm akzeptiert die folgenden Befehlszeilenargumente:
project
: Das Projekt, aus dem die Profile abgerufen werden. Erforderlich.page_size
: Die maximale Anzahl von Profilen, die pro API-Aufruf abgerufen werden. Der Maximalwert vonpage_size
ist 1.000. Wenn dieses Feld nicht angegeben ist, wird es auf „100“ gesetzt.page_token
: Ein Stringtoken, das durch eine vorherige Ausführung des zum Fortsetzen von Downloads. Optional.max_profiles
: Die maximale Anzahl der Profile, die abgerufen werden sollen. Wenn ein negativer Ganzzahl angegeben wird, versucht das Programm, alle Profile abzurufen.
Optional.
Beispielanwendung ausführen
So führen Sie die Beispielanwendung aus:
Klonen Sie das Repository:
git clone https://github.com/GoogleCloudPlatform/golang-samples.git
Wechseln Sie in das Verzeichnis, das das Beispielprogramm enthält:
cd golang-samples/profiler/export
Führen Sie das Programm aus, nachdem Sie YOUR_GCP_PROJECT durch die ID Ihres Google Cloud-Projekt:
go run main.go -project YOUR_GCP_PROJECT -page_size 1000 -max_profiles 10000
Das Programm kann einige Zeit in Anspruch nehmen. Das Programm gibt eine Token für die nächste Seite nach dem Abrufen der aktuellen Seite. Mit dem Token können Sie den Vorgang fortsetzen, wenn das Programm unterbrochen wird.
Heruntergeladene Profile ansehen
Die heruntergeladene Datei ist im Format des serialisierten Protokollpuffers. Verwenden Sie das Open-Source-Tool pprof
, um sie zu lesen.