mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add clock timer routines for debugging performance problems
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4976 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
28df0d583c
commit
a91931b95f
@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* gnc-engine-util.c -- GnuCash engine utility functions *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1997-2000 Linas Vepstas <linas@linas.org> *
|
||||
* Copyright (C) 1997-2001 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -34,6 +34,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-common.h"
|
||||
@ -152,6 +153,71 @@ gnc_log (gncModuleType module, gncLogLevel log_level, const char *prefix,
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
#define NUM_CLOCKS 10
|
||||
|
||||
static
|
||||
struct timeval gnc_clock[NUM_CLOCKS] = {
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0},
|
||||
};
|
||||
|
||||
void
|
||||
gnc_start_clock (int clockno, gncModuleType module, gncLogLevel log_level,
|
||||
const char *function_name, const char *format, ...)
|
||||
{
|
||||
struct timezone tz;
|
||||
va_list ap;
|
||||
|
||||
if ((0>clockno) || (NUM_CLOCKS <= clockno)) return;
|
||||
gettimeofday (&gnc_clock[clockno], &tz);
|
||||
|
||||
fprintf (stderr, "Clock %d Start: %s: ",
|
||||
clockno, prettify (function_name));
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
vfprintf (stderr, format, ap);
|
||||
|
||||
va_end (ap);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
void
|
||||
gnc_report_clock (int clockno, gncModuleType module, gncLogLevel log_level,
|
||||
const char *function_name, const char *format, ...)
|
||||
{
|
||||
struct timezone tz;
|
||||
struct timeval now;
|
||||
va_list ap;
|
||||
|
||||
if ((0>clockno) || (NUM_CLOCKS <= clockno)) return;
|
||||
gettimeofday (&now, &tz);
|
||||
|
||||
/* need to borrow to make differnce */
|
||||
if (now.tv_usec < gnc_clock[clockno].tv_usec)
|
||||
{
|
||||
now.tv_sec --;
|
||||
now.tv_usec -= 1000000;
|
||||
}
|
||||
now.tv_sec -= gnc_clock[clockno].tv_sec;
|
||||
now.tv_usec -= gnc_clock[clockno].tv_usec;
|
||||
|
||||
fprintf (stderr, "Clock %d Elapsed: %ld.%06ld %s: ",
|
||||
clockno, now.tv_sec, now.tv_usec, prettify (function_name));
|
||||
|
||||
va_start (ap, format);
|
||||
|
||||
vfprintf (stderr, format, ap);
|
||||
|
||||
va_end (ap);
|
||||
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/********************************************************************\
|
||||
* gnc-engine-util.h -- GnuCash engine utility functions *
|
||||
* Copyright (C) 1997 Robin D. Clark *
|
||||
* Copyright (C) 1998-2000 Linas Vepstas <linas@linas.org> *
|
||||
* Copyright (C) 1998-2001 Linas Vepstas <linas@linas.org> *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
@ -149,6 +149,25 @@ void gnc_log (gncModuleType module, gncLogLevel log_level,
|
||||
__FUNCTION__, format, ## args); \
|
||||
}
|
||||
|
||||
void gnc_start_clock (int clockno, gncModuleType module, gncLogLevel log_level,
|
||||
const char *function_name, const char *format, ...);
|
||||
|
||||
void gnc_report_clock (int clockno, gncModuleType module, gncLogLevel log_level,
|
||||
const char *function_name, const char *format, ...);
|
||||
|
||||
|
||||
#define START_CLOCK(clockno,format, args...) { \
|
||||
if (gnc_should_log (module, GNC_LOG_INFO)) \
|
||||
gnc_start_clock (clockno, module, GNC_LOG_INFO,\
|
||||
__FUNCTION__, format, ## args); \
|
||||
}
|
||||
|
||||
#define REPORT_CLOCK(clockno,format, args...) { \
|
||||
if (gnc_should_log (module, GNC_LOG_INFO)) \
|
||||
gnc_report_clock (clockno, module, GNC_LOG_INFO,\
|
||||
__FUNCTION__, format, ## args); \
|
||||
}
|
||||
|
||||
|
||||
/* Set the logging level of the given module. */
|
||||
void gnc_set_log_level(gncModuleType module, gncLogLevel level);
|
||||
|
Loading…
Reference in New Issue
Block a user