[Pcsclite-cvs-commit] r2368 - trunk/PCSC/src
Ludovic Rousseau
rousseau at alioth.debian.org
Wed Jan 31 10:18:04 CET 2007
Author: rousseau
Date: 2007-01-31 10:18:04 +0100 (Wed, 31 Jan 2007)
New Revision: 2368
Modified:
trunk/PCSC/src/winscard.c
Log:
add profiling framework on the server side
Modified: trunk/PCSC/src/winscard.c
===================================================================
--- trunk/PCSC/src/winscard.c 2007-01-31 09:08:11 UTC (rev 2367)
+++ trunk/PCSC/src/winscard.c 2007-01-31 09:18:04 UTC (rev 2368)
@@ -94,6 +94,89 @@
#include "sys_generic.h"
#include "eventhandler.h"
+#undef DO_PROFILE
+#ifdef DO_PROFILE
+
+#ifndef FALSE
+#define FALSE 0
+#define TRUE 1
+#endif
+
+#define PROFILE_FILE "/tmp/pcscd_profile"
+#include <stdio.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <unistd.h>
+
+struct timeval profile_time_start;
+FILE *fd;
+char profile_tty;
+
+#define PROFILE_START profile_start(__FUNCTION__);
+#define PROFILE_END profile_end(__FUNCTION__, __LINE__);
+
+static void profile_start(const char *f)
+{
+ static char initialized = FALSE;
+
+ if (!initialized)
+ {
+ initialized = TRUE;
+ fd = fopen(PROFILE_FILE, "a+");
+ if (NULL == fd)
+ {
+ fprintf(stderr, "\33[01;31mCan't open %s: %s\33[0m\n",
+ PROFILE_FILE, strerror(errno));
+ exit(-1);
+ }
+ fprintf(fd, "\nStart a new profile\n");
+ fflush(fd);
+
+ if (isatty(fileno(stderr)))
+ profile_tty = TRUE;
+ else
+ profile_tty = FALSE;
+ }
+
+ gettimeofday(&profile_time_start, NULL);
+} /* profile_start */
+
+/* r = a - b */
+static long int time_sub(struct timeval *a, struct timeval *b)
+{
+ struct timeval r;
+ r.tv_sec = a -> tv_sec - b -> tv_sec;
+ r.tv_usec = a -> tv_usec - b -> tv_usec;
+ if (r.tv_usec < 0)
+ {
+ r.tv_sec--;
+ r.tv_usec += 1000000;
+ }
+
+ return r.tv_sec * 1000000 + r.tv_usec;
+} /* time_sub */
+
+
+static void profile_end(const char *f, int line)
+{
+ struct timeval profile_time_end;
+ long d;
+
+ gettimeofday(&profile_time_end, NULL);
+ d = time_sub(&profile_time_end, &profile_time_start);
+
+ if (profile_tty)
+ fprintf(stderr, "\33[01;31mRESULT %s \33[35m%ld\33[0m (%d)\n", f, d,
+ line);
+ fprintf(fd, "%s %ld\n", f, d);
+ fflush(fd);
+} /* profile_end */
+
+#else
+#define PROFILE_START
+#define PROFILE_END
+#endif
+
/** used for backward compatibility */
#define SCARD_PROTOCOL_ANY_OLD 0x1000
@@ -190,6 +273,8 @@
PREADER_CONTEXT rContext = NULL;
DWORD dwStatus;
+ PROFILE_START
+
/*
* Check for NULL parameters
*/
@@ -400,6 +485,9 @@
rContext->dwContexts -= 1;
*phCard = 0;
+
+ PROFILE_END
+
return SCARD_F_INTERNAL_ERROR;
}
@@ -408,6 +496,8 @@
*/
SYS_USleep(PCSCLITE_STATUS_POLL_RATE + 10);
+ PROFILE_END
+
return SCARD_S_SUCCESS;
}
More information about the Pcsclite-cvs-commit
mailing list