瀏覽代碼

Merge pull request #571 from ZuluSCSI/dev_log_optimize

ZuluSCSI_log: Reduce flash usage
Alex Perez 6 月之前
父節點
當前提交
89a9db9b41
共有 2 個文件被更改,包括 49 次插入14 次删除
  1. 36 0
      src/ZuluSCSI_log.cpp
  2. 13 14
      src/ZuluSCSI_log.h

+ 36 - 0
src/ZuluSCSI_log.cpp

@@ -145,6 +145,42 @@ void log_raw(bytearray array)
     }
     }
 }
 }
 
 
+void logmsg_start()
+{
+    log_raw("[", (int)millis(), "ms] ");
+}
+
+void logmsg_end()
+{
+    log_raw("\r\n");
+}
+
+bool dbgmsg_start()
+{
+    if (g_log_debug)
+    {
+        // Check if log mask is not the default value, the selection was a success, and the selected ID was not match, then skip logging
+        if ( g_scsi_log_mask != 0xFF
+            && (SCSI_STS_SELECTION_SUCCEEDED & *SCSI_STS_SELECTED)
+            && (0 == (g_scsi_log_mask & (1 << (*SCSI_STS_SELECTED & 7))))
+           )
+        {
+            return false;
+        }
+
+        log_raw("[", (int)millis(), "ms] DBG ");
+
+        return true;
+    }
+
+    return false;
+}
+
+void dbgmsg_end()
+{
+    log_raw("\r\n");
+}
+
 uint32_t log_get_buffer_len()
 uint32_t log_get_buffer_len()
 {
 {
     return g_logpos;
     return g_logpos;

+ 13 - 14
src/ZuluSCSI_log.h

@@ -73,6 +73,14 @@ inline void log_raw()
     // End of template recursion
     // End of template recursion
 }
 }
 
 
+// These functions contain the common prefix and end of each
+// log message, and check if debug messages are enabled.
+// Having them in separate functions avoids inlining the code
+// into every call.
+void logmsg_start();
+void logmsg_end();
+bool dbgmsg_start();
+void dbgmsg_end();
 
 
 extern "C" unsigned long millis();
 extern "C" unsigned long millis();
 
 
@@ -89,28 +97,19 @@ inline void log_raw(T first, T2 second, Rest... rest)
 template<typename... Params>
 template<typename... Params>
 inline void logmsg(Params... params)
 inline void logmsg(Params... params)
 {
 {
-    log_raw("[", (int)millis(), "ms] ");
+    logmsg_start();
     log_raw(params...);
     log_raw(params...);
-    log_raw("\r\n");
+    logmsg_end();
 }
 }
 
 
 // Format a complete debug message
 // Format a complete debug message
 template<typename... Params>
 template<typename... Params>
 inline void dbgmsg(Params... params)
 inline void dbgmsg(Params... params)
 {
 {
-    if (g_log_debug)
+    if (g_log_debug && dbgmsg_start())
     {
     {
-        // Check if log mask is not the default value, the selection was a success, and the selected ID was not match, then skip logging
-        if ( g_scsi_log_mask != 0xFF
-            && (SCSI_STS_SELECTION_SUCCEEDED & *SCSI_STS_SELECTED)
-            && (0 == (g_scsi_log_mask & (1 << (*SCSI_STS_SELECTED & 7))))
-           )
-        {
-            return;
-        }
-        log_raw("[", (int)millis(), "ms] DBG ");
         log_raw(params...);
         log_raw(params...);
-        log_raw("\r\n");
+        dbgmsg_end();
     }
     }
 }
 }
 
 
@@ -134,4 +133,4 @@ void dbgmsg_f(const char *format, ...);
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif
-#endif
+#endif