# se-fbk/followthepid architecture

> Architecture diagram of the GitHub repository se-fbk/followthepid, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/se-fbk/followthepid
- Repository: https://github.com/se-fbk/followthepid

## Overview

##### Project type and purpose
- This is an open-source Python library/CLI tool named **followThePid**.
- Purpose: trace CPU usage and energy consumption of a running process (by PID) on Linux and macOS.

##### File structure
- Top-level:
- setup.py, requirements.txt → packaging & dependencies
- src/
- Inside src/:
- cpu.py → core CPU‐usage sampling
- device/ → abstraction for platform-specific energy readings
– base.py → abstract interface (DeviceBase)
– factory.py → chooses correct Device implementation at runtime
– linux.py, mac.py, windows.py → OS adapters
- metrics.py → data collection & normalization logic
- followThePid.py → main user-facing class (FollowThePid)
- example/simple_example.py → usage demo

##### README for additional insights
- Dependencies: Python 3.12+, pandas optional
- Uses Intel RAPL on Linux, powermetrics on macOS
- Outputs: CSV or pandas DataFrame

##### Elements
- Clear labels: e.g., “FollowThePid (CLI/Library)”, “DeviceFactory”, “LinuxDevice”

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Modules
    subgraph "Core Modules"
        FP["FollowThePid (CLI/Library)"]:::core
        CPU["CPU Sampler (cpu.py)"]:::core
        Metrics["Metrics Collector (metrics.py)"]:::core
    end

    %% Demo Example
    Example["Usage Example (simple_example.py)"]:::core

    %% Device Abstraction Layer
    subgraph "Device Abstraction Layer"
        Base["DeviceBase (base.py)"]:::abstraction
        Factory["DeviceFactory (factory.py)"]:::abstraction
    end

    %% OS Adapters
    subgraph "OS Adapters"
        Linux["LinuxDevice (linux.py)"]:::adapter
        Mac["MacDevice (mac.py)"]:::adapter
        Win["WindowsDevice (windows.py)"]:::adapter
    end

    %% Data Exporters
    subgraph "Data Exporters"
        CSV["CSV Writer"]:::exporter
        DF["Pandas DataFrame Builder"]:::exporter
    end

    %% External Systems
    subgraph "External Systems"
        RAPL["Linux RAPL sysfs"]:::external
        POW["macOS powermetrics"]:::external
        PANDAS["pandas library"]:::external
    end

    %% Packaging & Dependencies
    subgraph "Packaging & Dependencies"
        Setup["setup.py"]:::external
        Req["requirements.txt"]:::external
    end

    %% Connections
    FP -->|"invokes"| CPU
    FP -->|"invokes"| Metrics
    FP -->|"factory.get_device()"| Factory
    Example -->|"uses"| FP

    Factory --> Linux
    Factory --> Mac
    Factory --> Win

    CPU -->|"sampler.sample()"| Base
    Base --> Linux
    Base --> Mac
    Base --> Win

    Linux -->|"reads"| RAPL
    Mac -->|"reads"| POW

    CPU -->|"cpu usage"| Metrics
    Base -->|"energy readings"| Metrics

    Metrics -->|"export_csv()"| CSV
    Metrics -->|"export_dataframe()"| DF
    DF -->|"depends on"| PANDAS

    %% Click Events
    click FP "https://github.com/se-fbk/followthepid/blob/main/src/followThePid.py"
    click CPU "https://github.com/se-fbk/followthepid/blob/main/src/cpu.py"
    click Base "https://github.com/se-fbk/followthepid/blob/main/src/device/base.py"
    click Factory "https://github.com/se-fbk/followthepid/blob/main/src/device/factory.py"
    click Linux "https://github.com/se-fbk/followthepid/blob/main/src/device/linux.py"
    click Mac "https://github.com/se-fbk/followthepid/blob/main/src/device/mac.py"
    click Win "https://github.com/se-fbk/followthepid/blob/main/src/device/windows.py"
    click Metrics "https://github.com/se-fbk/followthepid/blob/main/src/metrics.py"
    click Example "https://github.com/se-fbk/followthepid/blob/main/src/example/simple_example.py"
    click Setup "https://github.com/se-fbk/followthepid/blob/main/setup.py"
    click Req "https://github.com/se-fbk/followthepid/blob/main/requirements.txt"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef abstraction fill:#90EE90,stroke:#333,stroke-width:1px
    classDef adapter fill:#FFA500,stroke:#333,stroke-width:1px
    classDef exporter fill:#EEE8AA,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
