From 2c4b216db6011e5b0f387cbfa22a8d1b14cc3294 Mon Sep 17 00:00:00 2001 From: Sean Keely Date: Thu, 3 Jun 2021 14:56:54 -0500 Subject: [PATCH] Allow limiting debug warning messages. Add macro debug_warning_n to stop printing a message after N instances. Change-Id: Id5f84b11eb63b3a20bd2bcb2ea8f10a066b457ef [ROCm/ROCR-Runtime commit: ca8387768e5b6105249b8221a546ec914c6d2d23] --- .../rocr-runtime/runtime/hsa-runtime/core/util/utils.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h b/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h index 29478f4dd2..3c95d45452 100644 --- a/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h +++ b/projects/rocr-runtime/runtime/hsa-runtime/core/util/utils.h @@ -103,17 +103,21 @@ static __forceinline unsigned long long int strtoull(const char* str, #define PASTE(x, y) PASTE2(x, y) #ifdef NDEBUG -#define debug_warning(exp) \ +#define debug_warning_n(exp, limit) \ do { \ } while (false) #else -#define debug_warning(exp) \ +#define debug_warning_n(exp, limit) \ do { \ - if (!(exp)) \ + static std::atomic count(0); \ + if (!(exp) && (limit == 0 || count < limit)) { \ fprintf(stderr, "Warning: " STRING(exp) " in %s, " __FILE__ ":" STRING(__LINE__) "\n", \ __PRETTY_FUNCTION__); \ + count++; \ + } \ } while (false) #endif +#define debug_warning(exp) debug_warning_n((exp), 0) #ifdef NDEBUG #define debug_print(fmt, ...) \