Re: pl/pgsql and returns timestamp type - Mailing list pgsql-novice

From Hubert depesz Lubaczewski
Subject Re: pl/pgsql and returns timestamp type
Date
Msg-id 20020914121524.GC32506@depesz.pl
Whole thread Raw
In response to Re: pl/pgsql and returns timestamp type  (Terry Yapt <yapt@technovell.com>)
List 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


Attachment

pgsql-novice by date:

Previous
From: Rod Taylor
Date:
Subject: Re: [BUGS] Postgres storing time in strange manner
Next
From: "Mark Seftel"
Date:
Subject: SIGHUP postmaster