Change time precision in ascii trace

60 views
Skip to first unread message

Vaibhav Agrawal

unread,
Jun 23, 2021, 10:07:06 AM6/23/21
to ns-3-users
Hello All,
I want to have a precision of nano seconds (9 places after decimal) in ASCII trace but by default it seems to have a precision of 10 microseconds (5 places after decimal). Is there anyone who knows how to change the precision of ASCII trace?

PS: setting global time resolution to nano seconds doesn't work.

Thank you for you time.

Vaibhav Agrawal

unread,
Jul 8, 2021, 9:47:32 AM7/8/21
to ns-3-users
For wireless sensor network.

Code snippet:

.....
YansWifiPhyHelper wifiPhy;
.....
AsciiTraceHelper ascii;
wifiPhy.EnableAsciiAll (ascii.CreateFileStream ("static-15nodes.tr"));
.....

But it seems like the time value is with 6 significant figures only. I desire it to be of 1 nanosecond accuracy for my academic project.
Please help!!

Adil Alsuhaim

unread,
Jul 9, 2021, 10:19:17 AM7/9/21
to ns-3-users
In C++, we use output streams with the << operator. Printing to the screen (standard output) is done with std::cout << which would print numbers to the screen with some default precision, that precision can be changed with the precision function for std::cout. The same thing can be done for other output streams, i.e. streams to files, and what the ASCII helper of ns-3 uses is std::ostream to output to a file.

ns-3 uses a class called OutputStreamWrapper for ASCII outputs. I suggest that you try changing the code of that class by specifying a higher precision. Go to the file ./src/network/utils/output-stream-wrapper.cc and in the constructor add the following line at the end:
    
    m_ostream->precision (9);

Which I think would change the precision to 9 decimal places and should work for all your ASCII traces.

Cheers,
Adil

Vaibhav Agrawal

unread,
Jul 9, 2021, 10:33:38 AM7/9/21
to ns-3-users
Sir,
That worked perfectly.
Thank you so much!!

Adil Alsuhaim

unread,
Jul 10, 2021, 12:17:39 AM7/10/21
to ns-3-users
No problems! Glad I could help!
Reply all
Reply to author
Forward
0 new messages