michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef prtrace_h___ michael@0: #define prtrace_h___ michael@0: /* michael@0: ** prtrace.h -- NSPR's Trace Facility. michael@0: ** michael@0: ** The Trace Facility provides a means to trace application michael@0: ** program events within a process. When implementing an michael@0: ** application program an engineer may insert a "Trace" function michael@0: ** call, passing arguments to be traced. The "Trace" function michael@0: ** combines the user trace data with identifying data and michael@0: ** writes this data in time ordered sequence into a circular michael@0: ** in-memory buffer; when the buffer fills, it wraps. michael@0: ** michael@0: ** Functions are provided to set and/or re-configure the size of michael@0: ** the trace buffer, control what events are recorded in the michael@0: ** buffer, enable and disable tracing based on specific user michael@0: ** supplied data and other control functions. Methods are provided michael@0: ** to record the trace entries in the in-memory trace buffer to michael@0: ** a file. michael@0: ** michael@0: ** Tracing may cause a performance degredation to the application michael@0: ** depending on the number and placement of calls to the tracing michael@0: ** facility. When tracing is compiled in and all tracing is michael@0: ** disabled via the runtime controls, the overhead should be michael@0: ** minimal. ... Famous last words, eh? michael@0: ** michael@0: ** When DEBUG is defined at compile time, the Trace Facility is michael@0: ** compiled as part of NSPR and any application using NSPR's michael@0: ** header files will have tracing compiled in. When DEBUG is not michael@0: ** defined, the Trace Facility is not compiled into NSPR nor michael@0: ** exported in its header files. If the Trace Facility is michael@0: ** desired in a non-debug build, then FORCE_NSPR_TRACE may be michael@0: ** defined at compile time for both the optimized build of NSPR michael@0: ** and the application. NSPR and any application using NSPR's michael@0: ** Trace Facility must be compiled with the same level of trace michael@0: ** conditioning or unresolved references may be realized at link michael@0: ** time. michael@0: ** michael@0: ** For any of the Trace Facility methods that requires a trace michael@0: ** handle as an input argument, the caller must ensure that the michael@0: ** trace handle argument is valid. An invalid trace handle michael@0: ** argument may cause unpredictable results. michael@0: ** michael@0: ** Trace Facility methods are thread-safe and SMP safe. michael@0: ** michael@0: ** Users of the Trace Facility should use the defined macros to michael@0: ** invoke trace methods, not the function calls directly. e.g. michael@0: ** PR_TRACE( h1,0,1,2, ...); not PR_Trace(h1,0,1,2, ...); michael@0: ** michael@0: ** Application designers should be aware of the effects of michael@0: ** debug and optimized build differences when using result of the michael@0: ** Trace Facility macros in expressions. michael@0: ** michael@0: ** See Also: prcountr.h michael@0: ** michael@0: ** /lth. 08-Jun-1998. michael@0: */ michael@0: michael@0: #include "prtypes.h" michael@0: #include "prthread.h" michael@0: #include "prtime.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /* michael@0: ** Opaque type for the trace handle michael@0: ** ... Don't even think about looking in here. michael@0: ** michael@0: */ michael@0: typedef void * PRTraceHandle; michael@0: michael@0: /* michael@0: ** PRTraceEntry -- A trace entry in the in-memory trace buffer michael@0: ** looks like this. michael@0: ** michael@0: */ michael@0: typedef struct PRTraceEntry michael@0: { michael@0: PRThread *thread; /* The thread creating the trace entry */ michael@0: PRTraceHandle handle; /* PRTraceHandle creating the trace entry */ michael@0: PRTime time; /* Value of PR_Now() at time of trace entry */ michael@0: PRUint32 userData[8]; /* user supplied trace data */ michael@0: } PRTraceEntry; michael@0: michael@0: /* michael@0: ** PRTraceOption -- command operands to michael@0: ** PR_[Set|Get]TraceOption(). See descriptive meanings there. michael@0: ** michael@0: */ michael@0: typedef enum PRTraceOption michael@0: { michael@0: PRTraceBufSize, michael@0: PRTraceEnable, michael@0: PRTraceDisable, michael@0: PRTraceSuspend, michael@0: PRTraceResume, michael@0: PRTraceSuspendRecording, michael@0: PRTraceResumeRecording, michael@0: PRTraceLockHandles, michael@0: PRTraceUnLockHandles, michael@0: PRTraceStopRecording michael@0: } PRTraceOption; michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_DEFINE_TRACE() -- Define a PRTraceHandle michael@0: ** michael@0: ** DESCRIPTION: PR_DEFINE_TRACE() is used to define a trace michael@0: ** handle. michael@0: ** michael@0: */ michael@0: #define PR_DEFINE_TRACE(name) PRTraceHandle name michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_INIT_TRACE_HANDLE() -- Set the value of a PRTraceHandle michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_INIT_TRACE_HANDLE() sets the value of a PRTraceHandle michael@0: ** to value. e.g. PR_INIT_TRACE_HANDLE( myHandle, NULL ); michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_INIT_TRACE_HANDLE(handle,value)\ michael@0: (handle) = (PRCounterHandle)(value) michael@0: #else michael@0: #define PR_INIT_TRACE_HANDLE(handle,value) michael@0: #endif michael@0: michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_CreateTrace() -- Create a trace handle michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_CreateTrace() creates a new trace handle. Tracing is michael@0: ** enabled for this handle when it is created. The trace handle michael@0: ** is intended for use in other Trace Facility calls. michael@0: ** michael@0: ** PR_CreateTrace() registers the QName, RName and description michael@0: ** data so that this data can be retrieved later. michael@0: ** michael@0: ** INPUTS: michael@0: ** qName: pointer to string. QName for this trace handle. michael@0: ** michael@0: ** rName: pointer to string. RName for this trace handle. michael@0: ** michael@0: ** description: pointer to string. Descriptive data about this michael@0: ** trace handle. michael@0: ** michael@0: ** OUTPUTS: michael@0: ** Creates the trace handle. michael@0: ** Registers the QName and RName with the trace facility. michael@0: ** michael@0: ** RETURNS: michael@0: ** PRTraceHandle michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** qName is limited to 31 characters. michael@0: ** rName is limited to 31 characters. michael@0: ** description is limited to 255 characters. michael@0: ** michael@0: */ michael@0: #define PRTRACE_NAME_MAX 31 michael@0: #define PRTRACE_DESC_MAX 255 michael@0: michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_CREATE_TRACE(handle,qName,rName,description)\ michael@0: (handle) = PR_CreateTrace((qName),(rName),(description)) michael@0: #else michael@0: #define PR_CREATE_TRACE(handle,qName,rName,description) michael@0: #endif michael@0: michael@0: NSPR_API(PRTraceHandle) michael@0: PR_CreateTrace( michael@0: const char *qName, /* QName for this trace handle */ michael@0: const char *rName, /* RName for this trace handle */ michael@0: const char *description /* description for this trace handle */ michael@0: ); michael@0: michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_DestroyTrace() -- Destroy a trace handle michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_DestroyTrace() removes the referenced trace handle and michael@0: ** associated QName, RName and description data from the Trace michael@0: ** Facility. michael@0: ** michael@0: ** INPUTS: handle. A PRTraceHandle michael@0: ** michael@0: ** OUTPUTS: michael@0: ** The trace handle is unregistered. michael@0: ** The QName, RName and description are removed. michael@0: ** michael@0: ** RETURNS: void michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_DESTROY_TRACE(handle)\ michael@0: PR_DestroyTrace((handle)) michael@0: #else michael@0: #define PR_DESTROY_TRACE(handle) michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_DestroyTrace( michael@0: PRTraceHandle handle /* Handle to be destroyed */ michael@0: ); michael@0: michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_Trace() -- Make a trace entry in the in-memory trace michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_Trace() makes an entry in the in-memory trace buffer for michael@0: ** the referenced trace handle. The next logically available michael@0: ** PRTraceEntry is used; when the next trace entry would overflow michael@0: ** the trace table, the table wraps. michael@0: ** michael@0: ** PR_Trace() for a specific trace handle may be disabled by michael@0: ** calling PR_SetTraceOption() specifying PRTraceDisable for the michael@0: ** trace handle to be disabled. michael@0: ** michael@0: ** INPUTS: michael@0: ** handle: PRTraceHandle. The trace handle for this trace. michael@0: ** michael@0: ** userData[0..7]: unsigned 32bit integers. user supplied data michael@0: ** that is copied into the PRTraceEntry michael@0: ** michael@0: ** OUTPUTS: michael@0: ** A PRTraceEntry is (conditionally) formatted in the in-memory michael@0: ** trace buffer. michael@0: ** michael@0: ** RETURNS: void. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7)\ michael@0: PR_Trace((handle),(ud0),(ud1),(ud2),(ud3),(ud4),(ud5),(ud6),(ud7)) michael@0: #else michael@0: #define PR_TRACE(handle,ud0,ud1,ud2,ud3,ud4,ud5,ud6,ud7) michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_Trace( michael@0: PRTraceHandle handle, /* use this trace handle */ michael@0: PRUint32 userData0, /* User supplied data word 0 */ michael@0: PRUint32 userData1, /* User supplied data word 1 */ michael@0: PRUint32 userData2, /* User supplied data word 2 */ michael@0: PRUint32 userData3, /* User supplied data word 3 */ michael@0: PRUint32 userData4, /* User supplied data word 4 */ michael@0: PRUint32 userData5, /* User supplied data word 5 */ michael@0: PRUint32 userData6, /* User supplied data word 6 */ michael@0: PRUint32 userData7 /* User supplied data word 7 */ michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_SetTraceOption() -- Control the Trace Facility michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_SetTraceOption() controls the Trace Facility. Depending on michael@0: ** command and value, attributes of the Trace Facility may be michael@0: ** changed. michael@0: ** michael@0: ** INPUTS: michael@0: ** command: An enumerated value in the set of PRTraceOption. michael@0: ** value: pointer to the data to be set. Type of the data is michael@0: ** dependent on command; for each value of command, the type michael@0: ** and meaning of dereferenced value is shown. michael@0: ** michael@0: ** PRTraceBufSize: unsigned long: the size of the trace buffer, michael@0: ** in bytes. michael@0: ** michael@0: ** PRTraceEnable: PRTraceHandle. The trace handle to be michael@0: ** enabled. michael@0: ** michael@0: ** PRTraceDisable: PRTraceHandle. The trace handle to be michael@0: ** disabled. michael@0: ** michael@0: ** PRTraceSuspend: void. value must be NULL. All tracing is michael@0: ** suspended. michael@0: ** michael@0: ** PRTraceResume: void. value must be NULL. Tracing for all michael@0: ** previously enabled, prior to a PRTraceSuspend, is resumed. michael@0: ** michael@0: ** PRTraceStopRecording: void. value must be NULL. If recording michael@0: ** (see: ** PR_RecordTraceEntries()) is being done, michael@0: ** PRTraceStopRecording causes PR_RecordTraceEntries() to return michael@0: ** to its caller. If recording is not being done, this function michael@0: ** has no effect. michael@0: ** michael@0: ** PRTraceSuspendRecording: void. Must be NULL. If recording is michael@0: ** being done, PRTraceSuspendRecording causes further writes to michael@0: ** the trace file to be suspended. Data in the in-memory michael@0: ** trace buffer that would ordinarily be written to the michael@0: ** trace file will not be written. Trace entries will continue michael@0: ** to be entered in the in-memory buffer. If the Trace Facility michael@0: ** recording is already in a suspended state, the call has no michael@0: ** effect. michael@0: ** michael@0: ** PRTraceResumeRecording: void. value must be NULL. If michael@0: ** recording for the Trace Facility has been previously been michael@0: ** suspended, this causes recording to resume. Recording resumes michael@0: ** with the next in-memory buffer segment that would be written michael@0: ** if trace recording had not been suspended. If recording is michael@0: ** not currently suspended, the call has no effect. michael@0: ** michael@0: ** PRTraceLockHandles: void. value must be NULL. Locks the michael@0: ** trace handle lock. While the trace handle lock is held, michael@0: ** calls to PR_CreateTrace() will block until the lock is michael@0: ** released. michael@0: ** michael@0: ** PRTraceUnlockHandles: void. value must be NULL. Unlocks the michael@0: ** trace handle lock. michael@0: ** michael@0: ** OUTPUTS: michael@0: ** The operation of the Trace Facility may be changed. michael@0: ** michael@0: ** RETURNS: void michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_SET_TRACE_OPTION(command,value)\ michael@0: PR_SetTraceOption((command),(value)) michael@0: #else michael@0: #define PR_SET_TRACE_OPTION(command,value) michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_SetTraceOption( michael@0: PRTraceOption command, /* One of the enumerated values */ michael@0: void *value /* command value or NULL */ michael@0: ); michael@0: michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_GetTraceOption() -- Retrieve settings from the Trace Facility michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_GetTraceOption() retrieves the current setting of the michael@0: ** Trace Facility control depending on command. michael@0: ** michael@0: ** michael@0: ** PRTraceBufSize: unsigned long: the size of the trace buffer, michael@0: ** in bytes. michael@0: ** michael@0: ** michael@0: ** INPUTS: michael@0: ** command: one of the enumerated values in PRTraceOptions michael@0: ** valid for PR_GetTraceOption(). michael@0: ** michael@0: ** OUTPUTS: michael@0: ** dependent on command. michael@0: ** michael@0: ** RETURNS: void michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_GET_TRACE_OPTION(command,value)\ michael@0: PR_GetTraceOption((command),(value)) michael@0: #else michael@0: #define PR_GET_TRACE_OPTION(command,value) michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_GetTraceOption( michael@0: PRTraceOption command, /* One of the enumerated values */ michael@0: void *value /* command value or NULL */ michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_GetTraceHandleFromName() -- Retrieve an existing michael@0: ** handle by name. michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_GetTraceHandleFromName() retreives an existing tracehandle michael@0: ** using the name specified by qName and rName. michael@0: ** michael@0: ** INPUTS: michael@0: ** qName: pointer to string. QName for this trace handle. michael@0: ** michael@0: ** rName: pointer to string. RName for this trace handle. michael@0: ** michael@0: ** michael@0: ** OUTPUTS: returned. michael@0: ** michael@0: ** RETURNS: michael@0: ** PRTraceHandle associated with qName and rName or NULL when michael@0: ** there is no match. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName)\ michael@0: (handle) = PR_GetTraceHandleFromName((qName),(rName)) michael@0: #else michael@0: #define PR_GET_TRACE_HANDLE_FROM_NAME(handle,qName,rName) michael@0: #endif michael@0: michael@0: NSPR_API(PRTraceHandle) michael@0: PR_GetTraceHandleFromName( michael@0: const char *qName, /* QName search argument */ michael@0: const char *rName /* RName search argument */ michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_GetTraceNameFromHandle() -- Retreive trace name michael@0: ** by bandle. michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_GetTraceNameFromHandle() retreives the existing qName, michael@0: ** rName, and description for the referenced trace handle. michael@0: ** michael@0: ** INPUTS: handle: PRTraceHandle. michael@0: ** michael@0: ** OUTPUTS: pointers to the Trace Facility's copy of qName, michael@0: ** rName and description. ... Don't mess with these values. michael@0: ** They're mine. michael@0: ** michael@0: ** RETURNS: void michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description)\ michael@0: PR_GetTraceNameFromHandle((handle),(qName),(rName),(description)) michael@0: #else michael@0: #define PR_GET_TRACE_NAME_FROM_HANDLE(handle,qName,rName,description) michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_GetTraceNameFromHandle( michael@0: PRTraceHandle handle, /* handle as search argument */ michael@0: const char **qName, /* pointer to associated QName */ michael@0: const char **rName, /* pointer to associated RName */ michael@0: const char **description /* pointer to associated description */ michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_FindNextTraceQname() -- Retrieive a QName handle michael@0: ** iterator. michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_FindNextTraceQname() retreives the first or next trace michael@0: ** QName handle, depending on the value of handle, from the trace michael@0: ** database. The PRTraceHandle returned can be used as an michael@0: ** iterator to traverse the QName handles in the Trace database. michael@0: ** michael@0: ** INPUTS: michael@0: ** handle: When NULL, PR_FindNextQname() returns the first QName michael@0: ** handle. When a handle is a valid PRTraceHandle previously michael@0: ** retreived using PR_FindNextQname() the next QName handle is michael@0: ** retreived. michael@0: ** michael@0: ** OUTPUTS: returned. michael@0: ** michael@0: ** RETURNS: michael@0: ** PRTraceHandle or NULL when there are no trace handles. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** Iterating thru the trace handles via FindFirst/FindNext michael@0: ** should be done under protection of the trace handle lock. michael@0: ** See: PR_SetTraceOption( PRLockTraceHandles ). michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_FIND_NEXT_TRACE_QNAME(next,handle)\ michael@0: (next) = PR_FindNextTraceQname((handle)) michael@0: #else michael@0: #define PR_FIND_NEXT_TRACE_QNAME(next,handle) michael@0: #endif michael@0: michael@0: NSPR_API(PRTraceHandle) michael@0: PR_FindNextTraceQname( michael@0: PRTraceHandle handle michael@0: ); michael@0: michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_FindNextTraceRname() -- Retrieive an RName handle michael@0: ** iterator. michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_FindNextTraceRname() retreives the first or next trace michael@0: ** RName handle, depending on the value of handle, from the trace michael@0: ** database. The PRTraceHandle returned can be used as an michael@0: ** iterator to traverse the RName handles in the Trace database. michael@0: ** michael@0: ** INPUTS: michael@0: ** rhandle: When NULL, PR_FindNextRname() returns the first michael@0: ** RName handle. When a handle is a valid PRTraceHandle michael@0: ** previously retreived using PR_FindNextRname() the next RName michael@0: ** handle is retreived. michael@0: ** qhandle: A valid PRTraceHandle retruned from a previous call michael@0: ** to PR_FIND_NEXT_TRACE_QNAME(). michael@0: ** michael@0: ** OUTPUTS: returned. michael@0: ** michael@0: ** RETURNS: michael@0: ** PRTraceHandle or NULL when there are no trace handles. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** Iterating thru the trace handles via FindNext should be done michael@0: ** under protection of the trace handle lock. See: ( michael@0: ** PR_SetTraceOption( PRLockTraceHandles ). michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle)\ michael@0: (next) = PR_FindNextTraceRname((rhandle),(qhandle)) michael@0: #else michael@0: #define PR_FIND_NEXT_TRACE_RNAME(next,rhandle,qhandle) michael@0: #endif michael@0: michael@0: NSPR_API(PRTraceHandle) michael@0: PR_FindNextTraceRname( michael@0: PRTraceHandle rhandle, michael@0: PRTraceHandle qhandle michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_RecordTraceEntries() -- Write trace entries to external media michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_RecordTraceEntries() causes entries in the in-memory trace michael@0: ** buffer to be written to external media. michael@0: ** michael@0: ** When PR_RecordTraceEntries() is called from an application michael@0: ** thread, the function appears to block until another thread michael@0: ** calls PR_SetTraceOption() with the PRTraceStopRecording michael@0: ** option. This suggests that PR_RecordTraceEntries() should be michael@0: ** called from a user supplied thread whose only job is to michael@0: ** record trace entries. michael@0: ** michael@0: ** The environment variable NSPR_TRACE_LOG controls the operation michael@0: ** of this function. When NSPR_TRACE_LOG is not defined in the michael@0: ** environment, no recording of trace entries occurs. When michael@0: ** NSPR_TRACE_LOG is defined, the value of its definition must be michael@0: ** the filename of the file to receive the trace entry buffer. michael@0: ** michael@0: ** PR_RecordTraceEntries() attempts to record the in-memory michael@0: ** buffer to a file, subject to the setting of the environment michael@0: ** variable NSPR_TRACE_LOG. It is possible because of system michael@0: ** load, the thread priority of the recording thread, number of michael@0: ** active trace records being written over time, and other michael@0: ** variables that some trace records can be lost. ... In other michael@0: ** words: don't bet the farm on getting everything. michael@0: ** michael@0: ** INPUTS: none michael@0: ** michael@0: ** OUTPUTS: none michael@0: ** michael@0: ** RETURNS: PR_STATUS michael@0: ** PR_SUCCESS no errors were found. michael@0: ** PR_FAILURE errors were found. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** Only one thread can call PR_RecordTraceEntries() within a michael@0: ** process. michael@0: ** michael@0: ** On error, PR_RecordTraceEntries() may return prematurely. michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_RECORD_TRACE_ENTRIES()\ michael@0: PR_RecordTraceEntries() michael@0: #else michael@0: #define PR_RECORD_TRACE_ENTRIES() michael@0: #endif michael@0: michael@0: NSPR_API(void) michael@0: PR_RecordTraceEntries( michael@0: void michael@0: ); michael@0: michael@0: /* ----------------------------------------------------------------------- michael@0: ** FUNCTION: PR_GetTraceEntries() -- Retreive trace entries from michael@0: ** the Trace Facility michael@0: ** michael@0: ** DESCRIPTION: michael@0: ** PR_GetTraceEntries() retreives trace entries from the Trace michael@0: ** Facility. Up to count trace entries are copied from the Trace michael@0: ** Facility into buffer. Only those trace entries that have not michael@0: ** been copied via a previous call to PR_GetTraceEntries() are michael@0: ** copied. The actual number copied is placed in the PRInt32 michael@0: ** variable pointed to by found. michael@0: ** michael@0: ** If more than count trace entries have entered the Trace michael@0: ** Facility since the last call to PR_GetTraceEntries() michael@0: ** a lost data condition is returned. In this case, the most michael@0: ** recent count trace entries are copied into buffer and found is michael@0: ** set to count. michael@0: ** michael@0: ** INPUTS: michael@0: ** count. The number of trace entries to be copied into buffer. michael@0: ** michael@0: ** michael@0: ** OUTPUTS: michael@0: ** buffer. An array of PRTraceEntries. The buffer is supplied michael@0: ** by the caller. michael@0: ** michael@0: ** found: 32bit signed integer. The number of PRTraceEntries michael@0: ** actually copied. found is always less than or equal to count. michael@0: ** michael@0: ** RETURNS: michael@0: ** zero when there is no lost data. michael@0: ** non-zero when some PRTraceEntries have been lost. michael@0: ** michael@0: ** RESTRICTIONS: michael@0: ** This is a real performance pig. The copy out operation is bad michael@0: ** enough, but depending on then frequency of calls to the michael@0: ** function, serious performance impact to the operating michael@0: ** application may be realized. ... YMMV. michael@0: ** michael@0: */ michael@0: #if defined (DEBUG) || defined (FORCE_NSPR_TRACE) michael@0: #define PR_GET_TRACE_ENTRIES(buffer,count,found)\ michael@0: PR_GetTraceEntries((buffer),(count),(found)) michael@0: #else michael@0: #define PR_GET_TRACE_ENTRIES(buffer,count,found) michael@0: #endif michael@0: michael@0: NSPR_API(PRIntn) michael@0: PR_GetTraceEntries( michael@0: PRTraceEntry *buffer, /* where to write output */ michael@0: PRInt32 count, /* number to get */ michael@0: PRInt32 *found /* number you got */ michael@0: ); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: #endif /* prtrace_h___ */ michael@0: