Skip to content

DylanWTR/Profiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Profiler

A simple C++ header-only profiling tool that outputs events in the Chrome Tracing format. This allows you to measure execution time of functions and code blocks and visualize them with Chrome's built-in timeline viewer.


Features

  • Header-only: just one file to include.
  • RAII timers: automatically profile functions or scopes.
  • Multi-thread aware: logs thread IDs.
  • Chrome Tracing output: open results in chrome://tracing.

Example usage

#include <profiler/Profiler.hpp>
#include <thread>
#include <vector>
#include <algorithm>

void heavy_function() {
    PROFILE_FUNCTION();
    std::vector<int> v(1'000'000);
    std::iota(v.begin(), v.end(), 0);
    std::sort(v.begin(), v.end(), std::greater<int>());
}

int main() {
    PROFILE_BEGIN_SESSION("demo", "profile.json");

    {
        PROFILE_SCOPE("startup");
        std::this_thread::sleep_for(std::chrono::milliseconds(50));
    }

    std::thread t1(heavy_function);
    std::thread t2(heavy_function);
    t1.join();
    t2.join();

    PROFILE_END_SESSION();
}

Visualizing results

  1. Run your program → generates profile.json.
  2. Open Chrome/Edge and go to chrome://tracing.
  3. Click Load and select profile.json.
  4. Explore a timeline of your function calls.

Chrome tracing screenshot


Installation (macOS)

1. Manual install

Copy the header into your system include path:

sudo mkdir -p /usr/local/include/profiler
sudo cp include/profiler/Profiler.hpp /usr/local/include/profiler/

Now you can include it from anywhere:

#include <profiler/Profiler.hpp>

2. CMake install

If you prefer CMake:

cmake -S . -B build
cmake --build build
sudo cmake --install build

This installs the header in /usr/local/include/profiler/.


Project structure

profiler/
├── include/profiler/Profiler.hpp   # Header-only library
├── examples/main.cpp               # Usage example
├── docs/screenshots/tracing.png    # Screenshot for README
├── CMakeLists.txt                  # CMake packaging for macOS
├── README.md                       # This file
└── LICENSE                         # MIT License

License

This project is licensed under the MIT License – see the LICENSE file for details.

About

A lightweight, header-only C++ profiler with Chrome Tracing support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published