-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add perf v2 support #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
33eaedb
fix(ci): add mode param
not-matthias c897b7b
feat: add support for benchmark markers
not-matthias 7317f26
feat: add multithread example
not-matthias 15b5d12
feat: add bench with `PauseTiming`
not-matthias eaa5ee2
chore: bump instrument-hooks
not-matthias 9fd25ee
fix: ignore instrument-hooks warning
not-matthias 7c2430e
fix: remove memory allocations, use fixed iteration count
not-matthias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule instrument-hooks
updated
15 files
+9 −2 | .github/workflows/ci.yml | |
+3 −2 | Justfile | |
+3,705 −2,754 | dist/core.c | |
+20 −1 | example/main.c | |
+61 −0 | flake.lock | |
+53 −0 | flake.nix | |
+29 −12 | includes/core.h | |
+3 −3 | scripts/release.py | |
+8 −1 | scripts/stub.c | |
+45 −0 | src/c.zig | |
+64 −51 | src/fifo.zig | |
+13 −0 | src/instruments/perf.zig | |
+7 −0 | src/instruments/root.zig | |
+47 −0 | src/shared.zig | |
+21 −0 | src/utils.zig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../google_benchmark_cmake/helper.hpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../google_benchmark_cmake/multithread_bench.hpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../google_benchmark_cmake/pause_timing_bench.hpp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef HELPER_HPP | ||
#define HELPER_HPP | ||
|
||
#ifdef _MSC_VER | ||
#define NOINLINE __declspec(noinline) | ||
#else | ||
#define NOINLINE __attribute__((noinline)) | ||
#endif | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <cstdint> | ||
#include <numeric> | ||
#include <vector> | ||
|
||
NOINLINE static uint64_t recursive_fib(int n) { | ||
if (n <= 1) return n; | ||
return recursive_fib(n - 1) + recursive_fib(n - 2); | ||
} | ||
|
||
NOINLINE static uint64_t expensive_operation() { | ||
// Expensive recursive compuation that will dominate flamegraph | ||
return 42 + recursive_fib(30); | ||
} | ||
|
||
#endif // HELPER_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#pragma once | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <atomic> | ||
#include <thread> | ||
|
||
#include "helper.hpp" | ||
|
||
// Simple multithreaded benchmark: spawn thread, do work, join | ||
static void BM_SimpleMultithread(benchmark::State& state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
std::atomic<bool> work_start{false}; | ||
std::atomic<bool> work_done{false}; | ||
|
||
std::thread worker([&]() { | ||
// Wait for the signal to start | ||
while (!work_start.load()) { | ||
std::this_thread::yield(); | ||
} | ||
|
||
// Do some CPU work | ||
benchmark::DoNotOptimize(expensive_operation()); | ||
work_done.store(true); | ||
}); | ||
state.ResumeTiming(); | ||
|
||
// Signal the worker to start | ||
work_start.store(true); | ||
|
||
// Wait for worker to complete | ||
while (!work_done.load()) { | ||
std::this_thread::yield(); | ||
} | ||
|
||
worker.join(); | ||
} | ||
} | ||
|
||
BENCHMARK(BM_SimpleMultithread); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#pragma once | ||
|
||
#include <benchmark/benchmark.h> | ||
|
||
#include <chrono> | ||
#include <thread> | ||
|
||
#include "helper.hpp" | ||
|
||
NOINLINE static uint64_t actual_work() { | ||
std::this_thread::sleep_for(std::chrono::milliseconds(1)); | ||
return 42; | ||
} | ||
|
||
static void BM_large_setup_teardown(benchmark::State& state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
benchmark::DoNotOptimize(expensive_operation()); | ||
state.ResumeTiming(); | ||
|
||
benchmark::DoNotOptimize(actual_work()); | ||
|
||
state.PauseTiming(); | ||
benchmark::DoNotOptimize(expensive_operation()); | ||
state.ResumeTiming(); | ||
} | ||
} | ||
// IMPORTANT: Use fixed iterations, otherwise we'll run for 10+ minutes | ||
BENCHMARK(BM_large_setup_teardown)->Iterations(100); | ||
|
||
static void BM_large_setup(benchmark::State& state) { | ||
for (auto _ : state) { | ||
state.PauseTiming(); | ||
benchmark::DoNotOptimize(expensive_operation()); | ||
state.ResumeTiming(); | ||
|
||
benchmark::DoNotOptimize(actual_work()); | ||
} | ||
} | ||
BENCHMARK(BM_large_setup)->Iterations(100); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.