diff options
author | Tom Lane | 2005-10-18 22:59:37 +0000 |
---|---|---|
committer | Tom Lane | 2005-10-18 22:59:37 +0000 |
commit | c4a54c6c09c9fe0c0a919ee9603a2b161e49d407 (patch) | |
tree | e7ed4fcfc447c75058993396d1cebef9c652c243 | |
parent | 63d39e128b22771ff06022e952e9e1dbd945d6ff (diff) |
Improve trace_sort code to also show the total memory or disk space used.
Per request from Marc.
-rw-r--r-- | src/backend/utils/sort/logtape.c | 9 | ||||
-rw-r--r-- | src/backend/utils/sort/tuplesort.c | 29 | ||||
-rw-r--r-- | src/include/utils/logtape.h | 1 |
3 files changed, 36 insertions, 3 deletions
diff --git a/src/backend/utils/sort/logtape.c b/src/backend/utils/sort/logtape.c index 4f6c55f181..2215062cf6 100644 --- a/src/backend/utils/sort/logtape.c +++ b/src/backend/utils/sort/logtape.c @@ -925,3 +925,12 @@ LogicalTapeTell(LogicalTapeSet *lts, int tapenum, *blocknum = lt->curBlockNumber; *offset = lt->pos; } + +/* + * Obtain total disk space currently used by a LogicalTapeSet, in blocks. + */ +long +LogicalTapeSetBlocks(LogicalTapeSet *lts) +{ + return lts->nFileBlocks; +} diff --git a/src/backend/utils/sort/tuplesort.c b/src/backend/utils/sort/tuplesort.c index aec2ed2cac..aad454e257 100644 --- a/src/backend/utils/sort/tuplesort.c +++ b/src/backend/utils/sort/tuplesort.c @@ -134,6 +134,7 @@ struct Tuplesortstate TupSortStatus status; /* enumerated value as shown above */ bool randomAccess; /* did caller request random access? */ long availMem; /* remaining memory available, in bytes */ + long allowedMem; /* total memory allowed, in bytes */ LogicalTapeSet *tapeset; /* logtape.c object for tapes in a temp file */ /* @@ -433,7 +434,8 @@ tuplesort_begin_common(int workMem, bool randomAccess) state->status = TSS_INITIAL; state->randomAccess = randomAccess; - state->availMem = workMem * 1024L; + state->allowedMem = workMem * 1024L; + state->availMem = state->allowedMem; state->tapeset = NULL; state->memtupcount = 0; @@ -582,9 +584,24 @@ void tuplesort_end(Tuplesortstate *state) { int i; +#ifdef TRACE_SORT + long spaceUsed; +#endif if (state->tapeset) + { +#ifdef TRACE_SORT + spaceUsed = LogicalTapeSetBlocks(state->tapeset); +#endif LogicalTapeSetClose(state->tapeset); + } + else + { +#ifdef TRACE_SORT + spaceUsed = (state->allowedMem - state->availMem + 1023) / 1024; +#endif + } + if (state->memtuples) { for (i = 0; i < state->memtupcount; i++) @@ -604,8 +621,14 @@ tuplesort_end(Tuplesortstate *state) #ifdef TRACE_SORT if (trace_sort) - elog(NOTICE, "sort ended: %s", - pg_rusage_show(&state->ru_start)); + { + if (state->tapeset) + elog(NOTICE, "external sort ended, %ld disk blocks used: %s", + spaceUsed, pg_rusage_show(&state->ru_start)); + else + elog(NOTICE, "internal sort ended, %ld KB used: %s", + spaceUsed, pg_rusage_show(&state->ru_start)); + } #endif pfree(state); diff --git a/src/include/utils/logtape.h b/src/include/utils/logtape.h index e8f1483a75..0d45ff979a 100644 --- a/src/include/utils/logtape.h +++ b/src/include/utils/logtape.h @@ -38,5 +38,6 @@ extern bool LogicalTapeSeek(LogicalTapeSet *lts, int tapenum, long blocknum, int offset); extern void LogicalTapeTell(LogicalTapeSet *lts, int tapenum, long *blocknum, int *offset); +extern long LogicalTapeSetBlocks(LogicalTapeSet *lts); #endif /* LOGTAPE_H */ |