List:Internals« Previous MessageNext Message »
From:  Date:June 30 2006 5:28pm
Subject:Re: High precision time
View as plain text  
Thanks Wojciech:

I was working on that approach, but you beat me to it. Your code compiled and loaded fine,
but when I run the function in mysql, I get an integer result (similar to
unix_timestamp()).

devel> select micronow() ;
+------------+
| micronow() |
+------------+
| 1151688170 |
+------------+
1 row in set (0.01 sec)


Here is the code:

#include <mysql/mysql.h>
#include <sys/time.h>

my_bool micronow_init(UDF_INIT *initid,UDF_ARGS *args, char *message) {
return 0;
}

void micronow_deinit(UDF_INIT *initid) {}

double micronow(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length,
char *is_null, char *error) {
struct timeval tv;
struct timezone tz ;
gettimeofday(&tv,&tz);

return (double) ((double)tv.tv_usec)/1000000+tv.tv_sec;
}

Any idea why it is doing this?
Thanks,
Bill Willits

---- Wojciech Meler <wmeler@stripped> wrote:
> Why not to use UDF ?
>
> #include <mysql/mysql.h>
> #include <sys/time.h>
>
> my_bool hrtime_init(UDF_INIT *initid,UDF_ARGS *args, char *message) {
> return 0;
> }
>
> void hrtime_deinit(UDF_INIT *initid) {}
>
> double hrtime(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned
> long *le
> ngth, char *is_null, char *error) {
> struct timeval tv;
> gettimeofday(&tv,NULL);
>
> return ((double)tv.tv_usec)/1000000+tv.tv_sec;
> }
>
>
> oompile it:
>
> gcc -shared -o hrtime.so hrtime.c
>
> and install:
>
> CREATE FUNCTION hrtime RETURNS REAL SONAME 'hrtime.so'
>
>
> bwillits@stripped wrote:
> > Sorry:
> >
> > Language: MySQL native function (for use in a stored proc)
> > OS: Linux (CentOS)
> >
> > thanks,
> > BW
> >
> > ---- Rick James <rjames@stripped> wrote:
> >
> >>Language? OS?
> >>
> >>Perl has HiRes::Timer
> >>PHP has microtimes
> >>Windows has QueryPerformanceTimer
> >>Java has something
> >>
> >>
> >>>If the answer is no, can you point me to the code for now()
> >>>or similar so I could investigate adding such a function?
> >>
> >
> >
>
>
> --
> MySQL Internals Mailing List
> For list archives: http://lists.mysql.com/internals
> To unsubscribe: http://lists.mysql.com/internals?unsub=1
>

Thread
High precision timebwillits29 Jun
  • RE: High precision timeRick James29 Jun
  • Re: High precision timeSergei Golubchik30 Jun
RE: High precision timebwillits29 Jun
  • Re: High precision timeWojciech Meler30 Jun
Re: High precision timebwillits30 Jun
Re: High precision timebwillits1 Jul