Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/GoogleCloudPlatform/golang-samples/profiler

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/GoogleCloudPlatform/golang-samples/profiler

  • v0.0.0-20241120234511-c5f1b76c464b
  • Source
  • Go
  • Socket score

Version published
Created
Source

Profiler samples

This directory contains Profiler samples. These samples are configured to collect profiling data and transmit that data to your Google Cloud Platform project. You can use the Profiler UI to analyze the collected profiles. For the Go language, your analysis options include CPU time, heap, allocated heap, contention, and thread analysis. You can even compare sets of profiles.

For profiling concepts, the capabilities of the Profiler UI, and how to configure your application to collect and transmit profiling data, see the Profiler documentation.

See the following configuration guides for details on modifying your application to collect and transmit profiling data:

See Profiling applications runing outside of Google Cloud Platform for additional configuration steps that are required when you are running your service outside of Google Cloud Platform.

Samples

Detailed instructions on executing these samples from Cloud Shell is included in Profiling samples.

profiler_quickstart

The sample profiler_quickstart is configured to run the hello-profiler service. This is a very simple service that is used by the Quickstart guide.

Go Code

hotapp

The sample hotapp is uses an infinite loop with two call stacks.

The Profiler documentation includes images generated from this sample. If you wish to generate profile data consistent with that included in the Profiler documentation, run the hotapp service with the following command line options:

go run main.go -service=docdemo-service -local_work -skew=75 -version=1.75.0

Go Code

hotmid

Sample hotmid is an application that simulates multiple calls to a library function made via different call paths. Each of these calls is not particularly expensive (and so does not stand out on the flame graph). But in the aggregate these calls add up to a significant time which can be identified via looking at the flat list of functions' self and total time.

Go Code

Executing a sample

To execute a sample and collect profiling data in your GCP project, do the following:

  1. If you have a new GCP, you need to enable the Profiler API for your project. Choose one of the following methods.

    From the Cloud console, go to APIs & Services and then click Enable APIS and Services. Search for Profiler. If the API isn't enabled, click Enable.

    From Cloud Shell, run the following command:

    gcloud services enable cloudprofiler.googleapis.com
    
  2. If you aren't running on GCP, then you need to create a service account. For details on these steps, see Profiling applications runing outside of Google Cloud Platform.

  3. From your clone of the GitHub repository, change to the source directory of the program you want to execute. For example, the following command changes the working directory to that for the sample hotapp:

    cd ~/gopath/src/github.com/GoogleCloudPlatform/golang-samples/profiler/hotapp
    
  4. If you aren't running on GCP, edit main.go and specify your GCP project ID.

  5. Start the program:

    go run main.go
    

A few seconds after you start the program, the message profiler has started is displayed. New messages are displayed each time a profile is uploaded to your GCP project. To stop the program, enter Ctrl-C.

Viewing your data

To view your profile data, do the following:

  1. Go to the Cloud Console.
  2. From the Navigation menu, scroll to the Stackdriver section and then select Profiler.

Each time you click Now, the Profiler UI is refreshed and includes profiles up to the current point in time.

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc