Review the pgsysconf function
authorCédric Villemain <cedric@2ndquadrant.fr>
Sat, 14 May 2011 21:33:16 +0000 (23:33 +0200)
committerCédric Villemain <cedric@2ndquadrant.fr>
Sun, 15 May 2011 01:03:00 +0000 (03:03 +0200)
Change fields name and remove useless elog

pgfincore.c
pgfincore.sql.in

index 21603f9b22077945fc8fc0c81d93ff007d0d9cdf..baed710b46c80dd6fd252bee414f937479a27a4c 100644 (file)
@@ -1,11 +1,12 @@
 /*
 *  PgFincore
-*  This project let you see what objects are in the FS cache memory
-*  Copyright (C) 2009 Cédric Villemain
+*  This project let you see and mainpulate objects in the FS page cache
+*  Copyright (C) 2009-2011 Cédric Villemain
 */
 
 /* { POSIX stuff */
 #define _XOPEN_SOURCE 600 /* fadvise */
+
 #include <stdlib.h> /* exit, calloc, free */
 #include <sys/stat.h> /* stat, fstat */
 #include <sys/types.h> /* size_t, mincore */
@@ -90,6 +91,7 @@ static bool RelationUsesTempNamespace(Relation relation)
  * just output the actual system value for
  * _SC_PAGESIZE     --> Page Size
  * _SC_AVPHYS_PAGES --> Free page in memory
+ * _SC_PHYS_PAGES   --> Total memory
  *
  */
 PG_FUNCTION_INFO_V1(pgsysconf);
@@ -97,34 +99,38 @@ Datum
 pgsysconf(PG_FUNCTION_ARGS)
 {
        HeapTuple       tuple;
-       TupleDesc tupdesc;
+       TupleDesc       tupdesc;
        Datum           values[PGSYSCONF_COLS];
        bool            nulls[PGSYSCONF_COLS];
 
        tupdesc = CreateTemplateTupleDesc(PGSYSCONF_COLS, false);
-       TupleDescInitEntry(tupdesc, (AttrNumber) 1, "block_size",  INT8OID, -1, 0);
-    TupleDescInitEntry(tupdesc, (AttrNumber) 2, "block_free",  INT8OID, -1, 0);
-    TupleDescInitEntry(tupdesc, (AttrNumber) 3, "total_blocks",  INT8OID, -1, 0);
+       TupleDescInitEntry(tupdesc, (AttrNumber) 1, "os_page_size",   INT8OID, -1, 0);
+       TupleDescInitEntry(tupdesc, (AttrNumber) 2, "os_pages_free",  INT8OID, -1, 0);
+       TupleDescInitEntry(tupdesc, (AttrNumber) 3, "os_total_pages", INT8OID, -1, 0);
        tupdesc = BlessTupleDesc(tupdesc);
 
-       values[0] = Int64GetDatum(sysconf(_SC_PAGESIZE));  /* Page size */
-    values[1] = Int64GetDatum(sysconf(_SC_AVPHYS_PAGES));  /* free page in memory */
-    values[2] = Int64GetDatum(sysconf(_SC_PHYS_PAGES));  /* total memory */
-       memset(nulls, 0, sizeof(nulls));
+       /* Page size */
+       values[0] = Int64GetDatum(sysconf(_SC_PAGESIZE));
 
+       /* free page in memory */
+       values[1] = Int64GetDatum(sysconf(_SC_AVPHYS_PAGES));
+
+       /* total memory */
+       values[2] = Int64GetDatum(sysconf(_SC_PHYS_PAGES));
+
+       memset(nulls, 0, sizeof(nulls));
        tuple = heap_form_tuple(tupdesc, values, nulls);
-       elog(DEBUG1, "pgsysconf: page_size %lld bytes, free page in memory %lld, total memory pages %lld",
-            (int64) values[0], (int64) values[1], (int64) values[2]);
        PG_RETURN_DATUM( HeapTupleGetDatum(tuple) );
 }
 
 /*
-*
-* pgfincore is a function that handle the process to have a sharelock on the relation
-* and to walk the segments.
-* for each segment it call the appropriate function depending on 'action' parameter
-*
-*/
+ *
+ * pgfincore is a function that handle the process to have a sharelock
+ * on the relation and to walk the segments.
+ * for each segment it call the appropriate function depending on 'action'
+ * parameter
+ *
+ */
 PG_FUNCTION_INFO_V1(pgfincore);
 Datum
 pgfincore(PG_FUNCTION_ARGS)
index 6b4c9faaa671901ab7984a498ff889b186f674c4..2d74626d7bb48f9d522735a32d7a90b059c8bd6e 100644 (file)
@@ -1,22 +1,25 @@
 SET search_path = public;
 
+--
+-- SYSCONF
+--
 CREATE OR REPLACE FUNCTION
-pgsysconf(OUT block_size   bigint,
-          OUT block_free   bigint,
-          OUT total_blocks bigint)
+pgsysconf(OUT os_page_size   bigint,
+          OUT os_pages_free  bigint,
+          OUT os_total_pages bigint)
 RETURNS record
 AS 'MODULE_PATHNAME'
 LANGUAGE C;
 
 CREATE OR REPLACE FUNCTION
-pgsysconf_pretty(OUT block_size   text,
-                 OUT free_memory  text,
-                 OUT total_memory text)
+pgsysconf_pretty(OUT os_page_size   text,
+                 OUT os_pages_free  text,
+                 OUT os_total_pages text)
 RETURNS record
 AS '
-select pg_size_pretty(block_size) as block_size,
-       pg_size_pretty(block_free * block_size) as free_memory,
-       pg_size_pretty(total_blocks * block_size) as total_memory
+select pg_size_pretty(os_page_size) as os_page_size,
+       pg_size_pretty(os_pages_free * os_page_size) as os_pages_free,
+       pg_size_pretty(os_total_pages * os_page_size) as os_total_pages
 from pgsysconf()'
 LANGUAGE SQL;