-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add memory profiling support #39
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
Open
not-matthias
wants to merge
7
commits into
main
Choose a base branch
from
cod-1945-support-memory-profiling-for-c
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−34
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7308d30
chore: bump instrument-hooks to support memory profiling
not-matthias fd7b4db
feat: add support for memory mode
not-matthias 7141b20
feat: define shared CODSPEED_MODE_DISPLAY
not-matthias 0ecc10c
feat: run memory profiling in CI
not-matthias dfa9f36
feat(example): add memory benchmark example
not-matthias 9194373
chore(ci): switch to simulation
not-matthias 16f4e61
wip: install latest memtrack cli
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
Submodule instrument-hooks
updated
14 files
| +1 −0 | .github/workflows/ci.yml | |
| +5 −2 | Justfile | |
| +3,280 −2,736 | dist/core.c | |
| +0 −13 | src/c.zig | |
| +6 −0 | src/instruments/analysis.zig | |
| +61 −0 | src/instruments/fifo_instrument.zig | |
| +3 −155 | src/instruments/perf.zig | |
| +25 −14 | src/instruments/root.zig | |
| +5 −1 | src/instruments/valgrind.zig | |
| +199 −0 | src/runner_fifo.zig | |
| +20 −0 | src/shared.zig | |
| +52 −20 | src/tests/deserialize_rust/create_serialized.rs | |
| +29 −0 | src/tests/deserialize_rust/rust_deser.zig | |
| +138 −0 | src/tests/deserialize_rust/serialized.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/memory_bench.hpp | ||
not-matthias marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,197 @@ | ||
| #pragma once | ||
|
|
||
| #include <benchmark/benchmark.h> | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| // Run-length encoding: compress consecutive repeated characters | ||
| // Example: "aaabbbccc" -> "3a3b3c" | ||
| // NOTE: Intentionally inefficient - no pre-allocation to show multiple | ||
| // allocations | ||
| static std::string rle_encode(const std::string& input) { | ||
| if (input.empty()) return ""; | ||
|
|
||
| std::string result; // No reserve - will trigger multiple reallocations | ||
|
|
||
| char current = input[0]; | ||
| size_t count = 1; | ||
|
|
||
| for (size_t i = 1; i < input.size(); ++i) { | ||
| if (input[i] == current) { | ||
| count++; | ||
| } else { | ||
| // Create intermediate strings for each run | ||
| std::string count_str = std::to_string(count); | ||
| std::string run_encoded = count_str + current; | ||
| result += run_encoded; // Concatenation causes reallocations | ||
| current = input[i]; | ||
| count = 1; | ||
| } | ||
| } | ||
|
|
||
| // Final run | ||
| std::string count_str = std::to_string(count); | ||
| std::string final_run = count_str + current; | ||
| result += final_run; | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| // Run-length decoding: decompress RLE encoded string | ||
| // Example: "3a3b3c" -> "aaabbbccc" | ||
| static std::string rle_decode(const std::string& input) { | ||
| std::string result; | ||
| size_t i = 0; | ||
|
|
||
| while (i < input.size()) { | ||
| // Parse the count | ||
| size_t count = 0; | ||
| while (i < input.size() && std::isdigit(input[i])) { | ||
| count = count * 10 + (input[i] - '0'); | ||
| i++; | ||
| } | ||
|
|
||
| // Get the character | ||
| if (i < input.size()) { | ||
| char ch = input[i]; | ||
| result.append(count, ch); | ||
| i++; | ||
| } | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| // Generate a string with patterns for RLE | ||
| static std::string generate_rle_input(size_t size, size_t run_length) { | ||
| std::string result; | ||
| result.reserve(size); | ||
|
|
||
| const std::string chars = "abcdefghijklmnopqrstuvwxyz"; | ||
| size_t char_idx = 0; | ||
|
|
||
| while (result.size() < size) { | ||
| size_t count = std::min(run_length, size - result.size()); | ||
| result.append(count, chars[char_idx % chars.size()]); | ||
| char_idx++; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| // Benchmark: RLE encoding with small runs (high compression) | ||
| static void BM_RLE_Encode_SmallRuns(benchmark::State& state) { | ||
| const size_t input_size = state.range(0); | ||
| std::string input = generate_rle_input(input_size, 3); | ||
|
|
||
| for (auto _ : state) { | ||
| std::string encoded = rle_encode(input); | ||
| benchmark::DoNotOptimize(encoded); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
|
|
||
| state.SetBytesProcessed(state.iterations() * input_size); | ||
| } | ||
| BENCHMARK(BM_RLE_Encode_SmallRuns) | ||
| ->Arg(100) | ||
| ->Arg(1000) | ||
| ->Arg(10000) | ||
| ->Arg(100000); | ||
|
|
||
| // Benchmark: RLE encoding with large runs (low compression) | ||
| static void BM_RLE_Encode_LargeRuns(benchmark::State& state) { | ||
| const size_t input_size = state.range(0); | ||
| std::string input = generate_rle_input(input_size, 100); | ||
|
|
||
| for (auto _ : state) { | ||
| std::string encoded = rle_encode(input); | ||
| benchmark::DoNotOptimize(encoded); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
|
|
||
| state.SetBytesProcessed(state.iterations() * input_size); | ||
| } | ||
| BENCHMARK(BM_RLE_Encode_LargeRuns) | ||
| ->Arg(100) | ||
| ->Arg(1000) | ||
| ->Arg(10000) | ||
| ->Arg(100000); | ||
|
|
||
| // Benchmark: RLE decoding | ||
| static void BM_RLE_Decode(benchmark::State& state) { | ||
| const size_t input_size = state.range(0); | ||
| std::string input = generate_rle_input(input_size, 10); | ||
| std::string encoded = rle_encode(input); | ||
|
|
||
| for (auto _ : state) { | ||
| std::string decoded = rle_decode(encoded); | ||
| benchmark::DoNotOptimize(decoded); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
|
|
||
| state.SetBytesProcessed(state.iterations() * encoded.size()); | ||
| } | ||
| BENCHMARK(BM_RLE_Decode)->Arg(100)->Arg(1000)->Arg(10000)->Arg(100000); | ||
|
|
||
| // Benchmark: Vector allocations (resizing pattern) | ||
| static void BM_Vector_PushBack(benchmark::State& state) { | ||
| const size_t count = state.range(0); | ||
|
|
||
| for (auto _ : state) { | ||
| std::vector<int> vec; | ||
| for (size_t i = 0; i < count; ++i) { | ||
| vec.push_back(static_cast<int>(i)); | ||
| } | ||
| benchmark::DoNotOptimize(vec); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
| } | ||
| BENCHMARK(BM_Vector_PushBack)->Arg(10)->Arg(100)->Arg(1000)->Arg(10000); | ||
|
|
||
| // Benchmark: Vector allocations with reserve (optimized) | ||
| static void BM_Vector_Reserve(benchmark::State& state) { | ||
| const size_t count = state.range(0); | ||
|
|
||
| for (auto _ : state) { | ||
| std::vector<int> vec; | ||
| vec.reserve(count); | ||
| for (size_t i = 0; i < count; ++i) { | ||
| vec.push_back(static_cast<int>(i)); | ||
| } | ||
| benchmark::DoNotOptimize(vec); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
| } | ||
| BENCHMARK(BM_Vector_Reserve)->Arg(10)->Arg(100)->Arg(1000)->Arg(10000); | ||
|
|
||
| // Benchmark: String concatenation (many allocations) | ||
| static void BM_String_Concatenation(benchmark::State& state) { | ||
| const size_t count = state.range(0); | ||
|
|
||
| for (auto _ : state) { | ||
| std::string result; | ||
| for (size_t i = 0; i < count; ++i) { | ||
| result += "x"; | ||
| } | ||
| benchmark::DoNotOptimize(result); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
| } | ||
| BENCHMARK(BM_String_Concatenation)->Arg(10)->Arg(100)->Arg(1000)->Arg(10000); | ||
|
|
||
| // Benchmark: String concatenation with reserve (optimized) | ||
| static void BM_String_Reserve(benchmark::State& state) { | ||
| const size_t count = state.range(0); | ||
|
|
||
| for (auto _ : state) { | ||
| std::string result; | ||
| result.reserve(count); | ||
| for (size_t i = 0; i < count; ++i) { | ||
| result += "x"; | ||
| } | ||
| benchmark::DoNotOptimize(result); | ||
| benchmark::ClobberMemory(); | ||
| } | ||
| } | ||
| BENCHMARK(BM_String_Reserve)->Arg(10)->Arg(100)->Arg(1000)->Arg(10000); |
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.
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.