We help IT Professionals succeed at work.

TDateTime::CurrentDateTime - problem with accurate time in milliseconds

Eimund
Eimund asked
on
2,895 Views
Last Modified: 2008-07-20
Hey,

I'm makeing a log where I need a timestamp for each log. The problem is the accuracy of the milliseconds when I request consecutive timestamps. In my log, when requesting a new timestamp within 100ms, it seems that TDateTime::CurrentDateTime jumps 10ms instead of 1ms. A piece of my selfmade log is shown below. As you se least significant millisecond digit is 3, and the change occures from the is the second least significant millisecond digit.

I call the function AddEvent (code snipp attached) from a multithreaded environment by using TThread::Synchronize.

Do any one know the cause of this? And if so, is there a way to get 1ms accuracy of the timestamp?

Regards
Eimund Smestad

18.07.2008 09:09:07.073      Data written to Interface 1
0X00 0X9C 0X34 0X3B 0X06 0X6C 0X9F 0XB1 0X7E 0XB7 0XBF 0X55 0XFA 0X40 0XC9 0XD9 0X56 0X96 0XC6 0X3C 0X34 0X3D 0XBA 0X9E 0X4F 0XF5

18.07.2008 09:09:07.083      IN-datalength on interface 1 is set to 26 bytes

18.07.2008 09:09:07.083      OUT-datalength on interface 1 is set to 32 bytes

18.07.2008 09:09:07.103      Data written to Interface 1
0X00 0X5E 0X56 0XB2 0XEE 0X89 0X95 0X05 0X2B 0X16 0X80 0X97 0X95 0X34 0X31 0X80 0X45 0X22 0XE2 0XAA 0X2D 0X81 0XB5 0X83 0X66 0X18 0XCA 0X92 0XA8 0XA6 0X80 0X88

18.07.2008 09:09:07.113      IN-datalength on interface 1 is set to 32 bytes



void CUSB::Log::AddEvent(AnsiString event, bool blanckline)
{
	AnsiString text;
 
	tid = tid.CurrentTime();
	LongTimeFormat = "hh:nn:ss.zzz";
	text = "" + tid.CurrentDateTime() + "\t" + event;
	Log->Lines->Add(text);
	if(blanckline)
		Log->Lines->Add("");
}

Open in new window

Comment
Watch Question

cup

Commented:
The problem is how long Log->Lines->Add takes.  If that has to do any new/malloc/realloc or printf/cout, there is very little chance of getting accurate ms timings.  Best stick to seconds.

If it is just dumping it into an array which is picked up by a logger task you might get more accurate timings.
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.