copy_execution_time_v2.patch
text/x-patch
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
Series: patch v2
| File | + | − |
|---|---|---|
| src/backend/commands/copy.c | 38 | 1 |
diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c
index e79ede4..ea0cc6e 100644
--- a/src/backend/commands/copy.c
+++ b/src/backend/commands/copy.c
@@ -61,6 +61,8 @@
#define ISOCTAL(c) (((c) >= '0') && ((c) <= '7'))
#define OCTVALUE(c) ((c) - '0')
+double copyreadlineTime, readTime, totalTime;
+
/*
* Represents the different source/dest cases we need to worry about at
* the bottom level
@@ -610,10 +612,12 @@ static int
CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
{
int bytesread = 0;
-
+ struct timespec before, after;
switch (cstate->copy_dest)
{
case COPY_FILE:
+ INSTR_TIME_SET_CURRENT(before);
+
bytesread = fread(databuf, 1, maxread, cstate->copy_file);
if (ferror(cstate->copy_file))
ereport(ERROR,
@@ -621,6 +625,10 @@ CopyGetData(CopyState cstate, void *databuf, int minread, int maxread)
errmsg("could not read from COPY file: %m")));
if (bytesread == 0)
cstate->reached_eof = true;
+
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ readTime += INSTR_TIME_GET_MILLISEC(after);
break;
case COPY_OLD_FE:
@@ -1059,8 +1067,15 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
if (is_from)
{
+ struct timespec before, after;
+ INSTR_TIME_SET_CURRENT(before);
Assert(rel);
+ /* Reset the variables before every copy operation */
+ readTime = 0;
+ copyreadlineTime = 0;
+ totalTime = 0;
+
/* check read-only transaction and parallel mode */
if (XactReadOnly && !rel->rd_islocaltemp)
PreventCommandIfReadOnly("COPY FROM");
@@ -1070,6 +1085,22 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt,
cstate->whereClause = whereClause;
*processed = CopyFrom(cstate); /* copy from file to database */
EndCopyFrom(cstate);
+
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ totalTime += INSTR_TIME_GET_MILLISEC(after);
+
+ elog(LOG, "Total file read time for copying operation : %.3f ms\n",
+ readTime);
+
+ /* Read time is included in copyreadlinetime*/
+ elog(LOG, "Total copyreadline time for copying operation: %.3f ms\n",
+ copyreadlineTime - readTime);
+
+ elog(LOG, "Remaining execution time for copying operation: %.3f ms\n",
+ totalTime - copyreadlineTime);
+ elog(LOG, "Total time for copying: %.3f ms\n", totalTime);
+
}
else
{
@@ -3890,12 +3921,14 @@ static bool
CopyReadLine(CopyState cstate)
{
bool result;
+ struct timespec before, after;
resetStringInfo(&cstate->line_buf);
cstate->line_buf_valid = true;
/* Mark that encoding conversion hasn't occurred yet */
cstate->line_buf_converted = false;
+ INSTR_TIME_SET_CURRENT(before);
/* Parse data and transfer into line_buf */
result = CopyReadLineText(cstate);
@@ -3949,6 +3982,10 @@ CopyReadLine(CopyState cstate)
}
}
+ INSTR_TIME_SET_CURRENT(after);
+ INSTR_TIME_SUBTRACT(after, before);
+ copyreadlineTime += INSTR_TIME_GET_MILLISEC(after);
+
/* Done reading the line. Convert it to server encoding. */
if (cstate->need_transcoding)
{