]> git.ipfire.org Git - thirdparty/nqptp.git/commitdiff
Make debug_print_buffer check the debug level before doing any work. Set suggested...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 5 Dec 2024 14:56:29 +0000 (14:56 +0000)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Thu, 5 Dec 2024 14:56:29 +0000 (14:56 +0000)
configure.ac
debug.c
debug.h
nqptp-utilities.c

index 503b805b49a31278df02f15aaa6b8130d6cfa4c4..d8611179b670f28603fe73c8fb80af7ac676d545 100644 (file)
@@ -3,6 +3,8 @@
 
 AC_PREREQ([2.68])
 AC_INIT([nqptp], [1.2.5], [4265913+mikebrady@users.noreply.github.com])
+: ${CFLAGS="-O3"}
+: ${CXXFLAGS="-O3"}
 AM_INIT_AUTOMAKE
 AC_CANONICAL_HOST
 
diff --git a/debug.c b/debug.c
index 50a7705f6d1b2ff692efc5287caf1574b6a95867..62108fd59b0602e9443e82789ce6ac52b29d681f 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -59,6 +59,10 @@ void debug_init(int level, int show_elapsed_time, int show_relative_time, int sh
   debugger_show_file_and_line = show_file_and_line;
 }
 
+int debug_level() {
+  return debuglev;
+}
+
 char *generate_preliminary_string(char *buffer, size_t buffer_length, double tss, double tsl,
                                   const char *filename, const int linenumber, const char *prefix) {
   size_t space_remaining = buffer_length;
diff --git a/debug.h b/debug.h
index 7415c97f2687ed0ae65a6466aa3adbae2e1719d3..8f7ffe424b773bbc7ee9411b3ee17996389e002c 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -22,6 +22,7 @@
 
 // level 0 is no messages, level 3 is most messages
 void debug_init(int level, int show_elapsed_time, int show_relative_time, int show_file_and_line);
+int debug_level(); // get current debug level
 
 void _die(const char *filename, const int linenumber, const char *format, ...);
 void _warn(const char *filename, const int linenumber, const char *format, ...);
index 18e5a9c9a4ca5d6c2dfc92536972c3d93b286aa8..39cb53b7e1d04fb30f0db6d0ecde03b05873013e 100644 (file)
@@ -114,52 +114,54 @@ void open_sockets_at_port(const char *node, uint16_t port,
 }
 
 void debug_print_buffer(int level, char *buf, size_t buf_len) {
-  // printf("Received %u bytes in a packet from %s:%d\n", buf_len, inet_ntoa(si_other.sin_addr),
-  // ntohs(si_other.sin_port));
-  char *obf =
-      malloc(buf_len * 4 + 1); // to be on the safe side -- 4 characters on average for each byte
-  if (obf != NULL) {
-    char *obfp = obf;
-    unsigned int obfc;
-    for (obfc = 0; obfc < buf_len; obfc++) {
-      snprintf(obfp, 3, "%02X", buf[obfc]);
-      obfp += 2;
-      if (obfc != buf_len - 1) {
-        if (obfc % 32 == 31) {
-          snprintf(obfp, 5, " || ");
-          obfp += 4;
-        } else if (obfc % 16 == 15) {
-          snprintf(obfp, 4, " | ");
-          obfp += 3;
-        } else if (obfc % 4 == 3) {
-          snprintf(obfp, 2, " ");
-          obfp += 1;
+  if (debug_level() >= level) {
+    // printf("Received %u bytes in a packet from %s:%d\n", buf_len, inet_ntoa(si_other.sin_addr),
+    // ntohs(si_other.sin_port));
+    char *obf =
+        malloc(buf_len * 4 + 1); // to be on the safe side -- 4 characters on average for each byte
+    if (obf != NULL) {
+      char *obfp = obf;
+      unsigned int obfc;
+      for (obfc = 0; obfc < buf_len; obfc++) {
+        snprintf(obfp, 3, "%02X", buf[obfc]);
+        obfp += 2;
+        if (obfc != buf_len - 1) {
+          if (obfc % 32 == 31) {
+            snprintf(obfp, 5, " || ");
+            obfp += 4;
+          } else if (obfc % 16 == 15) {
+            snprintf(obfp, 4, " | ");
+            obfp += 3;
+          } else if (obfc % 4 == 3) {
+            snprintf(obfp, 2, " ");
+            obfp += 1;
+          }
         }
+      };
+      *obfp = 0;
+      switch (buf[0]) {
+  
+      case 0x10:
+        debug(level, "SYNC: \"%s\".", obf);
+        break;
+      case 0x18:
+        debug(level, "FLUP: \"%s\".", obf);
+        break;
+      case 0x19:
+        debug(level, "DRSP: \"%s\".", obf);
+        break;
+      case 0x1B:
+        debug(level, "ANNC: \"%s\".", obf);
+        break;
+      case 0x1C:
+        debug(level, "SGNL: \"%s\".", obf);
+        break;
+      default:
+        debug(1, "XXXX  \"%s\".", obf); // output this at level 1
+        break;
       }
-    };
-    *obfp = 0;
-    switch (buf[0]) {
-
-    case 0x10:
-      debug(level, "SYNC: \"%s\".", obf);
-      break;
-    case 0x18:
-      debug(level, "FLUP: \"%s\".", obf);
-      break;
-    case 0x19:
-      debug(level, "DRSP: \"%s\".", obf);
-      break;
-    case 0x1B:
-      debug(level, "ANNC: \"%s\".", obf);
-      break;
-    case 0x1C:
-      debug(level, "SGNL: \"%s\".", obf);
-      break;
-    default:
-      debug(1, "XXXX  \"%s\".", obf); // output this at level 1
-      break;
+      free(obf);
     }
-    free(obf);
   }
 }