From 93c701edc6c6f065cd25f77f63ab31aff085d6ac Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 15 May 2008 00:17:41 +0000 Subject: Add support for tracking call counts and elapsed runtime for user-defined functions. Note that because this patch changes FmgrInfo, any external C functions you might be testing with 8.4 will need to be recompiled. Patch by Martin Pihlak, some editorialization by me (principally, removing tracking of getrusage() numbers) --- src/include/portability/instr_time.h | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'src/include/portability') diff --git a/src/include/portability/instr_time.h b/src/include/portability/instr_time.h index 666d495f20..7f4a0923b6 100644 --- a/src/include/portability/instr_time.h +++ b/src/include/portability/instr_time.h @@ -20,6 +20,8 @@ * * INSTR_TIME_SET_CURRENT(t) set t to current time * + * INSTR_TIME_ADD(x, y) x += y + * * INSTR_TIME_SUBTRACT(x, y) x -= y * * INSTR_TIME_ACCUM_DIFF(x, y, z) x += (y - z) @@ -35,15 +37,15 @@ * only useful on intervals. * * When summing multiple measurements, it's recommended to leave the - * running sum in instr_time form (ie, use INSTR_TIME_ACCUM_DIFF) and - * convert to a result format only at the end. + * running sum in instr_time form (ie, use INSTR_TIME_ADD or + * INSTR_TIME_ACCUM_DIFF) and convert to a result format only at the end. * * Beware of multiple evaluations of the macro arguments. * * * Copyright (c) 2001-2008, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.1 2008/05/14 19:10:29 tgl Exp $ + * $PostgreSQL: pgsql/src/include/portability/instr_time.h,v 1.2 2008/05/15 00:17:41 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -62,6 +64,18 @@ typedef struct timeval instr_time; #define INSTR_TIME_SET_CURRENT(t) gettimeofday(&(t), NULL) +#define INSTR_TIME_ADD(x,y) \ + do { \ + (x).tv_sec += (y).tv_sec; \ + (x).tv_usec += (y).tv_usec; \ + /* Normalize */ \ + while ((x).tv_usec >= 1000000) \ + { \ + (x).tv_usec -= 1000000; \ + (x).tv_sec++; \ + } \ + } while (0) + #define INSTR_TIME_SUBTRACT(x,y) \ do { \ (x).tv_sec -= (y).tv_sec; \ @@ -110,6 +124,9 @@ typedef LARGE_INTEGER instr_time; #define INSTR_TIME_SET_CURRENT(t) QueryPerformanceCounter(&(t)) +#define INSTR_TIME_ADD(x,y) \ + ((x).QuadPart += (y).QuadPart) + #define INSTR_TIME_SUBTRACT(x,y) \ ((x).QuadPart -= (y).QuadPart) -- cgit v1.2.1