Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

system time in milliseconds

Status
Not open for further replies.

Hopeful22

MIS
Dec 27, 2001
11
US
I'm try to convert the system date/clock time to milliseconds in order to measure relative completion time of an event. I am sending a tcp connect request from unix A to unix B. I would set T1 on unix A when the request was sent, and set T2 on unix B when request was received.
T2 - T1 = delay_time

Both system times are sync'd via NTP.
Subtraction of [clock click -milliseconds] on both sides yields a negative value. I'm thinking the [clock clicks] is not based on system time but cpu clocks. Both unix boxes are same model.

Any suggestions would be appreciated.
thanks
 
If you are convinced that clock clicks is not what you
could try something like this:

#include <stdio.h>
#include <time.h>

int main(void) {
time_t ltime;

time(&ltime);
printf(&quot;%ld\n&quot;, (long)localtime(&ltime));
return 0;
}
Compile and save as systime.
Then:
--------------------------
proc stime {} {
uplevel #0 &quot;set systemtime [exec pathto/systime]&quot;
return
}
 
I was trying out your suggestion. However, I'm receiving compiling errors:

host# gcc systime.c
systime.c: In function `main':
systime.c:7: parse error before `<'
systime.c:8: parse error before `<'

Might I be missing something?

thanks in advance!
 
I tried to compile it on 2 different systems, but I get the same error.

hostA]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-98)

hostB# gcc -v
Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.8/3.2/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --disable-nls
Thread model: posix
gcc version 3.2
 
Sorry, the first one wouldn't have returned anything valuable. This program returns microseconds which
are divided by 1000. If this doesn't compile I don't know what to tell you. It compiles fine on:
gcc version 2.95.3 20010315 (SuSE)

#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>



int main(void) {
struct timeval mytime;
struct timezone tz;

if ( (gettimeofday(&mytime,&tz)) != 0) {
perror(&quot;gettimeofday failed&quot;);
return 1;
} else {
printf(&quot;Milliseconds: %ld\n&quot;, mytime.tv_usec / 1000);
return 0;
}
return 1;
}
 
That definitely did the trick! It compiled fine.

Thanks a lot marsd! :)
 
After some further testing, I am getting some negative values sometimes when I do, where stime calls the C program referred in the prior postings:

set START_TIME [stime]
<snip>
...
wait for data
...
<snip>
set END_TIME [stime]

Total time: [expr $END_TIME - $START_TIME]

Any ideas?
Thanks in advance!
 
The turnover is every second.

mars@skag:~/cscraps > stime=`ms`
mars@skag:~/cscraps > etime=`ms`
mars@skag:~/cscraps > echo $stime $etime
Milliseconds: 889 Milliseconds: 654
mars@skag:~/cscraps > stime=`ms`
mars@skag:~/cscraps > etime=`ms`
mars@skag:~/cscraps > echo $stime $etime
Milliseconds: 433 Milliseconds: 949

Can you work with this or do you need milliseconds
measured by the hour, minute, or what???
 
Thanks for your input. It would work better if there's a way to measure the milliseconds by the minute or hour. Reason being it gives no indication on how many turnovers actually occurred.

thanks again





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top