From fe787aa87b250e8baefb275424b6e2fffa8c38f9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Villemain?= Date: Thu, 10 Dec 2009 03:20:22 +0100 Subject: [PATCH] add pgsysconf() --- ChangeLog | 1 + pgfincore.c | 36 ++++++++++++++++++++++++++++++++++++ pgfincore.sql.in | 8 ++++++++ 3 files changed, 45 insertions(+) diff --git a/ChangeLog b/ChangeLog index 04f7a86..44095b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -9,6 +9,7 @@ - add posix_fadvise_random flag - rewrite main SRF - improve output (more informations) + - add pgsysconf() 26/10/2009 Cédric Villemain diff --git a/pgfincore.c b/pgfincore.c index d8ad3a6..1b5220a 100644 --- a/pgfincore.c +++ b/pgfincore.c @@ -39,6 +39,7 @@ typedef struct char *relationpath; /* the relation path */ } pgfincore_fctx; +Datum pgsysconf(PG_FUNCTION_ARGS); Datum pgfincore(PG_FUNCTION_ARGS); static Datum pgmincore_file(char *filename, FunctionCallInfo fcinfo); @@ -46,6 +47,41 @@ static Datum pgfadvise_file(char *filename, int action, FunctionCallInfo fcinfo); + /* + * pgsysconf + */ +PG_FUNCTION_INFO_V1(pgsysconf); +Datum +pgsysconf(PG_FUNCTION_ARGS) { + HeapTuple tuple; + TupleDesc tupdesc; + Datum values[3]; + bool nulls[3]; + + // OS things + int64 pageSize = sysconf(_SC_PAGESIZE); /* Page size */ + int64 pageCache = sysconf(_SC_PHYS_PAGES); /* total page cache */ + int64 pageFree = sysconf(_SC_AVPHYS_PAGES); /* free page cache */ + + tupdesc = CreateTemplateTupleDesc(3, false); + TupleDescInitEntry(tupdesc, (AttrNumber) 1, "block_size", + INT8OID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 2, "block_cache", + INT8OID, -1, 0); + TupleDescInitEntry(tupdesc, (AttrNumber) 3, "block_free", + INT8OID, -1, 0); + + tupdesc = BlessTupleDesc(tupdesc); + + values[0] = Int64GetDatum(pageSize); + values[1] = Int64GetDatum(pageCache); + values[2] = Int64GetDatum(pageFree); + + tuple = heap_form_tuple(tupdesc, values, nulls); + + PG_RETURN_DATUM( HeapTupleGetDatum(tuple) ); +} + /* fincore - */ PG_FUNCTION_INFO_V1(pgfincore); diff --git a/pgfincore.sql.in b/pgfincore.sql.in index 5311359..fd60df2 100644 --- a/pgfincore.sql.in +++ b/pgfincore.sql.in @@ -1,5 +1,13 @@ SET search_path = public; +CREATE OR REPLACE FUNCTION +pgsysconf(OUT block_size bigint, + OUT block_cache bigint, + OUT block_free bigint) +RETURNS record +AS 'MODULE_PATHNAME' +LANGUAGE C; + CREATE OR REPLACE FUNCTION pgfincore(IN regclass, IN text, -- 2.39.5