You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2023/01/02 12:56:11 UTC

[GitHub] [nuttx] Gary-Hobson commented on a diff in pull request #8012: optimize syslog speed

Gary-Hobson commented on code in PR #8012:
URL: https://github.com/apache/nuttx/pull/8012#discussion_r1060016772


##########
drivers/syslog/vsyslog.c:
##########
@@ -67,6 +67,8 @@ static FAR const char * g_priority_str[] =
 int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
 {
   struct lib_syslogstream_s stream;
+  char buffer[128];

Review Comment:
   done



##########
drivers/syslog/vsyslog.c:
##########
@@ -166,66 +168,66 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
   switch (priority)
     {
       case LOG_EMERG:   /* Red, Bold, Blinking */
-        ret += lib_sprintf(&stream.public, "\e[31;1;5m");
+        offset += sprintf(offset, "\e[31;1;5m");

Review Comment:
   done



##########
drivers/syslog/vsyslog.c:
##########
@@ -166,66 +168,66 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap)
   switch (priority)
     {
       case LOG_EMERG:   /* Red, Bold, Blinking */
-        ret += lib_sprintf(&stream.public, "\e[31;1;5m");
+        offset += sprintf(offset, "\e[31;1;5m");
         break;
 
       case LOG_ALERT:   /* Red, Bold */
-        ret += lib_sprintf(&stream.public, "\e[31;1m");
+        offset += sprintf(offset, "\e[31;1m");
         break;
 
       case LOG_CRIT:    /* Red, Bold */
-        ret += lib_sprintf(&stream.public, "\e[31;1m");
+        offset += sprintf(offset, "\e[31;1m");
         break;
 
       case LOG_ERR:     /* Red */
-        ret += lib_sprintf(&stream.public, "\e[31m");
+        offset += sprintf(offset, "\e[31m");
         break;
 
       case LOG_WARNING: /* Yellow */
-        ret += lib_sprintf(&stream.public, "\e[33m");
+        offset += sprintf(offset, "\e[33m");
         break;
 
       case LOG_NOTICE:  /* Bold */
-        ret += lib_sprintf(&stream.public, "\e[1m");
+        offset += sprintf(offset, "\e[1m");
         break;
 
       case LOG_INFO:    /* Normal */
         break;
 
       case LOG_DEBUG:   /* Dim */
-        ret += lib_sprintf(&stream.public, "\e[2m");
+        offset += sprintf(offset, "\e[2m");
         break;
     }
 #endif
 
 #if defined(CONFIG_SYSLOG_PRIORITY)
   /* Prepend the message priority. */
 
-  ret += lib_sprintf(&stream.public, "[%6s] ", g_priority_str[priority]);
+  offset += sprintf(offset, "[%6s] ", g_priority_str[priority]);
 #endif
 
 #if defined(CONFIG_SYSLOG_PREFIX)
   /* Prepend the prefix, if available */
 
-  ret += lib_sprintf(&stream.public, "[%s] ", CONFIG_SYSLOG_PREFIX_STRING);
+  offset += sprintf(offset, "[%s] ", CONFIG_SYSLOG_PREFIX_STRING);
 #endif
 
 #if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME)
   /* Prepend the thread name */
 
   tcb = nxsched_get_tcb(gettid());
-  ret += lib_sprintf(&stream.public, "%s: ",
-                     (tcb != NULL) ? tcb->name : "(null)");
+  offset += sprintf(offset, "%s: ", (tcb != NULL) ? tcb->name : "(null)");

Review Comment:
   It's a good idea, but I recommend doing it in a separate PR



##########
libs/libc/stream/lib_syslogstream.c:
##########
@@ -103,6 +102,37 @@ static void syslogstream_addchar(FAR struct lib_syslogstream_s *stream,
       syslogstream_flush(stream);
     }
 }
+
+int syslogstream_addstring(FAR struct lib_syslogstream_s *stream,
+                           FAR const char *buff, int len)
+{
+  FAR struct iob_s *iob = stream->iob;
+  uint16_t ret = 0;

Review Comment:
   iob->io_len is uint16,  but using int is better



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org