aboutsummaryrefslogtreecommitdiff
path: root/mwe
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-09-11 15:07:22 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-09-11 15:07:22 +0200
commitfaccce92caa85e1466e30a1284119b1a8a666fa3 (patch)
tree03b5fe155cfcb112e1b44f1bf56fe1b506a8b41c /mwe
parent83568a442d494078a662276969a4ed9b789dc0c7 (diff)
add profiling pocpoc/profiling
Diffstat (limited to 'mwe')
-rw-r--r--mwe/profiling/.gitignore1
-rw-r--r--mwe/profiling/CMakeLists.txt14
-rw-r--r--mwe/profiling/lib/CMakeLists.txt11
-rw-r--r--mwe/profiling/lib/lib.cpp26
-rw-r--r--mwe/profiling/lib/lib.h12
-rw-r--r--mwe/profiling/main.c7
-rw-r--r--mwe/profiling/makefile1
-rw-r--r--mwe/profiling/readme.md11
8 files changed, 83 insertions, 0 deletions
diff --git a/mwe/profiling/.gitignore b/mwe/profiling/.gitignore
new file mode 100644
index 0000000..6a28331
--- /dev/null
+++ b/mwe/profiling/.gitignore
@@ -0,0 +1 @@
+callgrind.out.*
diff --git a/mwe/profiling/CMakeLists.txt b/mwe/profiling/CMakeLists.txt
new file mode 100644
index 0000000..a76aeb5
--- /dev/null
+++ b/mwe/profiling/CMakeLists.txt
@@ -0,0 +1,14 @@
+cmake_minimum_required(VERSION 3.28)
+
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_BUILD_TYPE Debug)
+
+project(main C CXX)
+
+add_subdirectory(lib)
+
+add_executable(main main.c)
+
+target_link_libraries(main PRIVATE test)
+
diff --git a/mwe/profiling/lib/CMakeLists.txt b/mwe/profiling/lib/CMakeLists.txt
new file mode 100644
index 0000000..bd78d59
--- /dev/null
+++ b/mwe/profiling/lib/CMakeLists.txt
@@ -0,0 +1,11 @@
+cmake_minimum_required(VERSION 3.28)
+
+set(CMAKE_C_STANDARD 11)
+set(CMAKE_CXX_STANDARD 20)
+set(CMAKE_BUILD_TYPE Release)
+
+project(lib C CXX)
+
+add_library(test SHARED lib.cpp)
+target_include_directories(test SYSTEM INTERFACE .)
+
diff --git a/mwe/profiling/lib/lib.cpp b/mwe/profiling/lib/lib.cpp
new file mode 100644
index 0000000..9ea8f26
--- /dev/null
+++ b/mwe/profiling/lib/lib.cpp
@@ -0,0 +1,26 @@
+#include <chrono>
+#include <thread>
+#include <random>
+
+#include "lib.h"
+
+// yeah this is bad, boo hoo
+using namespace std;
+using std::this_thread::sleep_for;
+using std::chrono::milliseconds;
+
+random_device dev;
+mt19937 rng(dev());
+uniform_int_distribution<mt19937::result_type> random_dist(1, 50);
+
+static void random_slow() {
+ int delay = random_dist(rng);
+ sleep_for(milliseconds(delay));
+}
+
+int recursive(int rem) {
+ if (rem <= 0) return 0;
+ random_slow();
+ return recursive(rem - 1) + recursive(rem - 2);
+}
+
diff --git a/mwe/profiling/lib/lib.h b/mwe/profiling/lib/lib.h
new file mode 100644
index 0000000..fc413ff
--- /dev/null
+++ b/mwe/profiling/lib/lib.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int recursive(int rem);
+
+#ifdef __cplusplus
+}
+#endif
+
diff --git a/mwe/profiling/main.c b/mwe/profiling/main.c
new file mode 100644
index 0000000..689da52
--- /dev/null
+++ b/mwe/profiling/main.c
@@ -0,0 +1,7 @@
+#include <lib.h>
+
+int main() {
+ int x = recursive(8);
+ return x == 0;
+}
+
diff --git a/mwe/profiling/makefile b/mwe/profiling/makefile
new file mode 100644
index 0000000..d637b57
--- /dev/null
+++ b/mwe/profiling/makefile
@@ -0,0 +1 @@
+include ../../lazy.mk
diff --git a/mwe/profiling/readme.md b/mwe/profiling/readme.md
new file mode 100644
index 0000000..99b1ee2
--- /dev/null
+++ b/mwe/profiling/readme.md
@@ -0,0 +1,11 @@
+# profiling test
+
+Test how callgrind handles executables that call library functions from
+libraries w/o debug symbols.
+
+To collect run info, run
+
+```
+$ valgrind --tool=callgrind build/main
+```
+