Skip to content

Commit

Permalink
BUILD: corrected system_clock duration for clang
Browse files Browse the repository at this point in the history
In GCC STL system_clock the duration is in nanoseconds, but in clang it
is in microseconds.

Also, the package version has been changed to 1.1.2 and the library
version to 1.1.1.
  • Loading branch information
zaga00 committed Oct 9, 2021
1 parent 0288fec commit 7cb9ca9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Package Version: 1.1.1
Library Version: 1:0:1
Package Version: 1.1.2
Library Version: 1:1:1
1 change: 1 addition & 0 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extern otc_ext_malloc_t otc_ext_malloc;
extern otc_ext_free_t otc_ext_free;


std::chrono::microseconds timespec_to_duration_us(const struct timespec *ts);
std::chrono::nanoseconds timespec_to_duration(const struct timespec *ts);
const char *otc_strerror(int errnum);

Expand Down
4 changes: 4 additions & 0 deletions src/span.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ static void ot_span_finish_with_options(struct otc_span *span, const struct otc_
struct opentracing::LogRecord record;

if (options->log_records[i].timestamp.value.tv_sec > 0) {
#ifdef __clang__
auto dt = timespec_to_duration_us(&(options->log_records[i].timestamp.value));
#else
auto dt = timespec_to_duration(&(options->log_records[i].timestamp.value));
#endif

record.timestamp = std::chrono::time_point<std::chrono::system_clock>(dt);
}
Expand Down
4 changes: 4 additions & 0 deletions src/tracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ static struct otc_span *ot_tracer_start_span_with_options(struct otc_tracer *tra
}

if (options->start_time_system.value.tv_sec > 0) {
#ifdef __clang__
auto dt = timespec_to_duration_us(&(options->start_time_system.value));
#else
auto dt = timespec_to_duration(&(options->start_time_system.value));
#endif

span_options.start_system_timestamp = std::chrono::time_point<std::chrono::system_clock>(dt);
}
Expand Down
21 changes: 21 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,27 @@ otc_ext_malloc_t otc_ext_malloc = OT_IFDEF_DBG(otc_dbg_malloc, malloc);
otc_ext_free_t otc_ext_free = OT_IFDEF_DBG(otc_dbg_free, free);


/***
* NAME
* timespec_to_duration_us -
*
* ARGUMENTS
* ts -
*
* DESCRIPTION
* -
*
* RETURN VALUE
* -
*/
std::chrono::microseconds timespec_to_duration_us(const struct timespec *ts)
{
auto duration = std::chrono::seconds{ts->tv_sec} + std::chrono::microseconds{ts->tv_nsec / 1000};

return std::chrono::duration_cast<std::chrono::microseconds>(duration);
}


/***
* NAME
* timespec_to_duration -
Expand Down

0 comments on commit 7cb9ca9

Please sign in to comment.