From 021a3748ddbffdb42afca05c9ebde8c9862e4fba Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 8 Jan 2016 11:35:45 -0800 Subject: [PATCH 1/2] Provide FDW query timing on DEBUG --- contrib/postgres_fdw/postgres_fdw.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 775eaa07da89c..607e51ded5b6b 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -39,6 +39,9 @@ #include "utils/rel.h" #include "utils/sampling.h" +#include +#include + PG_MODULE_MAGIC; /* Default CPU cost to start up a foreign query. */ @@ -74,7 +77,7 @@ typedef struct PgFdwRelationInfo bool use_remote_estimate; Cost fdw_startup_cost; Cost fdw_tuple_cost; - + /* Cached catalog information. */ ForeignTable *table; ForeignServer *server; @@ -154,6 +157,9 @@ typedef struct PgFdwScanState int fetch_ct_2; /* Min(# of fetches done, 2) */ bool eof_reached; /* true if last fetch reached EOF */ + /* Timing */ + struct timeval start_time; + /* working memory contexts */ MemoryContext batch_cxt; /* context holding current batch of tuples */ MemoryContext temp_cxt; /* context for per-tuple temporary data */ @@ -1019,7 +1025,10 @@ postgresIterateForeignScan(ForeignScanState *node) * cursor on the remote side. */ if (!fsstate->cursor_exists) + { + gettimeofday(&(fsstate->start_time), NULL); create_cursor(node); + } /* * Get some more tuples, if we've run out. @@ -1116,7 +1125,15 @@ postgresEndForeignScan(ForeignScanState *node) /* Close the cursor if open, to prevent accumulation of cursors */ if (fsstate->cursor_exists) + { + struct timeval end_time; + double secs; + gettimeofday(&end_time, NULL); + secs = 1000 * end_time.tv_sec + end_time.tv_usec/1000.0; + secs -= 1000 * (fsstate->start_time).tv_sec + (fsstate->start_time).tv_usec/1000.0; + elog(DEBUG1, "FDW Query Duration: %.3lf ms", secs); close_cursor(fsstate->conn, fsstate->cursor_number); + } /* Release remote connection */ ReleaseConnection(fsstate->conn); From 146d29fbb07dca0037b7735aaad1eba8704c9f9e Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Fri, 8 Jan 2016 11:46:39 -0800 Subject: [PATCH 2/2] Reformat to tabs --- contrib/postgres_fdw/postgres_fdw.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/postgres_fdw/postgres_fdw.c b/contrib/postgres_fdw/postgres_fdw.c index 607e51ded5b6b..dc65b812e90a9 100644 --- a/contrib/postgres_fdw/postgres_fdw.c +++ b/contrib/postgres_fdw/postgres_fdw.c @@ -77,7 +77,7 @@ typedef struct PgFdwRelationInfo bool use_remote_estimate; Cost fdw_startup_cost; Cost fdw_tuple_cost; - + /* Cached catalog information. */ ForeignTable *table; ForeignServer *server; @@ -1025,10 +1025,10 @@ postgresIterateForeignScan(ForeignScanState *node) * cursor on the remote side. */ if (!fsstate->cursor_exists) - { + { gettimeofday(&(fsstate->start_time), NULL); create_cursor(node); - } + } /* * Get some more tuples, if we've run out.