for using it for other things besides VACUUM.
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.315 2005/09/22 17:32:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.316 2005/10/03 22:52:21 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "utils/inval.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
+#include "utils/pg_rusage.h"
#include "utils/relcache.h"
#include "utils/syscache.h"
#include "pgstat.h"
VTupleLink vtlinks = (VTupleLink) palloc(100 * sizeof(VTupleLinkData));
int num_vtlinks = 0;
int free_vtlinks = 100;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
relname = RelationGetRelationName(onerel);
ereport(elevel,
"Total free space (including removable row versions) is %.0f bytes.\n"
"%u pages are or will become empty, including %u at the end of the table.\n"
"%u pages containing %.0f free bytes are potential move destinations.\n"
- "%s",
+ "%s.",
nkeep,
(unsigned long) min_tlen, (unsigned long) max_tlen,
nunused,
free_space,
empty_pages, empty_end_pages,
fraged_pages->num_pages, usable_free_space,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
}
num_fraged_pages,
vacuumed_pages;
int keep_tuples = 0;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
ExecContext_Init(&ec, onerel);
(errmsg("\"%s\": moved %u row versions, truncated %u to %u pages",
RelationGetRelationName(onerel),
num_moved, nblocks, blkno),
- errdetail("%s",
- vac_show_rusage(&ru0))));
+ errdetail("%s.",
+ pg_rusage_show(&ru0))));
/*
* Reflect the motion of system tuples to catalog cache here.
{
IndexBulkDeleteResult *stats;
IndexVacuumCleanupInfo vcinfo;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
/*
* Even though we're not planning to delete anything, we use the
stats->num_index_tuples,
stats->num_pages),
errdetail("%u index pages have been deleted, %u are currently reusable.\n"
- "%s",
+ "%s.",
stats->pages_deleted, stats->pages_free,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
/*
* Check for tuple count mismatch. If the index is partial, then it's
{
IndexBulkDeleteResult *stats;
IndexVacuumCleanupInfo vcinfo;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
/* Do bulk deletion */
stats = index_bulk_delete(indrel, tid_reaped, (void *) vacpagelist);
stats->num_pages),
errdetail("%.0f index row versions were removed.\n"
"%u index pages have been deleted, %u are currently reusable.\n"
- "%s",
+ "%s.",
stats->tuples_removed,
stats->pages_deleted, stats->pages_free,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
/*
* Check for tuple count mismatch. If the index is partial, then it's
}
-/*
- * Initialize usage snapshot.
- */
-void
-vac_init_rusage(VacRUsage *ru0)
-{
- struct timezone tz;
-
- getrusage(RUSAGE_SELF, &ru0->ru);
- gettimeofday(&ru0->tv, &tz);
-}
-
-/*
- * Compute elapsed time since ru0 usage snapshot, and format into
- * a displayable string. Result is in a static string, which is
- * tacky, but no one ever claimed that the Postgres backend is
- * threadable...
- */
-const char *
-vac_show_rusage(VacRUsage *ru0)
-{
- static char result[100];
- VacRUsage ru1;
-
- vac_init_rusage(&ru1);
-
- if (ru1.tv.tv_usec < ru0->tv.tv_usec)
- {
- ru1.tv.tv_sec--;
- ru1.tv.tv_usec += 1000000;
- }
- if (ru1.ru.ru_stime.tv_usec < ru0->ru.ru_stime.tv_usec)
- {
- ru1.ru.ru_stime.tv_sec--;
- ru1.ru.ru_stime.tv_usec += 1000000;
- }
- if (ru1.ru.ru_utime.tv_usec < ru0->ru.ru_utime.tv_usec)
- {
- ru1.ru.ru_utime.tv_sec--;
- ru1.ru.ru_utime.tv_usec += 1000000;
- }
-
- snprintf(result, sizeof(result),
- "CPU %d.%02ds/%d.%02du sec elapsed %d.%02d sec.",
- (int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
- (int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
- (int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
- (int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
- (int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
- (int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);
-
- return result;
-}
-
/*
* vacuum_delay_point --- check for interrupts and cost-based delay.
*
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.59 2005/09/22 17:32:58 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.60 2005/10/03 22:52:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#include "storage/freespace.h"
#include "storage/smgr.h"
#include "utils/lsyscache.h"
+#include "utils/pg_rusage.h"
/*
BlockNumber *index_pages_removed;
bool did_vacuum_index = false;
int i;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
relname = RelationGetRelationName(onerel);
ereport(elevel,
errdetail("%.0f dead row versions cannot be removed yet.\n"
"There were %.0f unused item pointers.\n"
"%u pages are entirely empty.\n"
- "%s",
+ "%s.",
nkeep,
nunused,
empty_pages,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
}
{
int tupindex;
int npages;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
npages = 0;
tupindex = 0;
(errmsg("\"%s\": removed %d row versions in %d pages",
RelationGetRelationName(onerel),
tupindex, npages),
- errdetail("%s",
- vac_show_rusage(&ru0))));
+ errdetail("%s.",
+ pg_rusage_show(&ru0))));
}
/*
{
IndexBulkDeleteResult *stats;
IndexVacuumCleanupInfo vcinfo;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
/*
* Acquire appropriate type of lock on index: must be exclusive if
stats->num_index_tuples,
stats->num_pages),
errdetail("%u index pages have been deleted, %u are currently reusable.\n"
- "%s",
+ "%s.",
stats->pages_deleted, stats->pages_free,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
pfree(stats);
}
{
IndexBulkDeleteResult *stats;
IndexVacuumCleanupInfo vcinfo;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
/*
* Acquire appropriate type of lock on index: must be exclusive if
stats->num_pages),
errdetail("%.0f index row versions were removed.\n"
"%u index pages have been deleted, %u are currently reusable.\n"
- "%s",
+ "%s.",
stats->tuples_removed,
stats->pages_deleted, stats->pages_free,
- vac_show_rusage(&ru0))));
+ pg_rusage_show(&ru0))));
pfree(stats);
}
int n;
int i,
j;
- VacRUsage ru0;
+ PGRUsage ru0;
- vac_init_rusage(&ru0);
+ pg_rusage_init(&ru0);
/*
* We need full exclusive lock on the relation in order to do
(errmsg("\"%s\": truncated %u to %u pages",
RelationGetRelationName(onerel),
old_rel_pages, new_rel_pages),
- errdetail("%s",
- vac_show_rusage(&ru0))));
+ errdetail("%s.",
+ pg_rusage_show(&ru0))));
}
/*
# Makefile for utils/misc
#
# IDENTIFICATION
-# $PostgreSQL: pgsql/src/backend/utils/misc/Makefile,v 1.23 2005/02/26 18:43:33 tgl Exp $
+# $PostgreSQL: pgsql/src/backend/utils/misc/Makefile,v 1.24 2005/10/03 22:52:23 tgl Exp $
#
#-------------------------------------------------------------------------
override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
-OBJS = guc.o help_config.o ps_status.o superuser.o
+OBJS = guc.o help_config.o pg_rusage.o ps_status.o superuser.o
# This location might depend on the installation directories. Therefore
# we can't subsitute it into pg_config.h.
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * pg_rusage.c
+ * Resource usage measurement support routines.
+ *
+ *
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * $PostgreSQL: pgsql/src/backend/utils/misc/pg_rusage.c,v 1.1 2005/10/03 22:52:23 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include <unistd.h>
+
+#include "utils/pg_rusage.h"
+
+
+/*
+ * Initialize usage snapshot.
+ */
+void
+pg_rusage_init(PGRUsage *ru0)
+{
+ struct timezone tz;
+
+ getrusage(RUSAGE_SELF, &ru0->ru);
+ gettimeofday(&ru0->tv, &tz);
+}
+
+/*
+ * Compute elapsed time since ru0 usage snapshot, and format into
+ * a displayable string. Result is in a static string, which is
+ * tacky, but no one ever claimed that the Postgres backend is
+ * threadable...
+ */
+const char *
+pg_rusage_show(const PGRUsage *ru0)
+{
+ static char result[100];
+ PGRUsage ru1;
+
+ pg_rusage_init(&ru1);
+
+ if (ru1.tv.tv_usec < ru0->tv.tv_usec)
+ {
+ ru1.tv.tv_sec--;
+ ru1.tv.tv_usec += 1000000;
+ }
+ if (ru1.ru.ru_stime.tv_usec < ru0->ru.ru_stime.tv_usec)
+ {
+ ru1.ru.ru_stime.tv_sec--;
+ ru1.ru.ru_stime.tv_usec += 1000000;
+ }
+ if (ru1.ru.ru_utime.tv_usec < ru0->ru.ru_utime.tv_usec)
+ {
+ ru1.ru.ru_utime.tv_sec--;
+ ru1.ru.ru_utime.tv_usec += 1000000;
+ }
+
+ snprintf(result, sizeof(result),
+ "CPU %d.%02ds/%d.%02du sec elapsed %d.%02d sec",
+ (int) (ru1.ru.ru_stime.tv_sec - ru0->ru.ru_stime.tv_sec),
+ (int) (ru1.ru.ru_stime.tv_usec - ru0->ru.ru_stime.tv_usec) / 10000,
+ (int) (ru1.ru.ru_utime.tv_sec - ru0->ru.ru_utime.tv_sec),
+ (int) (ru1.ru.ru_utime.tv_usec - ru0->ru.ru_utime.tv_usec) / 10000,
+ (int) (ru1.tv.tv_sec - ru0->tv.tv_sec),
+ (int) (ru1.tv.tv_usec - ru0->tv.tv_usec) / 10000);
+
+ return result;
+}
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.60 2005/07/14 05:13:43 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.61 2005/10/03 22:52:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
#ifndef VACUUM_H
#define VACUUM_H
-#include <sys/time.h>
-
-#ifdef HAVE_GETRUSAGE
-#include <sys/resource.h>
-#else
-#include "rusagestub.h"
-#endif
-
#include "access/htup.h"
#include "catalog/pg_attribute.h"
#include "catalog/pg_statistic.h"
} VacAttrStats;
-/* State structure for vac_init_rusage/vac_show_rusage */
-typedef struct VacRUsage
-{
- struct timeval tv;
- struct rusage ru;
-} VacRUsage;
-
/* Default statistics target (GUC parameter) */
extern DLLIMPORT int default_statistics_target; /* DLLIMPORT for PostGIS */
TransactionId *oldestXmin,
TransactionId *freezeLimit);
extern bool vac_is_partial_index(Relation indrel);
-extern void vac_init_rusage(VacRUsage *ru0);
-extern const char *vac_show_rusage(VacRUsage *ru0);
extern void vacuum_delay_point(void);
/* in commands/vacuumlazy.c */
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * pg_rusage.h
+ * header file for resource usage measurement support routines
+ *
+ *
+ * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $PostgreSQL: pgsql/src/include/utils/pg_rusage.h,v 1.1 2005/10/03 22:52:26 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_RUSAGE_H
+#define PG_RUSAGE_H
+
+#include <sys/time.h>
+
+#ifdef HAVE_GETRUSAGE
+#include <sys/resource.h>
+#else
+#include "rusagestub.h"
+#endif
+
+
+/* State structure for pg_rusage_init/pg_rusage_show */
+typedef struct PGRUsage
+{
+ struct timeval tv;
+ struct rusage ru;
+} PGRUsage;
+
+
+extern void pg_rusage_init(PGRUsage *ru0);
+extern const char *pg_rusage_show(const PGRUsage *ru0);
+
+#endif /* PG_RUSAGE_H */