nsprpub/pr/include/prtrace.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef prtrace_h___
michael@0 7 #define prtrace_h___
michael@0 8 /*
michael@0 9 ** prtrace.h -- NSPR's Trace Facility.
michael@0 10 **
michael@0 11 ** The Trace Facility provides a means to trace application
michael@0 12 ** program events within a process. When implementing an
michael@0 13 ** application program an engineer may insert a "Trace" function
michael@0 14 ** call, passing arguments to be traced. The "Trace" function
michael@0 15 ** combines the user trace data with identifying data and
michael@0 16 ** writes this data in time ordered sequence into a circular
michael@0 17 ** in-memory buffer; when the buffer fills, it wraps.
michael@0 18 **
michael@0 19 ** Functions are provided to set and/or re-configure the size of
michael@0 20 ** the trace buffer, control what events are recorded in the
michael@0 21 ** buffer, enable and disable tracing based on specific user
michael@0 22 ** supplied data and other control functions. Methods are provided
michael@0 23 ** to record the trace entries in the in-memory trace buffer to
michael@0 24 ** a file.
michael@0 25 **
michael@0 26 ** Tracing may cause a performance degredation to the application
michael@0 27 ** depending on the number and placement of calls to the tracing
michael@0 28 ** facility. When tracing is compiled in and all tracing is
michael@0 29 ** disabled via the runtime controls, the overhead should be
michael@0 30 ** minimal. ... Famous last words, eh?
michael@0 31 **
michael@0 32 ** When DEBUG is defined at compile time, the Trace Facility is
michael@0 33 ** compiled as part of NSPR and any application using NSPR's
michael@0 34 ** header files will have tracing compiled in. When DEBUG is not
michael@0 35 ** defined, the Trace Facility is not compiled into NSPR nor
michael@0 36 ** exported in its header files. If the Trace Facility is
michael@0 37 ** desired in a non-debug build, then FORCE_NSPR_TRACE may be
michael@0 38 ** defined at compile time for both the optimized build of NSPR
michael@0 39 ** and the application. NSPR and any application using NSPR's
michael@0 40 ** Trace Facility must be compiled with the same level of trace
michael@0 41 ** conditioning or unresolved references may be realized at link
michael@0 42 ** time.
michael@0 43 **
michael@0 44 ** For any of the Trace Facility methods that requires a trace
michael@0 45 ** handle as an input argument, the caller must ensure that the
michael@0 46 ** trace handle argument is valid. An invalid trace handle
michael@0 47 ** argument may cause unpredictable results.
michael@0 48 **
michael@0 49 ** Trace Facility methods are thread-safe and SMP safe.
michael@0 50 **
michael@0 51 ** Users of the Trace Facility should use the defined macros to
michael@0 52 ** invoke trace methods, not the function calls directly. e.g.
michael@0 53 ** PR_TRACE( h1,0,1,2, ...); not PR_Trace(h1,0,1,2, ...);
michael@0 54 **
michael@0 55 ** Application designers should be aware of the effects of
michael@0 56 ** debug and optimized build differences when using result of the
michael@0 57 ** Trace Facility macros in expressions.
michael@0 58 **
michael@0 59 ** See Also: prcountr.h
michael@0 60 **
michael@0 61 ** /lth. 08-Jun-1998.
michael@0 62 */
michael@0 63
michael@0 64 #include "prtypes.h"
michael@0 65 #include "prthread.h"
michael@0 66 #include "prtime.h"
michael@0 67
michael@0 68 PR_BEGIN_EXTERN_C
michael@0 69
michael@0 70 /*
michael@0 71 ** Opaque type for the trace handle
michael@0 72 ** ... Don't even think about looking in here.
michael@0 73 **
michael@0 74 */
michael@0 75 typedef void * PRTraceHandle;
michael@0 76
michael@0 77 /*
michael@0 78 ** PRTraceEntry -- A trace entry in the in-memory trace buffer
michael@0 79 ** looks like this.
michael@0 80 **
michael@0 81 */
michael@0 82 typedef struct PRTraceEntry
michael@0 83 {
michael@0 84 PRThread *thread; /* The thread creating the trace entry */
michael@0 85 PRTraceHandle handle; /* PRTraceHandle creating the trace entry */
michael@0 86 PRTime time; /* Value of PR_Now() at time of trace entry */
michael@0 87 PRUint32 userData[8]; /* user supplied trace data */
michael@0 88 } PRTraceEntry;
michael@0 89
michael@0 90 /*
michael@0 91 ** PRTraceOption -- command operands to
michael@0 92 ** PR_[Set|Get]TraceOption(). See descriptive meanings there.
michael@0 93 **
michael@0 94 */
michael@0 95 typedef enum PRTraceOption
michael@0 96 {
michael@0 97 PRTraceBufSize,
michael@0 98 PRTraceEnable,
michael@0 99 PRTraceDisable,
michael@0 100 PRTraceSuspend,
michael@0 101 PRTraceResume,
michael@0 102 PRTraceSuspendRecording,
michael@0 103 PRTraceResumeRecording,
michael@0 104 PRTraceLockHandles,
michael@0 105 PRTraceUnLockHandles,
michael@0 106 PRTraceStopRecording
michael@0 107 } PRTraceOption;
michael@0 108
michael@0 109 /* -----------------------------------------------------------------------
michael@0 110 ** FUNCTION: PR_DEFINE_TRACE() -- Define a PRTraceHandle
michael@0 111 **
michael@0 112 ** DESCRIPTION: PR_DEFINE_TRACE() is used to define a trace
michael@0 113 ** handle.
michael@0 114 **
michael@0 115 */
michael@0 116 #define PR_DEFINE_TRACE(name) PRTraceHandle name
michael@0 117
michael@0 118 /* -----------------------------------------------------------------------
michael@0 119 ** FUNCTION: PR_INIT_TRACE_HANDLE() -- Set the value of a PRTraceHandle
michael@0 120 **
michael@0 121 ** DESCRIPTION:
michael@0 122 ** PR_INIT_TRACE_HANDLE() sets the value of a PRTraceHandle
michael@0 123 ** to value. e.g. PR_INIT_TRACE_HANDLE( myHandle, NULL );
michael@0 124 **
michael@0 125 */
michael@0 126 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 127 #define PR_INIT_TRACE_HANDLE(handle,value)\
michael@0 128 (handle) = (PRCounterHandle)(value)
michael@0 129 #else
michael@0 130 #define PR_INIT_TRACE_HANDLE(handle,value)
michael@0 131 #endif
michael@0 132
michael@0 133
michael@0 134 /* -----------------------------------------------------------------------
michael@0 135 ** FUNCTION: PR_CreateTrace() -- Create a trace handle
michael@0 136 **
michael@0 137 ** DESCRIPTION:
michael@0 138 ** PR_CreateTrace() creates a new trace handle. Tracing is
michael@0 139 ** enabled for this handle when it is created. The trace handle
michael@0 140 ** is intended for use in other Trace Facility calls.
michael@0 141 **
michael@0 142 ** PR_CreateTrace() registers the QName, RName and description
michael@0 143 ** data so that this data can be retrieved later.
michael@0 144 **
michael@0 145 ** INPUTS:
michael@0 146 ** qName: pointer to string. QName for this trace handle.
michael@0 147 **
michael@0 148 ** rName: pointer to string. RName for this trace handle.
michael@0 149 **
michael@0 150 ** description: pointer to string. Descriptive data about this
michael@0 151 ** trace handle.
michael@0 152 **
michael@0 153 ** OUTPUTS:
michael@0 154 ** Creates the trace handle.
michael@0 155 ** Registers the QName and RName with the trace facility.
michael@0 156 **
michael@0 157 ** RETURNS:
michael@0 158 ** PRTraceHandle
michael@0 159 **
michael@0 160 ** RESTRICTIONS:
michael@0 161 ** qName is limited to 31 characters.
michael@0 162 ** rName is limited to 31 characters.
michael@0 163 ** description is limited to 255 characters.
michael@0 164 **
michael@0 165 */
michael@0 166 #define PRTRACE_NAME_MAX 31
michael@0 167 #define PRTRACE_DESC_MAX 255
michael@0 168
michael@0 169 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 170 #define PR_CREATE_TRACE(handle,qName,rName,description)\
michael@0 171 (handle) = PR_CreateTrace((qName),(rName),(description))
michael@0 172 #else
michael@0 173 #define PR_CREATE_TRACE(handle,qName,rName,description)
michael@0 174 #endif
michael@0 175
michael@0 176 NSPR_API(PRTraceHandle)
michael@0 177 PR_CreateTrace(
michael@0 178 const char *qName, /* QName for this trace handle */
michael@0 179 const char *rName, /* RName for this trace handle */
michael@0 180 const char *description /* description for this trace handle */
michael@0 181 );
michael@0 182
michael@0 183
michael@0 184 /* -----------------------------------------------------------------------
michael@0 185 ** FUNCTION: PR_DestroyTrace() -- Destroy a trace handle
michael@0 186 **
michael@0 187 ** DESCRIPTION:
michael@0 188 ** PR_DestroyTrace() removes the referenced trace handle and
michael@0 189 ** associated QName, RName and description data from the Trace
michael@0 190 ** Facility.
michael@0 191 **
michael@0 192 ** INPUTS: handle. A PRTraceHandle
michael@0 193 **
michael@0 194 ** OUTPUTS:
michael@0 195 ** The trace handle is unregistered.
michael@0 196 ** The QName, RName and description are removed.
michael@0 197 **
michael@0 198 ** RETURNS: void
michael@0 199 **
michael@0 200 ** RESTRICTIONS:
michael@0 201 **
michael@0 202 */
michael@0 203 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 204 #define PR_DESTROY_TRACE(handle)\
michael@0 205 PR_DestroyTrace((handle))
michael@0 206 #else
michael@0 207 #define PR_DESTROY_TRACE(handle)
michael@0 208 #endif
michael@0 209
michael@0 210 NSPR_API(void)
michael@0 211 PR_DestroyTrace(
michael@0 212 PRTraceHandle handle /* Handle to be destroyed */
michael@0 213 );
michael@0 214
michael@0 215
michael@0 216 /* -----------------------------------------------------------------------
michael@0 217 ** FUNCTION: PR_Trace() -- Make a trace entry in the in-memory trace
michael@0 218 **
michael@0 219 ** DESCRIPTION:
michael@0 220 ** PR_Trace() makes an entry in the in-memory trace buffer for
michael@0 221 ** the referenced trace handle. The next logically available
michael@0 222 ** PRTraceEntry is used; when the next trace entry would overflow
michael@0 223 ** the trace table, the table wraps.
michael@0 224 **
michael@0 225 ** PR_Trace() for a specific trace handle may be disabled by
michael@0 226 ** calling PR_SetTraceOption() specifying PRTraceDisable for the
michael@0 227 ** trace handle to be disabled.
michael@0 228 **
michael@0 229 ** INPUTS:
michael@0 230 ** handle: PRTraceHandle. The trace handle for this trace.
michael@0 231 **
michael@0 232 ** userData[0..7]: unsigned 32bit integers. user supplied data
michael@0 233 ** that is copied into the PRTraceEntry
michael@0 234 **
michael@0 235 ** OUTPUTS:
michael@0 236 ** A PRTraceEntry is (conditionally) formatted in the in-memory
michael@0 237 ** trace buffer.
michael@0 238 **
michael@0 239 ** RETURNS: void.
michael@0 240 **
michael@0 241 ** RESTRICTIONS:
michael@0 242 **
michael@0 243 */
michael@0 244 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 245 #define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7)\
michael@0 246 PR_Trace((handle),(ud0),(ud1),(ud2),(ud3),(ud4),(ud5),(ud6),(ud7))
michael@0 247 #else
michael@0 248 #define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7)
michael@0 249 #endif
michael@0 250
michael@0 251 NSPR_API(void)
michael@0 252 PR_Trace(
michael@0 253 PRTraceHandle handle, /* use this trace handle */
michael@0 254 PRUint32 userData0, /* User supplied data word 0 */
michael@0 255 PRUint32 userData1, /* User supplied data word 1 */
michael@0 256 PRUint32 userData2, /* User supplied data word 2 */
michael@0 257 PRUint32 userData3, /* User supplied data word 3 */
michael@0 258 PRUint32 userData4, /* User supplied data word 4 */
michael@0 259 PRUint32 userData5, /* User supplied data word 5 */
michael@0 260 PRUint32 userData6, /* User supplied data word 6 */
michael@0 261 PRUint32 userData7 /* User supplied data word 7 */
michael@0 262 );
michael@0 263
michael@0 264 /* -----------------------------------------------------------------------
michael@0 265 ** FUNCTION: PR_SetTraceOption() -- Control the Trace Facility
michael@0 266 **
michael@0 267 ** DESCRIPTION:
michael@0 268 ** PR_SetTraceOption() controls the Trace Facility. Depending on
michael@0 269 ** command and value, attributes of the Trace Facility may be
michael@0 270 ** changed.
michael@0 271 **
michael@0 272 ** INPUTS:
michael@0 273 ** command: An enumerated value in the set of PRTraceOption.
michael@0 274 ** value: pointer to the data to be set. Type of the data is
michael@0 275 ** dependent on command; for each value of command, the type
michael@0 276 ** and meaning of dereferenced value is shown.
michael@0 277 **
michael@0 278 ** PRTraceBufSize: unsigned long: the size of the trace buffer,
michael@0 279 ** in bytes.
michael@0 280 **
michael@0 281 ** PRTraceEnable: PRTraceHandle. The trace handle to be
michael@0 282 ** enabled.
michael@0 283 **
michael@0 284 ** PRTraceDisable: PRTraceHandle. The trace handle to be
michael@0 285 ** disabled.
michael@0 286 **
michael@0 287 ** PRTraceSuspend: void. value must be NULL. All tracing is
michael@0 288 ** suspended.
michael@0 289 **
michael@0 290 ** PRTraceResume: void. value must be NULL. Tracing for all
michael@0 291 ** previously enabled, prior to a PRTraceSuspend, is resumed.
michael@0 292 **
michael@0 293 ** PRTraceStopRecording: void. value must be NULL. If recording
michael@0 294 ** (see: ** PR_RecordTraceEntries()) is being done,
michael@0 295 ** PRTraceStopRecording causes PR_RecordTraceEntries() to return
michael@0 296 ** to its caller. If recording is not being done, this function
michael@0 297 ** has no effect.
michael@0 298 **
michael@0 299 ** PRTraceSuspendRecording: void. Must be NULL. If recording is
michael@0 300 ** being done, PRTraceSuspendRecording causes further writes to
michael@0 301 ** the trace file to be suspended. Data in the in-memory
michael@0 302 ** trace buffer that would ordinarily be written to the
michael@0 303 ** trace file will not be written. Trace entries will continue
michael@0 304 ** to be entered in the in-memory buffer. If the Trace Facility
michael@0 305 ** recording is already in a suspended state, the call has no
michael@0 306 ** effect.
michael@0 307 **
michael@0 308 ** PRTraceResumeRecording: void. value must be NULL. If
michael@0 309 ** recording for the Trace Facility has been previously been
michael@0 310 ** suspended, this causes recording to resume. Recording resumes
michael@0 311 ** with the next in-memory buffer segment that would be written
michael@0 312 ** if trace recording had not been suspended. If recording is
michael@0 313 ** not currently suspended, the call has no effect.
michael@0 314 **
michael@0 315 ** PRTraceLockHandles: void. value must be NULL. Locks the
michael@0 316 ** trace handle lock. While the trace handle lock is held,
michael@0 317 ** calls to PR_CreateTrace() will block until the lock is
michael@0 318 ** released.
michael@0 319 **
michael@0 320 ** PRTraceUnlockHandles: void. value must be NULL. Unlocks the
michael@0 321 ** trace handle lock.
michael@0 322 **
michael@0 323 ** OUTPUTS:
michael@0 324 ** The operation of the Trace Facility may be changed.
michael@0 325 **
michael@0 326 ** RETURNS: void
michael@0 327 **
michael@0 328 ** RESTRICTIONS:
michael@0 329 **
michael@0 330 */
michael@0 331 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 332 #define PR_SET_TRACE_OPTION(command,value)\
michael@0 333 PR_SetTraceOption((command),(value))
michael@0 334 #else
michael@0 335 #define PR_SET_TRACE_OPTION(command,value)
michael@0 336 #endif
michael@0 337
michael@0 338 NSPR_API(void)
michael@0 339 PR_SetTraceOption(
michael@0 340 PRTraceOption command, /* One of the enumerated values */
michael@0 341 void *value /* command value or NULL */
michael@0 342 );
michael@0 343
michael@0 344
michael@0 345 /* -----------------------------------------------------------------------
michael@0 346 ** FUNCTION: PR_GetTraceOption() -- Retrieve settings from the Trace Facility
michael@0 347 **
michael@0 348 ** DESCRIPTION:
michael@0 349 ** PR_GetTraceOption() retrieves the current setting of the
michael@0 350 ** Trace Facility control depending on command.
michael@0 351 **
michael@0 352 **
michael@0 353 ** PRTraceBufSize: unsigned long: the size of the trace buffer,
michael@0 354 ** in bytes.
michael@0 355 **
michael@0 356 **
michael@0 357 ** INPUTS:
michael@0 358 ** command: one of the enumerated values in PRTraceOptions
michael@0 359 ** valid for PR_GetTraceOption().
michael@0 360 **
michael@0 361 ** OUTPUTS:
michael@0 362 ** dependent on command.
michael@0 363 **
michael@0 364 ** RETURNS: void
michael@0 365 **
michael@0 366 ** RESTRICTIONS:
michael@0 367 **
michael@0 368 */
michael@0 369 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 370 #define PR_GET_TRACE_OPTION(command,value)\
michael@0 371 PR_GetTraceOption((command),(value))
michael@0 372 #else
michael@0 373 #define PR_GET_TRACE_OPTION(command,value)
michael@0 374 #endif
michael@0 375
michael@0 376 NSPR_API(void)
michael@0 377 PR_GetTraceOption(
michael@0 378 PRTraceOption command, /* One of the enumerated values */
michael@0 379 void *value /* command value or NULL */
michael@0 380 );
michael@0 381
michael@0 382 /* -----------------------------------------------------------------------
michael@0 383 ** FUNCTION: PR_GetTraceHandleFromName() -- Retrieve an existing
michael@0 384 ** handle by name.
michael@0 385 **
michael@0 386 ** DESCRIPTION:
michael@0 387 ** PR_GetTraceHandleFromName() retreives an existing tracehandle
michael@0 388 ** using the name specified by qName and rName.
michael@0 389 **
michael@0 390 ** INPUTS:
michael@0 391 ** qName: pointer to string. QName for this trace handle.
michael@0 392 **
michael@0 393 ** rName: pointer to string. RName for this trace handle.
michael@0 394 **
michael@0 395 **
michael@0 396 ** OUTPUTS: returned.
michael@0 397 **
michael@0 398 ** RETURNS:
michael@0 399 ** PRTraceHandle associated with qName and rName or NULL when
michael@0 400 ** there is no match.
michael@0 401 **
michael@0 402 ** RESTRICTIONS:
michael@0 403 **
michael@0 404 */
michael@0 405 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 406 #define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName)\
michael@0 407 (handle) = PR_GetTraceHandleFromName((qName),(rName))
michael@0 408 #else
michael@0 409 #define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName)
michael@0 410 #endif
michael@0 411
michael@0 412 NSPR_API(PRTraceHandle)
michael@0 413 PR_GetTraceHandleFromName(
michael@0 414 const char *qName, /* QName search argument */
michael@0 415 const char *rName /* RName search argument */
michael@0 416 );
michael@0 417
michael@0 418 /* -----------------------------------------------------------------------
michael@0 419 ** FUNCTION: PR_GetTraceNameFromHandle() -- Retreive trace name
michael@0 420 ** by bandle.
michael@0 421 **
michael@0 422 ** DESCRIPTION:
michael@0 423 ** PR_GetTraceNameFromHandle() retreives the existing qName,
michael@0 424 ** rName, and description for the referenced trace handle.
michael@0 425 **
michael@0 426 ** INPUTS: handle: PRTraceHandle.
michael@0 427 **
michael@0 428 ** OUTPUTS: pointers to the Trace Facility's copy of qName,
michael@0 429 ** rName and description. ... Don't mess with these values.
michael@0 430 ** They're mine.
michael@0 431 **
michael@0 432 ** RETURNS: void
michael@0 433 **
michael@0 434 ** RESTRICTIONS:
michael@0 435 **
michael@0 436 */
michael@0 437 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 438 #define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description)\
michael@0 439 PR_GetTraceNameFromHandle((handle),(qName),(rName),(description))
michael@0 440 #else
michael@0 441 #define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description)
michael@0 442 #endif
michael@0 443
michael@0 444 NSPR_API(void)
michael@0 445 PR_GetTraceNameFromHandle(
michael@0 446 PRTraceHandle handle, /* handle as search argument */
michael@0 447 const char **qName, /* pointer to associated QName */
michael@0 448 const char **rName, /* pointer to associated RName */
michael@0 449 const char **description /* pointer to associated description */
michael@0 450 );
michael@0 451
michael@0 452 /* -----------------------------------------------------------------------
michael@0 453 ** FUNCTION: PR_FindNextTraceQname() -- Retrieive a QName handle
michael@0 454 ** iterator.
michael@0 455 **
michael@0 456 ** DESCRIPTION:
michael@0 457 ** PR_FindNextTraceQname() retreives the first or next trace
michael@0 458 ** QName handle, depending on the value of handle, from the trace
michael@0 459 ** database. The PRTraceHandle returned can be used as an
michael@0 460 ** iterator to traverse the QName handles in the Trace database.
michael@0 461 **
michael@0 462 ** INPUTS:
michael@0 463 ** handle: When NULL, PR_FindNextQname() returns the first QName
michael@0 464 ** handle. When a handle is a valid PRTraceHandle previously
michael@0 465 ** retreived using PR_FindNextQname() the next QName handle is
michael@0 466 ** retreived.
michael@0 467 **
michael@0 468 ** OUTPUTS: returned.
michael@0 469 **
michael@0 470 ** RETURNS:
michael@0 471 ** PRTraceHandle or NULL when there are no trace handles.
michael@0 472 **
michael@0 473 ** RESTRICTIONS:
michael@0 474 ** Iterating thru the trace handles via FindFirst/FindNext
michael@0 475 ** should be done under protection of the trace handle lock.
michael@0 476 ** See: PR_SetTraceOption( PRLockTraceHandles ).
michael@0 477 **
michael@0 478 */
michael@0 479 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 480 #define PR_FIND_NEXT_TRACE_QNAME(next,handle)\
michael@0 481 (next) = PR_FindNextTraceQname((handle))
michael@0 482 #else
michael@0 483 #define PR_FIND_NEXT_TRACE_QNAME(next,handle)
michael@0 484 #endif
michael@0 485
michael@0 486 NSPR_API(PRTraceHandle)
michael@0 487 PR_FindNextTraceQname(
michael@0 488 PRTraceHandle handle
michael@0 489 );
michael@0 490
michael@0 491
michael@0 492 /* -----------------------------------------------------------------------
michael@0 493 ** FUNCTION: PR_FindNextTraceRname() -- Retrieive an RName handle
michael@0 494 ** iterator.
michael@0 495 **
michael@0 496 ** DESCRIPTION:
michael@0 497 ** PR_FindNextTraceRname() retreives the first or next trace
michael@0 498 ** RName handle, depending on the value of handle, from the trace
michael@0 499 ** database. The PRTraceHandle returned can be used as an
michael@0 500 ** iterator to traverse the RName handles in the Trace database.
michael@0 501 **
michael@0 502 ** INPUTS:
michael@0 503 ** rhandle: When NULL, PR_FindNextRname() returns the first
michael@0 504 ** RName handle. When a handle is a valid PRTraceHandle
michael@0 505 ** previously retreived using PR_FindNextRname() the next RName
michael@0 506 ** handle is retreived.
michael@0 507 ** qhandle: A valid PRTraceHandle retruned from a previous call
michael@0 508 ** to PR_FIND_NEXT_TRACE_QNAME().
michael@0 509 **
michael@0 510 ** OUTPUTS: returned.
michael@0 511 **
michael@0 512 ** RETURNS:
michael@0 513 ** PRTraceHandle or NULL when there are no trace handles.
michael@0 514 **
michael@0 515 ** RESTRICTIONS:
michael@0 516 ** Iterating thru the trace handles via FindNext should be done
michael@0 517 ** under protection of the trace handle lock. See: (
michael@0 518 ** PR_SetTraceOption( PRLockTraceHandles ).
michael@0 519 **
michael@0 520 */
michael@0 521 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 522 #define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle)\
michael@0 523 (next) = PR_FindNextTraceRname((rhandle),(qhandle))
michael@0 524 #else
michael@0 525 #define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle)
michael@0 526 #endif
michael@0 527
michael@0 528 NSPR_API(PRTraceHandle)
michael@0 529 PR_FindNextTraceRname(
michael@0 530 PRTraceHandle rhandle,
michael@0 531 PRTraceHandle qhandle
michael@0 532 );
michael@0 533
michael@0 534 /* -----------------------------------------------------------------------
michael@0 535 ** FUNCTION: PR_RecordTraceEntries() -- Write trace entries to external media
michael@0 536 **
michael@0 537 ** DESCRIPTION:
michael@0 538 ** PR_RecordTraceEntries() causes entries in the in-memory trace
michael@0 539 ** buffer to be written to external media.
michael@0 540 **
michael@0 541 ** When PR_RecordTraceEntries() is called from an application
michael@0 542 ** thread, the function appears to block until another thread
michael@0 543 ** calls PR_SetTraceOption() with the PRTraceStopRecording
michael@0 544 ** option. This suggests that PR_RecordTraceEntries() should be
michael@0 545 ** called from a user supplied thread whose only job is to
michael@0 546 ** record trace entries.
michael@0 547 **
michael@0 548 ** The environment variable NSPR_TRACE_LOG controls the operation
michael@0 549 ** of this function. When NSPR_TRACE_LOG is not defined in the
michael@0 550 ** environment, no recording of trace entries occurs. When
michael@0 551 ** NSPR_TRACE_LOG is defined, the value of its definition must be
michael@0 552 ** the filename of the file to receive the trace entry buffer.
michael@0 553 **
michael@0 554 ** PR_RecordTraceEntries() attempts to record the in-memory
michael@0 555 ** buffer to a file, subject to the setting of the environment
michael@0 556 ** variable NSPR_TRACE_LOG. It is possible because of system
michael@0 557 ** load, the thread priority of the recording thread, number of
michael@0 558 ** active trace records being written over time, and other
michael@0 559 ** variables that some trace records can be lost. ... In other
michael@0 560 ** words: don't bet the farm on getting everything.
michael@0 561 **
michael@0 562 ** INPUTS: none
michael@0 563 **
michael@0 564 ** OUTPUTS: none
michael@0 565 **
michael@0 566 ** RETURNS: PR_STATUS
michael@0 567 ** PR_SUCCESS no errors were found.
michael@0 568 ** PR_FAILURE errors were found.
michael@0 569 **
michael@0 570 ** RESTRICTIONS:
michael@0 571 ** Only one thread can call PR_RecordTraceEntries() within a
michael@0 572 ** process.
michael@0 573 **
michael@0 574 ** On error, PR_RecordTraceEntries() may return prematurely.
michael@0 575 **
michael@0 576 */
michael@0 577 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 578 #define PR_RECORD_TRACE_ENTRIES()\
michael@0 579 PR_RecordTraceEntries()
michael@0 580 #else
michael@0 581 #define PR_RECORD_TRACE_ENTRIES()
michael@0 582 #endif
michael@0 583
michael@0 584 NSPR_API(void)
michael@0 585 PR_RecordTraceEntries(
michael@0 586 void
michael@0 587 );
michael@0 588
michael@0 589 /* -----------------------------------------------------------------------
michael@0 590 ** FUNCTION: PR_GetTraceEntries() -- Retreive trace entries from
michael@0 591 ** the Trace Facility
michael@0 592 **
michael@0 593 ** DESCRIPTION:
michael@0 594 ** PR_GetTraceEntries() retreives trace entries from the Trace
michael@0 595 ** Facility. Up to count trace entries are copied from the Trace
michael@0 596 ** Facility into buffer. Only those trace entries that have not
michael@0 597 ** been copied via a previous call to PR_GetTraceEntries() are
michael@0 598 ** copied. The actual number copied is placed in the PRInt32
michael@0 599 ** variable pointed to by found.
michael@0 600 **
michael@0 601 ** If more than count trace entries have entered the Trace
michael@0 602 ** Facility since the last call to PR_GetTraceEntries()
michael@0 603 ** a lost data condition is returned. In this case, the most
michael@0 604 ** recent count trace entries are copied into buffer and found is
michael@0 605 ** set to count.
michael@0 606 **
michael@0 607 ** INPUTS:
michael@0 608 ** count. The number of trace entries to be copied into buffer.
michael@0 609 **
michael@0 610 **
michael@0 611 ** OUTPUTS:
michael@0 612 ** buffer. An array of PRTraceEntries. The buffer is supplied
michael@0 613 ** by the caller.
michael@0 614 **
michael@0 615 ** found: 32bit signed integer. The number of PRTraceEntries
michael@0 616 ** actually copied. found is always less than or equal to count.
michael@0 617 **
michael@0 618 ** RETURNS:
michael@0 619 ** zero when there is no lost data.
michael@0 620 ** non-zero when some PRTraceEntries have been lost.
michael@0 621 **
michael@0 622 ** RESTRICTIONS:
michael@0 623 ** This is a real performance pig. The copy out operation is bad
michael@0 624 ** enough, but depending on then frequency of calls to the
michael@0 625 ** function, serious performance impact to the operating
michael@0 626 ** application may be realized. ... YMMV.
michael@0 627 **
michael@0 628 */
michael@0 629 #if defined (DEBUG) || defined (FORCE_NSPR_TRACE)
michael@0 630 #define PR_GET_TRACE_ENTRIES(buffer,count,found)\
michael@0 631 PR_GetTraceEntries((buffer),(count),(found))
michael@0 632 #else
michael@0 633 #define PR_GET_TRACE_ENTRIES(buffer,count,found)
michael@0 634 #endif
michael@0 635
michael@0 636 NSPR_API(PRIntn)
michael@0 637 PR_GetTraceEntries(
michael@0 638 PRTraceEntry *buffer, /* where to write output */
michael@0 639 PRInt32 count, /* number to get */
michael@0 640 PRInt32 *found /* number you got */
michael@0 641 );
michael@0 642
michael@0 643 PR_END_EXTERN_C
michael@0 644
michael@0 645 #endif /* prtrace_h___ */
michael@0 646

mercurial