mirror of
https://github.com/VARCem/PDCurses.git
synced 2026-09-24 15:55:14 +00:00
debug: hold trace file open while trace is enabled
this gives a substantial increase in responsiveness during traceon sessions compared to opening and closing the file for every log line
This commit is contained in:
committed by
William McBrine
parent
209089a594
commit
01aedfcba6
@@ -50,7 +50,7 @@ typedef struct /* structure for ripped off lines */
|
||||
#define _DLCHAR 0x15 /* Delete Line char (^U) */
|
||||
|
||||
extern WINDOW *pdc_lastscr;
|
||||
extern bool pdc_trace_on; /* tracing flag */
|
||||
extern FILE *pdc_dbfp; /* tracing file pointer (NULL = off) */
|
||||
extern bool pdc_color_started;
|
||||
extern unsigned long pdc_key_modifiers;
|
||||
extern MOUSE_STATUS pdc_mouse_status;
|
||||
@@ -105,7 +105,7 @@ size_t PDC_wcstombs(char *, const wchar_t *, size_t);
|
||||
#endif
|
||||
|
||||
#ifdef PDCDEBUG
|
||||
# define PDC_LOG(x) if (pdc_trace_on) PDC_debug x
|
||||
# define PDC_LOG(x) if (pdc_dbfp) PDC_debug x
|
||||
#else
|
||||
# define PDC_LOG(x)
|
||||
#endif
|
||||
|
||||
@@ -35,49 +35,50 @@ debug
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
|
||||
bool pdc_trace_on = FALSE;
|
||||
FILE *pdc_dbfp = NULL;
|
||||
|
||||
void PDC_debug(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
FILE *dbfp;
|
||||
char hms[9];
|
||||
time_t now;
|
||||
|
||||
if (!pdc_trace_on)
|
||||
if (!pdc_dbfp)
|
||||
return;
|
||||
|
||||
/* open debug log file append */
|
||||
time(&now);
|
||||
strftime(hms, 9, "%H:%M:%S", localtime(&now));
|
||||
fprintf(pdc_dbfp, "At: %8.8ld - %s ", (long) clock(), hms);
|
||||
|
||||
dbfp = fopen("trace", "a");
|
||||
if (!dbfp)
|
||||
va_start(args, fmt);
|
||||
vfprintf(pdc_dbfp, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void traceon(void)
|
||||
{
|
||||
if (pdc_dbfp)
|
||||
fclose(pdc_dbfp);
|
||||
|
||||
/* open debug log file append */
|
||||
pdc_dbfp = fopen("trace", "a");
|
||||
if (!pdc_dbfp)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"PDC_debug(): Unable to open debug log file\n");
|
||||
return;
|
||||
}
|
||||
|
||||
time(&now);
|
||||
strftime(hms, 9, "%H:%M:%S", localtime(&now));
|
||||
fprintf(dbfp, "At: %8.8ld - %s ", (long) clock(), hms);
|
||||
|
||||
va_start(args, fmt);
|
||||
vfprintf(dbfp, fmt, args);
|
||||
va_end(args);
|
||||
|
||||
fclose(dbfp);
|
||||
}
|
||||
|
||||
void traceon(void)
|
||||
{
|
||||
pdc_trace_on = TRUE;
|
||||
|
||||
PDC_LOG(("traceon() - called\n"));
|
||||
}
|
||||
|
||||
void traceoff(void)
|
||||
{
|
||||
if (!pdc_dbfp)
|
||||
return;
|
||||
|
||||
PDC_LOG(("traceoff() - called\n"));
|
||||
|
||||
pdc_trace_on = FALSE;
|
||||
fclose(pdc_dbfp);
|
||||
pdc_dbfp = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user