mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-24 15:55:14 +00:00
debug: add PDC_TRACE_FLUSH env var to toggle aggressive fflush()
This commit is contained in:
committed by
William McBrine
parent
01aedfcba6
commit
b9f639b5b6
@@ -31,11 +31,13 @@ debug
|
||||
|
||||
**man-end****************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
FILE *pdc_dbfp = NULL;
|
||||
static bool want_fflush = FALSE;
|
||||
|
||||
void PDC_debug(const char *fmt, ...)
|
||||
{
|
||||
@@ -53,10 +55,25 @@ void PDC_debug(const char *fmt, ...)
|
||||
va_start(args, fmt);
|
||||
vfprintf(pdc_dbfp, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
/* If you are crashing and losing debugging information, enable this
|
||||
* by setting the environment variable PDC_TRACE_FLUSH to 1. This may
|
||||
* impact performance.
|
||||
*/
|
||||
if (want_fflush)
|
||||
fflush(pdc_dbfp);
|
||||
|
||||
/* If with PDC_TRACE_FLUSH enabled you are still losing logging in
|
||||
* crashes, you may need to add a platform-dependent mechanism to flush
|
||||
* the OS buffers as well (such as fsync() on POSIX) -- but expect
|
||||
* terrible performance.
|
||||
*/
|
||||
}
|
||||
|
||||
void traceon(void)
|
||||
{
|
||||
char *env;
|
||||
|
||||
if (pdc_dbfp)
|
||||
fclose(pdc_dbfp);
|
||||
|
||||
@@ -69,6 +86,9 @@ void traceon(void)
|
||||
return;
|
||||
}
|
||||
|
||||
if ((env = getenv("PDC_TRACE_FLUSH")))
|
||||
want_fflush = atoi(env);
|
||||
|
||||
PDC_LOG(("traceon() - called\n"));
|
||||
}
|
||||
|
||||
@@ -81,4 +101,5 @@ void traceoff(void)
|
||||
|
||||
fclose(pdc_dbfp);
|
||||
pdc_dbfp = NULL;
|
||||
want_fflush = FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user