Re: Measuring the execution time of functions within functions...

From: Jerry Sievers <jerry(at)jerrysievers(dot)com>
To: mario(dot)splivalo(at)mobart(dot)hr
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Measuring the execution time of functions within functions...
Date: 2006-04-03 16:32:09
Message-ID: m3irpqei2d.fsf@prod01.jerrysievers.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Mario Splivalo <mario(dot)splivalo(at)mobart(dot)hr> writes:

> I have asked this before, but haven't noticed any response, so if there
> were any, I appologize for asking this again...
>
> I have a function that is called by middle-tier (java trough JDBC), and
> in postgres log I can see only the execution time of that function. I
> have no idea how long are functions insde taking time to execute.
>
> Since the function is written in plpgsql I tried to calculate the
> durations by using now() function, but realized that within the
> transaction now() always retunrs the same value.
>
> The good thing is that those RAISE NOTICE calls from within my function
> are logged as they're encountered, so, with carefully placed RAISE
> NOTICE calls I could see how much time are the -inside- functions
> taking.
>
> For instance:
>
> CREATE FUNCTION test_outer() RETURNS void
> AS
> $$BODY$$BEGIN
> RAISE NOTICE 'We start here'
> PERFORM SELECT someInternalFunction1();
> RAISE NOTICE 'InternalFunction1 is done now.';
> PERFORM SELECT someInternalFunction2();
> RAISE NOTICE 'InternalFunction2 is done now.';
> -- ... more code here
> END$$BODY$$
> LANGUAGE 'plpgsql'
>
> Is there any other, maybe more convinient way to measure the 'inside'
> function performance? I also have a problem if the outer function is
> written in SQL, like this, for instance:

See the timeofday() func which returns the actual time and is not
frozen in the current transaction. You'll need to cast it to
timestamp or other if wishing to do time arithmetic deltas on it.

HTH

--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Kenji Morishige 2006-04-03 18:24:03 optimizing db for small table with tons of updates
Previous Message Alvaro Herrera 2006-04-03 12:50:47 Re: Measuring the execution time of functions within functions...