From f71e40ab600b1b3d00f163d1edf7125ca99b25bd Mon Sep 17 00:00:00 2001 From: German Service Network Date: Sun, 17 Mar 2024 08:10:20 +0100 Subject: [PATCH] Extended configure.ac with --enable-debug and create debug output cpu time use --- configure.ac | 5 +++++ src/fping.c | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/configure.ac b/configure.ac index cfe702f..9f6e2e0 100644 --- a/configure.ac +++ b/configure.ac @@ -67,6 +67,11 @@ AC_ARG_ENABLE([safe-limits], AS_IF([test "x$enable_safe_limits" = "xyes"], [ AC_DEFINE(FPING_SAFE_LIMITS, [1], [safe limits should be enforced])]) +AC_ARG_ENABLE([debug], + AS_HELP_STRING([--enable-debug], [enable debugging @<:@default=no@:>@]), [enable_debug=$enableval], [enable_debug=no]) +AS_IF([test "x$enable_debug" = "xyes"], [ + AC_DEFINE([DEBUG], [1], [Define if debugging is enabled])]) + AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AM_MAINTAINER_MODE diff --git a/src/fping.c b/src/fping.c index 532d96e..779836a 100644 --- a/src/fping.c +++ b/src/fping.c @@ -452,6 +452,13 @@ int p_setsockopt(uid_t p_uid, int sockfd, int level, int optname, int main(int argc, char **argv) { +/* Debug: CPU Performance */ +#if defined(DEBUG) || defined(_DEBUG) + clock_t perf_cpu_start, perf_cpu_end; + double perf_cpu_time_used; + perf_cpu_start = clock(); +#endif /* DEBUG || _DEBUG */ + int c; const uid_t suid = geteuid(); int tos = 0; @@ -1198,6 +1205,13 @@ int main(int argc, char **argv) /* main loop */ main_loop(); +/* Debug: CPU Performance */ +#if defined(DEBUG) || defined(_DEBUG) + perf_cpu_end = clock(); + perf_cpu_time_used = ((double) (perf_cpu_end - perf_cpu_start)) / CLOCKS_PER_SEC; + printf("[DEBUG] CPU time used: %f sec", perf_cpu_time_used); +#endif /* DEBUG || _DEBUG */ + finish(); return 0;