Skip to content

Provide FDW query time profiles #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions contrib/postgres_fdw/postgres_fdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#include "utils/rel.h"
#include "utils/sampling.h"

#include <sys/time.h>
#include <time.h>

PG_MODULE_MAGIC;

/* Default CPU cost to start up a foreign query. */
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down