Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FOGL-9183: Round of the microseconds to seconds for time difference #93

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions C/services/notification/notification_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,13 @@ bool NotificationInstance::handleState(bool evalRet)
// Calculate time diff
timersub(&now_tv, &m_lastSentTv, &diffTimeTv);

// round up the seconds If microseconds are greater than or equal to 500000
if (diffTimeTv.tv_usec >= 500000)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if define it as const

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think, i fully understand the rationality of the logic here. What is the need to look into lower order precision (micros second) ? to override, high order precision ? Does our need to have time precision of 500 milli second ..?

I think it is better if we stick with the time precisions.

I see we are using gettimeofday() here are some resons we should not use it https://blog.habets.se/2010/09/gettimeofday-should-never-be-used-to-measure-time.html

Here the example code with custom precision.

    auto start = std::chrono::steady_clock::now();

    // Perform some operations
    for (int i = 0; i < 1000000; ++i);

    auto end = std::chrono::steady_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);

{
diffTimeTv.tv_sec = diffTimeTv.tv_sec + 1;
diffTimeTv.tv_usec = 0;
}

switch(nType.type)
{
case NotificationInstance::OneShot:
Expand Down