nssilock.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 _NSSILOCK_H_
  99. #define _NSSILOCK_H_
  100. #include "utilrename.h"
  101. #include "prtypes.h"
  102. #include "prmon.h"
  103. #include "prlock.h"
  104. #include "prcvar.h"
  105. #include "nssilckt.h"
  106. PR_BEGIN_EXTERN_C
  107. #if defined(NEED_NSS_ILOCK)
  108. #define PZ_NewLock(t) pz_NewLock((t), __FILE__, __LINE__)
  109. extern PZLock *
  110. pz_NewLock(
  111. nssILockType ltype,
  112. char *file,
  113. PRIntn line);
  114. #define PZ_Lock(k) pz_Lock((k), __FILE__, __LINE__)
  115. extern void
  116. pz_Lock(
  117. PZLock *lock,
  118. char *file,
  119. PRIntn line);
  120. #define PZ_Unlock(k) pz_Unlock((k), __FILE__, __LINE__)
  121. extern PRStatus
  122. pz_Unlock(
  123. PZLock *lock,
  124. char *file,
  125. PRIntn line);
  126. #define PZ_DestroyLock(k) pz_DestroyLock((k), __FILE__, __LINE__)
  127. extern void
  128. pz_DestroyLock(
  129. PZLock *lock,
  130. char *file,
  131. PRIntn line);
  132. #define PZ_NewCondVar(l) pz_NewCondVar((l), __FILE__, __LINE__)
  133. extern PZCondVar *
  134. pz_NewCondVar(
  135. PZLock *lock,
  136. char *file,
  137. PRIntn line);
  138. #define PZ_DestroyCondVar(v) pz_DestroyCondVar((v), __FILE__, __LINE__)
  139. extern void
  140. pz_DestroyCondVar(
  141. PZCondVar *cvar,
  142. char *file,
  143. PRIntn line);
  144. #define PZ_WaitCondVar(v, t) pz_WaitCondVar((v), (t), __FILE__, __LINE__)
  145. extern PRStatus
  146. pz_WaitCondVar(
  147. PZCondVar *cvar,
  148. PRIntervalTime timeout,
  149. char *file,
  150. PRIntn line);
  151. #define PZ_NotifyCondVar(v) pz_NotifyCondVar((v), __FILE__, __LINE__)
  152. extern PRStatus
  153. pz_NotifyCondVar(
  154. PZCondVar *cvar,
  155. char *file,
  156. PRIntn line);
  157. #define PZ_NotifyAllCondVar(v) pz_NotifyAllCondVar((v), __FILE__, __LINE__)
  158. extern PRStatus
  159. pz_NotifyAllCondVar(
  160. PZCondVar *cvar,
  161. char *file,
  162. PRIntn line);
  163. #define PZ_NewMonitor(t) pz_NewMonitor((t), __FILE__, __LINE__)
  164. extern PZMonitor *
  165. pz_NewMonitor(
  166. nssILockType ltype,
  167. char *file,
  168. PRIntn line);
  169. #define PZ_DestroyMonitor(m) pz_DestroyMonitor((m), __FILE__, __LINE__)
  170. extern void
  171. pz_DestroyMonitor(
  172. PZMonitor *mon,
  173. char *file,
  174. PRIntn line);
  175. #define PZ_EnterMonitor(m) pz_EnterMonitor((m), __FILE__, __LINE__)
  176. extern void
  177. pz_EnterMonitor(
  178. PZMonitor *mon,
  179. char *file,
  180. PRIntn line);
  181. #define PZ_ExitMonitor(m) pz_ExitMonitor((m), __FILE__, __LINE__)
  182. extern PRStatus
  183. pz_ExitMonitor(
  184. PZMonitor *mon,
  185. char *file,
  186. PRIntn line);
  187. #define PZ_InMonitor(m) (PZ_GetMonitorEntryCount(m) > 0)
  188. #define PZ_GetMonitorEntryCount(m) pz_GetMonitorEntryCount((m), __FILE__, __LINE__)
  189. extern PRIntn
  190. pz_GetMonitorEntryCount(
  191. PZMonitor *mon,
  192. char *file,
  193. PRIntn line);
  194. #define PZ_Wait(m, i) pz_Wait((m), ((i)), __FILE__, __LINE__)
  195. extern PRStatus
  196. pz_Wait(
  197. PZMonitor *mon,
  198. PRIntervalTime ticks,
  199. char *file,
  200. PRIntn line);
  201. #define PZ_Notify(m) pz_Notify((m), __FILE__, __LINE__)
  202. extern PRStatus
  203. pz_Notify(
  204. PZMonitor *mon,
  205. char *file,
  206. PRIntn line);
  207. #define PZ_NotifyAll(m) pz_NotifyAll((m), __FILE__, __LINE__)
  208. extern PRStatus
  209. pz_NotifyAll(
  210. PZMonitor *mon,
  211. char *file,
  212. PRIntn line);
  213. #define PZ_TraceFlush() pz_TraceFlush()
  214. extern void pz_TraceFlush(void);
  215. #else /* NEED_NSS_ILOCK */
  216. #define PZ_NewLock(t) PR_NewLock()
  217. #define PZ_DestroyLock(k) PR_DestroyLock((k))
  218. #define PZ_Lock(k) PR_Lock((k))
  219. #define PZ_Unlock(k) PR_Unlock((k))
  220. #define PZ_NewCondVar(l) PR_NewCondVar((l))
  221. #define PZ_DestroyCondVar(v) PR_DestroyCondVar((v))
  222. #define PZ_WaitCondVar(v, t) PR_WaitCondVar((v), (t))
  223. #define PZ_NotifyCondVar(v) PR_NotifyCondVar((v))
  224. #define PZ_NotifyAllCondVar(v) PR_NotifyAllCondVar((v))
  225. #define PZ_NewMonitor(t) PR_NewMonitor()
  226. #define PZ_DestroyMonitor(m) PR_DestroyMonitor((m))
  227. #define PZ_EnterMonitor(m) PR_EnterMonitor((m))
  228. #define PZ_ExitMonitor(m) PR_ExitMonitor((m))
  229. #define PZ_InMonitor(m) PR_InMonitor((m))
  230. #define PZ_Wait(m, t) PR_Wait(((m)), ((t)))
  231. #define PZ_Notify(m) PR_Notify((m))
  232. #define PZ_NotifyAll(m) PR_Notify((m))
  233. #define PZ_TraceFlush() /* nothing */
  234. #endif /* NEED_NSS_ILOCK */
  235. PR_END_EXTERN_C
  236. #endif /* _NSSILOCK_H_ */