diff options
| author | hachem <im@hachem.wtf> | 2026-09-04 05:46:36 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-04 05:46:36 +0200 |
| commit | d3a1b908fd3b0c47da2c33c16d18ebeb00da3b97 (patch) | |
| tree | 1e8861de97ebd0c580a0cfaa4c759cf3e5be8e3b /test/trace_demo.cpp | |
| parent | 9023d106c61db0be0de6460a397bbad42bbc3d96 (diff) | |
refactor: reorganize tests
Diffstat (limited to 'test/trace_demo.cpp')
| -rw-r--r-- | test/trace_demo.cpp | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/trace_demo.cpp b/test/trace_demo.cpp new file mode 100644 index 0000000..d5dbce0 --- /dev/null +++ b/test/trace_demo.cpp @@ -0,0 +1,49 @@ +// a demo target for the flame-chart timeline: a nest of functions that call one +// another so the timeline has real depth. main is the outermost (bottom row), +// each callee stacks a row higher +#include <chrono> +#include <cstdio> +#include <thread> + +// innermost: a chunk of busywork so the leaf calls have visible width +auto leaf(int n) -> long +{ + long total = 0; + for (int i = 0; i < n * 60000; ++i) + total += i % 7; + + return total; +} + +// calls leaf a few times +auto inner(int round) -> long +{ + long total = 0; + for (int i = 1; i <= 3; ++i) + total += leaf(round % 4 + i); + + return total; +} + +// calls inner, one level below main +auto outer(int round) -> long +{ + const long a = inner(round); + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + const long b = inner(round + 1); + return a + b; +} + +auto main() -> int +{ + for (int round = 0; round < 20; ++round) + { + const long result = outer(round); + std::printf("round %d -> %ld\n", round, result); + std::fflush(stdout); + + std::this_thread::sleep_for(std::chrono::milliseconds(150)); + } + + std::puts("done"); +} |
