[PATCH] Millisecond timestamping

Raphaël Assénat raph at 8d.com
Fri Sep 2 19:20:20 UTC 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

As I was considering adding timestamping support to minicom, I noticed 
this feature has already been commited earlier this year! It works great,
but I need greater resolution. I intend to track where time is spent 
by a booting embedded system.

I have therefore added a fourth mode toggled by CTRL+A N. I think this change
could be useful to other users as well. Please review and consider applying.

Sample output:

[2011-09-02 15:10:50.135] I2C:   ready
[2011-09-02 15:10:50.139] DRAM:  128 MB
[2011-09-02 15:10:50.199] NAND:  256 MiB
[2011-09-02 15:10:50.775] In:    serial
[2011-09-02 15:10:50.775] Out:   serial
[2011-09-02 15:10:50.775] Err:   serial
[2011-09-02 15:10:50.995] Die ID #4482000100000000015da3960b008008

Best regards,
Raphaël Assénat


Signed-off-by: raph at 8d.com
diff -Nru minicom/src/minicom.c minicom-edit/src/minicom.c
- --- minicom/src/minicom.c	2011-09-02 11:26:02.000000000 -0400
+++ minicom-edit/src/minicom.c	2011-09-02 14:59:40.000000000 -0400
@@ -23,6 +23,7 @@
  *				command line
  * jl  09.07.98 added option -S to start a script at startup
  * mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
+ * raph at 8d.com 02/09/11 - Added millisecond timestamping option
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -876,7 +877,7 @@
 static void toggle_line_timestamp(void)
 {
   ++line_timestamp;
- -  line_timestamp %= 3;
+  line_timestamp %= 4;
   set_line_timestamp(line_timestamp);
 }
 
@@ -1570,6 +1571,9 @@
           case 2:
             s = _("Timestamp lines every second");
             break;
+          case 3:
+            s = _("Timestamp every line (millisecond)");
+            break;
           }
         status_set_display(s, 0);
         break;
diff -Nru minicom/src/vt100.c minicom-edit/src/vt100.c
- --- minicom/src/vt100.c	2011-09-02 11:26:02.000000000 -0400
+++ minicom-edit/src/vt100.c	2011-09-02 15:00:16.000000000 -0400
@@ -22,6 +22,7 @@
  * // jl 04.09.97 character map conversions in and out
  *    jl 06.07.98 use conversion tables with the capture file
  *    mark.einon at gmail.com 16/02/11 - Added option to timestamp terminal output
+ *    raph at 8d.com 02/09/11 - Added millisecond timestamping option
  */
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -893,23 +894,27 @@
 
   if (last_ch == '\n' && vt_line_timestamp)
     {
- -      time_t tmstmp_now;
       static time_t tmstmp_last;
       char tmstmp_str[36];
       struct tm tmstmp_tm;
+      struct timeval tv_now;
 
- -      time(&tmstmp_now);
- -      if (vt_line_timestamp == 1
- -          || tmstmp_now != tmstmp_last)
+      gettimeofday(&tv_now, NULL);
+      if ((vt_line_timestamp == 1) || (vt_line_timestamp == 3)
+          || tv_now.tv_sec != tmstmp_last)
         {
- -          if (   localtime_r(&tmstmp_now, &tmstmp_tm)
+          if (   localtime_r(&tv_now.tv_sec, &tmstmp_tm)
               && strftime(tmstmp_str, sizeof(tmstmp_str),
- -                          "[%F %T]", &tmstmp_tm))
+                          "[%F %T", &tmstmp_tm))
             {
               output_s(tmstmp_str);
- -              output_s(vt_line_timestamp == 2 ? "\r\n" : " ");
+              if (vt_line_timestamp == 3) {
+				  sprintf(tmstmp_str, ".%03ld", tv_now.tv_usec / 1000);
+				  output_s(tmstmp_str);
+			  }
+              output_s(vt_line_timestamp == 2 ? "]\r\n" : "] ");
             }
- -          tmstmp_last = tmstmp_now;
+          tmstmp_last = tv_now.tv_sec;
         }
     }
 
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)

iEYEARECAAYFAk5hLHQACgkQu3aLmFcr6L3iawCg4oc8+77nXShaKXMn5vfvjW+A
5YgAoLKAtfVzyZGy/rSgx9coAbZAE5d5
=/stu
-----END PGP SIGNATURE-----



More information about the minicom-devel mailing list