[Pcsclite-cvs-commit] r5126 - /trunk/PCSC/src/winscard_clnt.c
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Fri Aug 13 12:41:31 UTC 2010
Author: rousseau
Date: Fri Aug 13 12:41:29 2010
New Revision: 5126
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=5126
Log:
Revert changeset 5102 to add profiling on the client side again.
ltrace(1) can't be used with a dynamically loaded (dlopen(3)) library like
it is the case with the majority of PKCS#11 client application.
Modified:
trunk/PCSC/src/winscard_clnt.c
Modified: trunk/PCSC/src/winscard_clnt.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/winscard_clnt.c?rev=5126&op=diff
==============================================================================
--- trunk/PCSC/src/winscard_clnt.c (original)
+++ trunk/PCSC/src/winscard_clnt.c Fri Aug 13 12:41:29 2010
@@ -110,6 +110,95 @@
static char sharing_shall_block = TRUE;
+#undef DO_PROFILE
+#ifdef DO_PROFILE
+
+#define PROFILE_FILE "/tmp/pcsc_profile"
+#include <stdio.h>
+#include <sys/time.h>
+
+struct timeval profile_time_start;
+FILE *profile_fd;
+char profile_tty;
+char fct_name[100];
+
+#define PROFILE_START profile_start(__FUNCTION__);
+#define PROFILE_END(rv) profile_end(__FUNCTION__, rv);
+
+static void profile_start(const char *f)
+{
+ static char initialized = FALSE;
+
+ if (!initialized)
+ {
+ char filename[80];
+
+ initialized = TRUE;
+ sprintf(filename, "%s-%d", PROFILE_FILE, getuid());
+ profile_fd = fopen(filename, "a+");
+ if (NULL == profile_fd)
+ {
+ fprintf(stderr, "\33[01;31mCan't open %s: %s\33[0m\n",
+ PROFILE_FILE, strerror(errno));
+ exit(-1);
+ }
+ fprintf(profile_fd, "\nStart a new profile\n");
+
+ if (isatty(fileno(stderr)))
+ profile_tty = TRUE;
+ else
+ profile_tty = FALSE;
+ }
+
+ /* PROFILE_END was not called before? */
+ if (profile_tty && fct_name[0])
+ printf("\33[01;34m WARNING: %s starts before %s finishes\33[0m\n",
+ f, fct_name);
+
+ strlcpy(fct_name, f, sizeof(fct_name));
+
+ gettimeofday(&profile_time_start, NULL);
+} /* profile_start */
+
+static void profile_end(const char *f, LONG rv)
+{
+ struct timeval profile_time_end;
+ long d;
+
+ gettimeofday(&profile_time_end, NULL);
+ d = time_sub(&profile_time_end, &profile_time_start);
+
+ if (profile_tty)
+ {
+ if (fct_name[0])
+ {
+ if (strncmp(fct_name, f, sizeof(fct_name)))
+ printf("\33[01;34m WARNING: %s ends before %s\33[0m\n",
+ f, fct_name);
+ }
+ else
+ printf("\33[01;34m WARNING: %s ends but we lost its start\33[0m\n",
+ f);
+
+ /* allow to detect missing PROFILE_END calls */
+ fct_name[0] = '\0';
+
+ if (rv != SCARD_S_SUCCESS)
+ fprintf(stderr,
+ "\33[01;31mRESULT %s \33[35m%ld \33[34m0x%08lX %s\33[0m\n",
+ f, d, rv, pcsc_stringify_error(rv));
+ else
+ fprintf(stderr, "\33[01;31mRESULT %s \33[35m%ld\33[0m\n", f, d);
+ }
+ fprintf(profile_fd, "%s %ld\n", f, d);
+ fflush(profile_fd);
+} /* profile_end */
+
+#else
+#define PROFILE_START
+#define PROFILE_END(rv)
+#endif
+
/**
* Represents an Application Context Channel.
* A channel belongs to an Application Context (\c _psContextMap).
@@ -301,6 +390,8 @@
int daemon_launched = FALSE;
int retries = 0;
+ PROFILE_START
+
again:
/* Check if the server is running */
rv = SCardCheckDaemonAvailability();
@@ -387,6 +478,8 @@
}
end:
+ PROFILE_END(rv)
+
return rv;
}
@@ -569,6 +662,8 @@
struct release_struct scReleaseStruct;
SCONTEXTMAP * currentContextMap;
+ PROFILE_START
+
CHECK_SAME_PROCESS
/*
@@ -577,7 +672,10 @@
*/
currentContextMap = SCardGetContext(hContext);
if (NULL == currentContextMap)
+ {
+ PROFILE_END(SCARD_E_INVALID_HANDLE)
return SCARD_E_INVALID_HANDLE;
+ }
(void)pthread_mutex_lock(currentContextMap->mMutex);
@@ -625,6 +723,8 @@
(void)SCardLockThread();
(void)SCardRemoveContext(hContext);
(void)SCardUnlockThread();
+
+ PROFILE_END(rv)
return rv;
}
@@ -720,6 +820,8 @@
struct connect_struct scConnectStruct;
SCONTEXTMAP * currentContextMap;
+ PROFILE_START
+
/*
* Check for NULL parameters
*/
@@ -802,6 +904,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -888,6 +992,8 @@
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+ PROFILE_START
+
if (pdwActiveProtocol == NULL)
return SCARD_E_INVALID_PARAMETER;
@@ -958,6 +1064,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -1000,6 +1108,8 @@
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+ PROFILE_START
+
CHECK_SAME_PROCESS
/*
@@ -1054,6 +1164,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -1101,6 +1213,8 @@
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+ PROFILE_START
+
CHECK_SAME_PROCESS
/*
@@ -1161,6 +1275,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -1213,6 +1329,8 @@
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+ PROFILE_START
+
/*
* Zero out everything
*/
@@ -1276,6 +1394,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+ PROFILE_END(rv)
+
return rv;
}
@@ -1291,6 +1411,8 @@
struct cancel_transaction_struct scCancelStruct;
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+
+ PROFILE_START
CHECK_SAME_PROCESS
@@ -1340,6 +1462,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -1448,6 +1572,8 @@
LPBYTE bufAtr = NULL;
DWORD dummy;
+ PROFILE_START
+
/* default output values */
if (pdwState)
*pdwState = 0;
@@ -1630,6 +1756,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -1740,6 +1868,8 @@
SCONTEXTMAP * currentContextMap;
int currentReaderCount = 0;
LONG rv = SCARD_S_SUCCESS;
+
+ PROFILE_START
if ((rgReaderStates == NULL && cReaders > 0)
|| (cReaders > PCSCLITE_MAX_READERS_CONTEXTS))
@@ -2185,6 +2315,8 @@
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+ PROFILE_END(rv)
+
return rv;
}
@@ -2250,6 +2382,8 @@
SCONTEXTMAP * currentContextMap;
CHANNEL_MAP * pChannelMap;
+ PROFILE_START
+
/* 0 bytes received by default */
if (NULL != lpBytesReturned)
*lpBytesReturned = 0;
@@ -2262,7 +2396,10 @@
rv = SCardGetContextAndChannelFromHandle(hCard, ¤tContextMap,
&pChannelMap);
if (rv == -1)
+ {
+ PROFILE_END(SCARD_E_INVALID_HANDLE)
return SCARD_E_INVALID_HANDLE;
+ }
(void)pthread_mutex_lock(currentContextMap->mMutex);
@@ -2340,6 +2477,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -2454,6 +2593,8 @@
LONG ret;
unsigned char *buf = NULL;
+ PROFILE_START
+
if (NULL == pcbAttrLen)
return SCARD_E_INVALID_PARAMETER;
@@ -2481,6 +2622,8 @@
ret = SCardGetSetAttrib(hCard, SCARD_GET_ATTRIB, dwAttrId, buf,
pcbAttrLen);
+
+ PROFILE_END(ret)
return ret;
}
@@ -2621,6 +2764,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -2693,6 +2838,8 @@
CHANNEL_MAP * pChannelMap;
struct transmit_struct scTransmitStruct;
+ PROFILE_START
+
if (pbSendBuffer == NULL || pbRecvBuffer == NULL ||
pcbRecvLength == NULL || pioSendPci == NULL)
return SCARD_E_INVALID_PARAMETER;
@@ -2707,6 +2854,7 @@
if (rv == -1)
{
*pcbRecvLength = 0;
+ PROFILE_END(SCARD_E_INVALID_HANDLE)
return SCARD_E_INVALID_HANDLE;
}
@@ -2812,6 +2960,8 @@
end:
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -2876,6 +3026,7 @@
char *buf = NULL;
(void)mszGroups;
+ PROFILE_START
/*
* Check for NULL parameters
@@ -2890,7 +3041,10 @@
*/
currentContextMap = SCardGetContext(hContext);
if (NULL == currentContextMap)
+ {
+ PROFILE_END(SCARD_E_INVALID_HANDLE)
return SCARD_E_INVALID_HANDLE;
+ }
(void)pthread_mutex_lock(currentContextMap->mMutex);
@@ -2970,6 +3124,8 @@
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+ PROFILE_END(rv)
+
return rv;
}
@@ -2991,6 +3147,8 @@
LONG rv = SCARD_S_SUCCESS;
SCONTEXTMAP * currentContextMap;
+ PROFILE_START
+
CHECK_SAME_PROCESS
/*
@@ -3001,6 +3159,8 @@
return SCARD_E_INVALID_HANDLE;
free((void *)pvMem);
+
+ PROFILE_END(rv)
return rv;
}
@@ -3062,6 +3222,8 @@
LONG rv = SCARD_S_SUCCESS;
SCONTEXTMAP * currentContextMap;
char *buf = NULL;
+
+ PROFILE_START
/* Multi-string with two trailing \0 */
const char ReaderGroup[] = "SCard$DefaultReaders\0";
@@ -3119,6 +3281,8 @@
*pcchGroups = dwGroups;
(void)pthread_mutex_unlock(currentContextMap->mMutex);
+
+ PROFILE_END(rv)
return rv;
}
@@ -3159,6 +3323,8 @@
uint32_t dwClientID = 0;
struct cancel_struct scCancelStruct;
+ PROFILE_START
+
/*
* Make sure this context has been opened
*/
@@ -3203,6 +3369,8 @@
ClientCloseSession(dwClientID);
error:
+ PROFILE_END(rv)
+
return rv;
}
@@ -3234,6 +3402,8 @@
LONG rv;
SCONTEXTMAP * currentContextMap;
+ PROFILE_START
+
rv = SCARD_S_SUCCESS;
/* Check if the _same_ server is running */
@@ -3245,6 +3415,8 @@
currentContextMap = SCardGetContext(hContext);
if (currentContextMap == NULL)
rv = SCARD_E_INVALID_HANDLE;
+
+ PROFILE_END(rv)
return rv;
}
More information about the Pcsclite-cvs-commit
mailing list