Just a different look at it ... sort of a "trace" file approach ... and not really thought through to any depth ... just add a few SP calls at points in the relevant places in the stored procedure in question and then review the trace file:
Original Message:
Sent: Fri February 07, 2025 08:56 AM
From: Andreas Legner
Subject: An accurate timestamp in a stored procedure
Hi Art,
I don't think it depends on USEOSTIME, it works well also with USEOSTIME 0.
And careful with the microseconds: e.g. a value of 153 first had to be left padded to full six digits 000153 before any decision on how many digits after the dot you're interested in.
Also: OUT instead of INOUT would of course be good enough in this case.
Andreas
------------------------------
Andreas Legner
Informix Dev
HCL Software
Original Message:
Sent: Fri February 07, 2025 08:28 AM
From: Art Kagel
Subject: An accurate timestamp in a stored procedure
Andreas:
Very cool function, but the underlying _ostime() function is an undocumented internal function. Also, it requires USEOSTIME to be set to 1 (and a server restart if it is not already set).
FWIW, here's a version of your "test" program that returns only five subsecond digits so it can be cast to a datetime for other uses and resolutions:
CREATE PROCEDURE IF NOT EXISTS ostime ()
-- returning integer, integer;
returning varchar(255);
define secs integer;
define usecs integer;
define rets varchar(255);
let secs = 0;
let usecs = 0;
call ostime(secs, usecs);
-- works:
-- return secs, usecs;
-- convert to string:
let rets = dbinfo('utc_to_datetime', secs) || '.' || lpad(usecs, 5, '0');
return rets;
end procedure;
So:
> select ostime()::datetime year to fraction(5), (ostime()::datetime year to fraction(5))::datetime hour to fraction(2);
(expression) (expression)
2025-02-07 08:27:34.82682 08:27:34.82
1 row(s) retrieved.
Art
------------------------------
Art S. Kagel, President and Principal Consultant
ASK Database Management Corp.
www.askdbmgt.com
Original Message:
Sent: Fri February 07, 2025 07:27 AM
From: Andreas Legner
Subject: An accurate timestamp in a stored procedure
Hi Andrew,
how about this guy:
create procedure ostime(inout integer, inout integer) external name '(_ostime)' language C;
Through its two inout params it will give you seconds and micro-seconds immediately from a call to gettimeofday().
To demonstrate:
create procedure test_ostime()
-- returning integer, integer;
returning varchar(255);
define secs integer;
define usecs integer;
define rets varchar(255);
let secs = 0;
let usecs = 0;
call ostime(secs, usecs);
-- works:
-- return secs, usecs;
-- convert to string:
let rets = dbinfo('utc_to_datetime', secs) || '.' || lpad(usecs, 6, '0');
return rets;
end procedure;
execute procedure test_ostime();
HTH,
Andreas
------------------------------
Andreas Legner
Informix Dev
HCL Software
Original Message:
Sent: Thu February 06, 2025 10:26 AM
From: Andrew Cilia
Subject: An accurate timestamp in a stored procedure
Hi All,
the background to this challenge is a repetitively used stored procedure that usually take no longer than 5 seconds each execution. Unfortunately, it is run thousands of times and so every millisecond I can drop off the SP execution time will help. So the plan of attack was to insert selects of the current timestamp in different places in the SP and run using debug to find the offending section in the SP. Basically a divide and rule approach.
BUT
1. We know that selecting the current timestamp in an SP is useless because, although it gives you fractions of a second, the timestamp does not change for the duration of the SP.
2. We can use select (dbinfo-utc_to_datetime sh_curtime) from sysmaster:sysshmvals but that sh_curtime is just an integer and thus has a resolution of just one second.
So, would I be right in saying that my only way around this is to call a UDR written in C or something that will provide me with the accuracy that I need?
------------------------------
Andrew Cilia
------------------------------