Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions util/TimeUtil.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
#pragma once
#include <sys/time.h>
#include "util/Types.hpp"
#include <sys/time.h>

#ifdef MONOTONIC_CLOCK
#include <time.h>
#endif

namespace TimeUtil
namespace TimeUtil {
static u64 utime()
{
static u64 utime()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return (u64)tv.tv_sec * 1000000 + tv.tv_usec;
}
#ifdef MONOTONIC_CLOCK
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC_RAW, &ts); // or CLOCK_MONOTONIC
return (uint64_t)ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000ULL;
#else
struct timeval tv;
gettimeofday(&tv, NULL);
return (u64)tv.tv_sec * 1000000 + tv.tv_usec;
#endif
}
} // namespace TimeUtil
13 changes: 13 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def add_zcm_configure_options(ctx):
choices=['true', 'false'],
help='Include the zcmtype name in the hash generation')

# RRR (Jakob H.): Shouldn't this default to false so that the previous default behavior
# is preserved?
gr.add_option('--monotonic-clock', dest='monotonic_clock', default='true',
choices=['true', 'false'],
help='Instead of using the system clock, use a clock source that is guaranteed '
'to be monotonic for all utimes internally')

add_use_option('dev', 'Enable all dev tools')
add_use_option('build-cache', 'Enable the build cache for faster rebuilds')
add_use_option('clang', 'Enable build using clang sanitizers')
Expand Down Expand Up @@ -179,6 +186,8 @@ def process_zcm_configure_options(ctx):
env.HASH_TYPENAME = getattr(opt, 'hash_typename')
env.HASH_MEMBER_NAMES = getattr(opt, 'hash_member_names')

env.MONOTONIC_CLOCK = getattr(opt, 'monotonic_clock')

env.USING_CACHE = hasoptDev('use_build_cache') and attempt_use_cache(ctx)
env.USING_CLANG = hasoptDev('use_clang') and attempt_use_clang(ctx)
env.USING_CXXTEST = hasoptDev('use_cxxtest') and attempt_use_cxxtest(ctx)
Expand Down Expand Up @@ -228,6 +237,7 @@ def process_zcm_configure_options(ctx):
Logs.pprint('BLUE', '\nType Configuration:')
print_entry("hash-typename", env.HASH_TYPENAME == 'true')
print_entry("hash-member-names", env.HASH_MEMBER_NAMES == 'true', True)
print_entry("monotonic-clock", env.MONOTONIC_CLOCK == 'true', True)

Logs.pprint('BLUE', '\nDev Configuration:')
print_entry("Build Cache", env.USING_CACHE)
Expand Down Expand Up @@ -420,6 +430,9 @@ def setup_environment(ctx):
if ctx.env.HASH_MEMBER_NAMES == 'true':
ctx.env.DEFINES_default.append("ENABLE_MEMBERNAME_HASHING")

if ctx.env.MONOTONIC_CLOCK == 'true':
ctx.env.DEFINES_default.append("MONOTONIC_CLOCK")

if ctx.env.TRACK_TRAFFIC_TOPOLOGY == 'true':
ctx.env.DEFINES_default.append("TRACK_TRAFFIC_TOPOLOGY")

Expand Down
Loading