[Pcsclite-cvs-commit] r2633 - /trunk/PCSC/src/debuglog.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Wed Oct 3 13:53:06 UTC 2007
Author: rousseau
Date: Wed Oct 3 13:53:06 2007
New Revision: 2633
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=2633
Log:
display time delta between two lines of logs when printed to stderr
Modified:
trunk/PCSC/src/debuglog.c
Modified: trunk/PCSC/src/debuglog.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/debuglog.c?rev=2633&op=diff
==============================================================================
--- trunk/PCSC/src/debuglog.c (original)
+++ trunk/PCSC/src/debuglog.c Wed Oct 3 13:53:06 2007
@@ -25,6 +25,8 @@
#include <stdarg.h>
#include <assert.h>
#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
#include "pcsclite.h"
#include "misc.h"
@@ -84,6 +86,11 @@
if (LogDoColor)
{
const char *color_pfx = "", *color_sfx = "\33[0m";
+ const char *time_pfx = "\33[36m", *time_sfx = color_sfx;
+ static struct timeval last_time = { 0, 0 };
+ struct timeval new_time = { 0, 0 };
+ struct timeval tmp;
+ int delta;
switch (priority)
{
@@ -104,7 +111,23 @@
color_sfx = "";
break;
}
- fprintf(stderr, "%s%s%s\n", color_pfx, DebugBuffer, color_sfx);
+
+ gettimeofday(&new_time, NULL);
+ if (0 == last_time.tv_sec)
+ last_time = new_time;
+
+ tmp.tv_sec = new_time.tv_sec - last_time.tv_sec;
+ tmp.tv_usec = new_time.tv_usec - last_time.tv_usec;
+ if (tmp.tv_usec < 0)
+ {
+ tmp.tv_sec--;
+ tmp.tv_usec += 1000000;
+ }
+ delta = tmp.tv_sec * 1000000 + tmp.tv_usec;
+
+ fprintf(stderr, "%s%.8d%s %s%s%s\n", time_pfx, delta, time_sfx,
+ color_pfx, DebugBuffer, color_sfx);
+ last_time = new_time;
}
else
fprintf(stderr, "%s\n", DebugBuffer);
More information about the Pcsclite-cvs-commit
mailing list