# open-telemetry/opentelemetry-ebpf-profiler architecture

> Architecture diagram of the GitHub repository open-telemetry/opentelemetry-ebpf-profiler, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/open-telemetry/opentelemetry-ebpf-profiler
- Repository: https://github.com/open-telemetry/opentelemetry-ebpf-profiler

## Overview

##### Main Components

a) Core System Components:
- eBPF Programs (Kernel Space)
- Host Agent (User Space)
- Backend Collector
- Visualization Layer (devfiler)

b) Key Processing Components:
- Tracer
- Process Manager
- Trace Handler
- Reporter
- Interpreter Handlers
- Stack Delta Provider

**[Kernel Space]**
- ↑↓
**[User Space Agent]**
- ↑↓
**[Collection & Visualization]**

##### Detailed Component Relationships

a) Kernel Space Layer:
- EBPF Programs attached to kernel probes
- BPF maps for data sharing
- Stack unwinding components
- Perf events system

b) User Space Layer:
- Process Manager with connections to interpreter handlers
- Trace Handler showing conversion pipeline
- Reporter with gRPC connection
- Stack Delta Provider connected to native code analysis

c) Collection Layer:
- Backend Collector receiving gRPC data
- Devfiler visualization component

##### Data Flow Representation

- Stack trace collection (eBPF → User Space)
- Process events (Kernel → Process Manager)
- Trace conversion pipeline
- Reporting flow to collector

##### Component Details

Each major component should show:
- Input/Output interfaces
- Key responsibilities
- Internal sub-components
- Resource requirements

##### Implementation Details

Specific technical elements:
- BPF program entry points
- Trace format conversions
- Hash calculation methods
- gRPC protocol endpoints

##### The scalable data collection and reporting mechanism

This system design should help developers understand both the high-level architecture and the detailed interactions between components while highlighting the project's unique features like cross-language profiling and efficient stack unwinding.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef kernel fill:#a0d8ef
    classDef userspace fill:#b8e6b3
    classDef collection fill:#ffd700
    classDef datastore fill:#ffb6c1
    classDef interpreter fill:#dda0dd
    classDef process fill:#98fb98
    classDef native fill:#f0e68c

    %% Legend
    subgraph Legend
        L1[Kernel Components]:::kernel
        L2[User Space Components]:::userspace
        L3[Collection Components]:::collection
        L4[Data Stores]:::datastore
        L5[Interpreters]:::interpreter
    end

    %% Kernel Space Layer
    subgraph Kernel
        BPF[eBPF Programs]:::kernel
        MAPS[BPF Maps]:::datastore
        PERF[Perf Events]:::kernel
    end
    click BPF "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/support/ebpf/"
    click MAPS "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/libpf/"

    %% User Space Layer
    subgraph UserSpace
        HA[Host Agent]:::userspace
        PM[Process Manager]:::process
        TH[Trace Handler]:::userspace
        REP[Reporter]:::userspace
        SDP[Stack Delta Provider]:::native
        TR[Tracer]:::userspace
        NU[Native Unwinding]:::native
        PI[Process Information]:::process
        MC[Metrics Collector]:::userspace
    end
    click HA "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/blob/main/host/host.go"
    click PM "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/processmanager/"
    click TH "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/tracehandler/"
    click REP "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/reporter/"
    click SDP "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/blob/main/nativeunwind/elfunwindinfo/stackdeltaprovider.go"
    click TR "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/tracer/"
    click NU "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/nativeunwind/"
    click PI "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/process/"
    click MC "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/metrics/"

    %% Interpreter Layer
    subgraph Interpreters
        PY[Python]:::interpreter
        RB[Ruby]:::interpreter
        PHP[PHP]:::interpreter
        NODE[Node.js]:::interpreter
        JAVA[Java/Hotspot]:::interpreter
        NET[.NET]:::interpreter
    end
    click PY "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/python/"
    click RB "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/ruby/"
    click PHP "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/php/"
    click NODE "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/nodev8/"
    click JAVA "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/hotspot/"
    click NET "https://github.com/open-telemetry/opentelemetry-ebpf-profiler/tree/main/interpreter/dotnet/"

    %% Relationships
    BPF --> MAPS
    BPF --> PERF
    MAPS --> HA
    PERF --> HA
    HA --> PM
    HA --> TH
    PM --> Interpreters
    TH --> REP
    TR --> TH
    NU --> SDP
    SDP --> TH
    PI --> PM
    MC --> REP

    %% Data Flow
    MAPS -.-> TR
    TR -.-> TH
    TH -.-> REP
    PM -.-> PI
```
