From 6dbf014773f5f8ac0b0e291392dfde518de94daf Mon Sep 17 00:00:00 2001 From: johannst Date: Tue, 23 Jan 2024 01:39:29 +0000 Subject: deploy: 8c9fd06e839c06717dd2dcb067371a5e1fc71801 --- trace_profile/callgrind/cg_example.cc | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 trace_profile/callgrind/cg_example.cc (limited to 'trace_profile/callgrind/cg_example.cc') diff --git a/trace_profile/callgrind/cg_example.cc b/trace_profile/callgrind/cg_example.cc new file mode 100644 index 0000000..d143790 --- /dev/null +++ b/trace_profile/callgrind/cg_example.cc @@ -0,0 +1,36 @@ +#include +#include + +#include + +struct cnt { + volatile int a; + volatile int b; +}; + +void inc_a(cnt &c) { c.a++; } +void inc_b(cnt &c) { c.b++; } + +int main() { + cnt C{0, 0}; + + CALLGRIND_START_INSTRUMENTATION; + + std::thread T1([&C]() { + for (int i = 0; i < 20000000; ++i) { + inc_a(C); + } + }); + std::thread T2([&C]() { + for (int i = 0; i < 10000000; ++i) { + inc_b(C); + } + }); + T1.join(); + T2.join(); + + CALLGRIND_STOP_INSTRUMENTATION; + + printf("%d %d\n", C.a, C.b); + return 0; +} -- cgit v1.2.3