Re: pl/pgsql and returns timestamp type

From: Hubert depesz Lubaczewski <depesz(at)depesz(dot)pl>
To: Terry Yapt <yapt(at)technovell(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: pl/pgsql and returns timestamp type
Date: 2002-09-14 12:15:24
Message-ID: 20020914121524.GC32506@depesz.pl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, Sep 10, 2002 at 07:58:22PM +0200, Terry Yapt wrote:
> I am only testing different datatypes. In the example I would like to
> know how many time was spent by the function execution.

since we were bothered with this too (and measuring outside of function
was not an option - we had to test how much particular parts of function
takes time, we (friend of mine to be exact) wrote this code:

--- getcpuclock.c ---
#include <postgres.h>
#include <fmgr.h>

PG_FUNCTION_INFO_V1(getcpuclock);

Datum getcpuclock(PG_FUNCTION_ARGS)
{
uint64 tsc;

asm (
"\n\trdtsc"
"\n\tmovl\t%%eax,(%0)"
"\n\tmovl\t%%edx,4(%0)"
:
: "cx" (&tsc)
: "ax", "dx"
);

PG_RETURN_INT64(tsc);
}
--- getcpuclock.c ---

this compiled into .so, and installed into postgres with
CREATE FUNCTION getcpuclock() RETURNS INT8 AS '/home/users/pgdba/work/lib/getcpuclock.so' LANGUAGE 'C';

(or equivalent with corrected paths)
will give you function which returns number of processor ticks from last
bootup.
this is not easily convertible into seconds or anything else, but
provides very good accuracy, and is more or less perfect when measuring
how much time you spend on different tasks.

hope this helps a bit.

depesz

--
hubert depesz lubaczewski http://www.depesz.pl/
------------------------------------------------------------------------
Mój Boże, spraw abym milczał, dopóki się nie upewnię, że naprawdę mam
coś do powiedzenia. (c) 1998 depesz

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message J Matt Clark 2002-09-14 21:13:59 ODBC type "PG_TYPE_LO_NAME"
Previous Message sdeel 2002-09-14 04:41:49 how to process?