nssilckt.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. /*
  5. ** nssilock.h - Instrumented locking functions for NSS
  6. **
  7. ** Description:
  8. ** nssilock provides instrumentation for locks and monitors in
  9. ** the NSS libraries. The instrumentation, when enabled, causes
  10. ** each call to the instrumented function to record data about
  11. ** the call to an external file. The external file
  12. ** subsequently used to extract performance data and other
  13. ** statistical information about the operation of locks used in
  14. ** the nss library.
  15. **
  16. ** To enable compilation with instrumentation, build NSS with
  17. ** the compile time switch NEED_NSS_ILOCK defined.
  18. **
  19. ** say: "gmake OS_CFLAGS+=-DNEED_NSS_ILOCK" at make time.
  20. **
  21. ** At runtime, to enable recording from nssilock, one or more
  22. ** environment variables must be set. For each nssILockType to
  23. ** be recorded, an environment variable of the form NSS_ILOCK_x
  24. ** must be set to 1. For example:
  25. **
  26. ** set NSS_ILOCK_Cert=1
  27. **
  28. ** nssilock uses PRLOG is used to record to trace data. The
  29. ** PRLogModule name associated with nssilock data is: "nssilock".
  30. ** To enable recording of nssilock data you will need to set the
  31. ** environment variable NSPR_LOG_MODULES to enable
  32. ** recording for the nssilock log module. Similarly, you will
  33. ** need to set the environment variable NSPR_LOG_FILE to specify
  34. ** the filename to receive the recorded data. See prlog.h for usage.
  35. ** Example:
  36. **
  37. ** export NSPR_LOG_MODULES=nssilock:6
  38. ** export NSPR_LOG_FILE=xxxLogfile
  39. **
  40. ** Operation:
  41. ** nssilock wraps calls to NSPR's PZLock and PZMonitor functions
  42. ** with similarly named functions: PZ_NewLock(), etc. When NSS is
  43. ** built with lock instrumentation enabled, the PZ* functions are
  44. ** compiled into NSS; when lock instrumentation is disabled,
  45. ** calls to PZ* functions are directly mapped to PR* functions
  46. ** and the instrumentation arguments to the PZ* functions are
  47. ** compiled away.
  48. **
  49. **
  50. ** File Format:
  51. ** The format of the external file is implementation
  52. ** dependent. Where NSPR's PR_LOG() function is used, the file
  53. ** contains data defined for PR_LOG() plus the data written by
  54. ** the wrapped function. On some platforms and under some
  55. ** circumstances, platform dependent logging or
  56. ** instrumentation probes may be used. In any case, the
  57. ** relevant data provided by the lock instrumentation is:
  58. **
  59. ** lockType, func, address, duration, line, file [heldTime]
  60. **
  61. ** where:
  62. **
  63. ** lockType: a character representation of nssILockType for the
  64. ** call. e.g. ... "cert"
  65. **
  66. ** func: the function doing the tracing. e.g. "NewLock"
  67. **
  68. ** address: address of the instrumented lock or monitor
  69. **
  70. ** duration: is how long was spent in the instrumented function,
  71. ** in PRIntervalTime "ticks".
  72. **
  73. ** line: the line number within the calling function
  74. **
  75. ** file: the file from which the call was made
  76. **
  77. ** heldTime: how long the lock/monitor was held. field
  78. ** present only for PZ_Unlock() and PZ_ExitMonitor().
  79. **
  80. ** Design Notes:
  81. ** The design for lock instrumentation was influenced by the
  82. ** need to gather performance data on NSS 3.x. It is intended
  83. ** that the effort to modify NSS to use lock instrumentation
  84. ** be minimized. Existing calls to locking functions need only
  85. ** have their names changed to the instrumentation function
  86. ** names.
  87. **
  88. ** Private NSS Interface:
  89. ** nssilock.h defines a private interface for use by NSS.
  90. ** nssilock.h is experimental in nature and is subject to
  91. ** change or revocation without notice. ... Don't mess with
  92. ** it.
  93. **
  94. */
  95. /*
  96. * $Id:
  97. */
  98. #ifndef _NSSILCKT_H_
  99. #define _NSSILCKT_H_
  100. #include "utilrename.h"
  101. #include "prtypes.h"
  102. #include "prmon.h"
  103. #include "prlock.h"
  104. #include "prcvar.h"
  105. typedef enum {
  106. nssILockArena = 0,
  107. nssILockSession = 1,
  108. nssILockObject = 2,
  109. nssILockRefLock = 3,
  110. nssILockCert = 4,
  111. nssILockCertDB = 5,
  112. nssILockDBM = 6,
  113. nssILockCache = 7,
  114. nssILockSSL = 8,
  115. nssILockList = 9,
  116. nssILockSlot = 10,
  117. nssILockFreelist = 11,
  118. nssILockOID = 12,
  119. nssILockAttribute = 13,
  120. nssILockPK11cxt = 14, /* pk11context */
  121. nssILockRWLock = 15,
  122. nssILockOther = 16,
  123. nssILockSelfServ = 17,
  124. nssILockKeyDB = 18,
  125. nssILockLast /* don't use this one! */
  126. } nssILockType;
  127. /*
  128. ** conditionally compile in nssilock features
  129. */
  130. #if defined(NEED_NSS_ILOCK)
  131. /*
  132. ** Declare operation type enumerator
  133. ** enumerations identify the function being performed
  134. */
  135. typedef enum {
  136. FlushTT = 0,
  137. NewLock = 1,
  138. Lock = 2,
  139. Unlock = 3,
  140. DestroyLock = 4,
  141. NewCondVar = 5,
  142. WaitCondVar = 6,
  143. NotifyCondVar = 7,
  144. NotifyAllCondVar = 8,
  145. DestroyCondVar = 9,
  146. NewMonitor = 10,
  147. EnterMonitor = 11,
  148. ExitMonitor = 12,
  149. Notify = 13,
  150. NotifyAll = 14,
  151. Wait = 15,
  152. DestroyMonitor = 16
  153. } nssILockOp;
  154. /*
  155. ** Declare the trace record
  156. */
  157. struct pzTrace_s {
  158. PRUint32 threadID; /* PR_GetThreadID() */
  159. nssILockOp op; /* operation being performed */
  160. nssILockType ltype; /* lock type identifier */
  161. PRIntervalTime callTime; /* time spent in function */
  162. PRIntervalTime heldTime; /* lock held time, or -1 */
  163. void *lock; /* address of lock structure */
  164. PRIntn line; /* line number */
  165. char file[24]; /* filename */
  166. };
  167. /*
  168. ** declare opaque types. See: nssilock.c
  169. */
  170. typedef struct pzlock_s PZLock;
  171. typedef struct pzcondvar_s PZCondVar;
  172. typedef struct pzmonitor_s PZMonitor;
  173. #else /* NEED_NSS_ILOCK */
  174. #define PZLock PRLock
  175. #define PZCondVar PRCondVar
  176. #define PZMonitor PRMonitor
  177. #endif /* NEED_NSS_ILOCK */
  178. #endif /* _NSSILCKT_H_ */