Skip to content

Commit

Permalink
Improve timestamp by get it from syscall. (#3958)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg committed Mar 2, 2022
1 parent 1eda1f5 commit b87de93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/common/function/FunctionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ FunctionManager::FunctionManager() {
attr.isPure_ = false;
attr.body_ = [](const auto &args) -> Value {
UNUSED(args);
return time::WallClock::fastNowInSec();
return ::time(NULL);
};
}
{
Expand Down Expand Up @@ -1765,7 +1765,7 @@ FunctionManager::FunctionManager() {
attr.isPure_ = false;
attr.body_ = [](const auto &args) -> Value {
if (args.empty()) {
return time::WallClock::fastNowInSec();
return ::time(NULL);
}
auto status = time::TimeUtils::toTimestamp(args[0].get());
if (!status.ok()) {
Expand Down
5 changes: 3 additions & 2 deletions src/common/time/TimeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ class TimeUtils {

// <seconds, milliseconds>
static UnixTime unixTime() {
auto ms = WallClock::fastNowInMilliSec();
return UnixTime{ms / 1000, ms % 1000};
::timespec ts;
::clock_gettime(CLOCK_REALTIME, &ts);
return UnixTime{ts.tv_sec, ::lround(ts.tv_nsec / 1000000)};
}
}; // class TimeUtils

Expand Down

0 comments on commit b87de93

Please sign in to comment.