tests: add callgrind start/stop macros in benchmark programs
Change-Id: Ibd875f4275431ebcbeba2fffe319956580714553
Refs: #3610
diff --git a/tests/other/pit-fib-benchmark.cpp b/tests/other/pit-fib-benchmark.cpp
index e6c907f..85ffe5e 100644
--- a/tests/other/pit-fib-benchmark.cpp
+++ b/tests/other/pit-fib-benchmark.cpp
@@ -28,6 +28,10 @@
#include "tests/test-common.hpp"
+#ifdef HAVE_VALGRIND
+#include <valgrind/callgrind.h>
+#endif
+
namespace nfd {
namespace tests {
@@ -38,6 +42,10 @@
: m_fib(m_nameTree)
, m_pit(m_nameTree)
{
+#ifdef _DEBUG
+ BOOST_TEST_MESSAGE("Benchmark compiled in debug mode is unreliable, "
+ "please compile in release mode.");
+#endif
}
void
@@ -113,6 +121,10 @@
generatePacketsAndPopulateFib(nRoundTrip, nFibEntries, fibPrefixLength,
interestNameLength, dataNameLength);
+#ifdef HAVE_VALGRIND
+ CALLGRIND_START_INSTRUMENTATION;
+#endif
+
auto t1 = time::steady_clock::now();
for (size_t i = 0; i < nRoundTrip + gap3 + gap4; ++i) {
@@ -133,6 +145,11 @@
}
auto t2 = time::steady_clock::now();
+
+#ifdef HAVE_VALGRIND
+ CALLGRIND_STOP_INSTRUMENTATION;
+#endif
+
BOOST_TEST_MESSAGE(time::duration_cast<time::microseconds>(t2 - t1));
}