Skip to content

withlin/golang-profiling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

golang-profiling

δΈ­ζ–‡ζ–‡ζ‘£ | English

πŸ”₯ A high-performance Golang application profiling tool based on eBPF technology, capable of generating interactive flame graphs for performance analysis.

πŸ”₯ Example Flame Graph

Example Flame Graph

✨ Features

  • πŸš€ Zero-overhead profiling: Uses eBPF technology for minimal performance impact
  • 🎯 Precise stack tracing: Captures complete call stacks with symbol resolution
  • πŸ”₯ Interactive flame graphs: Generates SVG flame graphs with zoom and search capabilities
  • 🎨 Customizable visualization: Supports various color schemes and layout options
  • πŸ“Š Multiple output formats: SVG flame graphs and folded stack traces
  • πŸ”§ Flexible targeting: Profile by PID, process name, or system-wide
  • ⚑ Real-time analysis: Live profiling with configurable sampling rates

πŸ› οΈ System Requirements

  • Operating System: Linux (kernel version >= 4.4)
  • Architecture: x86_64, aarch64
  • Privileges: Root access or CAP_BPF capability
  • Dependencies:
    • Rust toolchain (>= 1.70)
    • LLVM/Clang (>= 10.0)
    • Linux headers
    • Perl (for flame graph generation)

πŸ“¦ Installation

Option 1: Download Pre-built Binaries

Download the latest release from GitHub Releases:

# Download for x86_64 Linux
wget https://github.com/YOUR_USERNAME/golang-profile/releases/latest/download/golang-profiling-linux-x86_64.tar.gz
tar -xzf golang-profiling-linux-x86_64.tar.gz
sudo mv golang-profiling /usr/local/bin/

# Download for ARM64 Linux
wget https://github.com/YOUR_USERNAME/golang-profile/releases/latest/download/golang-profiling-linux-aarch64.tar.gz
tar -xzf golang-profiling-linux-aarch64.tar.gz
sudo mv golang-profiling /usr/local/bin/

Option 2: Build from Source

Install Rust Toolchain

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env

Install System Dependencies

Ubuntu/Debian:

sudo apt update
sudo apt install -y clang llvm libelf-dev libz-dev pkg-config linux-headers-$(uname -r) perl

CentOS/RHEL/Fedora:

# CentOS/RHEL
sudo yum install -y clang llvm elfutils-libelf-devel zlib-devel pkgconfig kernel-headers perl

# Fedora
sudo dnf install -y clang llvm elfutils-libelf-devel zlib-devel pkgconfig kernel-headers perl

Arch Linux:

sudo pacman -S clang llvm libelf zlib pkgconf linux-headers perl

Install bpf-linker

cargo install bpf-linker

πŸš€ Build

git clone <repository-url>
cd golang-profile
cargo build --release

The compiled binary will be available at target/release/golang-profiling.

πŸ“– Usage

Basic Usage

# Profile by PID
sudo ./target/release/golang-profiling --pid 1234 --duration 10 --output profile.svg

# Profile by process name
sudo ./target/release/golang-profiling --name "my-go-app" --duration 30 --output app_profile.svg

# System-wide profiling
sudo ./target/release/golang-profiling --duration 5 --output system_profile.svg

Command Line Options

Parameter Description Default Example
--pid Target process PID - --pid 1234
--name Target process name - --name "golang-app"
--duration Profiling duration (seconds) 10 --duration 30
--frequency Sampling frequency (Hz) 99 --frequency 199
--output Output SVG file path flamegraph.svg --output profile.svg
--folded-output Output folded stack file - --folded-output stacks.folded

Flame Graph Customization

Parameter Description Default Example
--title Flame graph title "Flame Graph" --title "My App Profile"
--subtitle Flame graph subtitle - --subtitle "CPU Profile"
--colors Color scheme hot --colors java
--bgcolors Background colors - --bgcolors blue
--width Image width 1200 --width 1600
--height Row height 16 --height 20
--fonttype Font family Verdana --fonttype Arial
--fontsize Font size 12 --fontsize 14
--inverted Invert flame graph false --inverted
--flamechart Generate flame chart false --flamechart
--hash Consistent colors false --hash
--random Random colors false --random

Usage Examples

1. Basic Process Profiling

sudo ./target/release/golang-profiling --pid 1234 --duration 10 --output basic_profile.svg

2. High-Frequency Sampling

sudo ./target/release/golang-profiling --name "my-service" --frequency 199 --duration 30 --output detailed_profile.svg

3. Custom Styled Flame Graph

sudo ./target/release/golang-profiling \
  --pid 1234 \
  --duration 15 \
  --title "Production Service Profile" \
  --subtitle "CPU Usage Analysis" \
  --colors java \
  --width 1600 \
  --height 20 \
  --fontsize 14 \
  --output custom_profile.svg

4. Inverted Flame Graph (Icicle Graph)

sudo ./target/release/golang-profiling --pid 1234 --inverted --title "Icicle Graph" --output icicle.svg

5. Export Both SVG and Folded Format

sudo ./target/release/golang-profiling \
  --pid 1234 \
  --duration 20 \
  --output profile.svg \
  --folded-output profile.folded

πŸ“Š Output Files

  • SVG Flame Graph: Interactive flame graph that can be opened in browsers, supports click-to-zoom and search
  • Folded Stack File: Text format raw data that can be used with other analysis tools

πŸ” Performance Analysis Tips

  1. Choose Appropriate Sampling Frequency:

    • High frequency (199Hz+): Suitable for short-term precise analysis
    • Low frequency (49Hz-99Hz): Suitable for long-term monitoring
  2. Recommended Duration:

    • Development environment: 5-10 seconds
    • Production environment: 30-60 seconds
  3. Reading Flame Graphs:

    • X-axis: Functions sorted alphabetically (not time)
    • Y-axis: Call stack depth
    • Width: Proportion of CPU time consumed by function

πŸ”§ Troubleshooting

Common Issues

  1. Permission Denied

    Error: Permission denied
    

    Solution: Run with sudo or ensure user has CAP_BPF capability

  2. Process Not Found

    Error: Process not found
    

    Solution: Check if the process PID or name is correct

  3. eBPF Not Supported

    Error: BPF program load failed
    

    Solution: Ensure kernel version >= 4.4 and eBPF support is enabled

  4. Missing Dependencies

    Error: flamegraph.pl not found
    

    Solution: Ensure Perl is installed and flamegraph.pl is in the project directory

πŸ“„ License

This project is licensed under multiple licenses:

  • Apache License 2.0
  • MIT License
  • GPL v2 License

🀝 Contributing

Contributions are welcome! Please feel free to submit Issues and Pull Requests.

πŸ”— Related Projects

  • FlameGraph - Brendan Gregg's flame graph tools
  • aya - Rust eBPF library

Happy Profiling! πŸ”₯

About

golang-profiling by ebpf

Resources

License

Apache-2.0 and 2 other licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
GPL-2.0
LICENSE-GPL2
MIT
LICENSE-MIT

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors