logging: add log_output_timestamp_to_us() helper function

So far we only have log_msg_timestamp_get() function, which returns
internal timestamp representation. This is either clock cycles or uptime
in ms, depending on main clock precision.

Introduce log_output_timestamp_to_us() helper function, which allows to
convert internal logging timestamp to us.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2021-03-04 21:10:43 +01:00 committed by Anas Nashif
parent de16299c62
commit 552028dd20
2 changed files with 15 additions and 0 deletions

View file

@ -200,6 +200,14 @@ static inline void log_output_hostname_set(const struct log_output *output,
*/
void log_output_timestamp_freq_set(uint32_t freq);
/** @brief Convert timestamp of the message to us.
*
* @param timestamp Message timestamp
*
* @return Timestamp value in us.
*/
uint64_t log_output_timestamp_to_us(uint32_t timestamp);
/**
* @}
*/

View file

@ -753,3 +753,10 @@ void log_output_timestamp_freq_set(uint32_t frequency)
freq = frequency;
}
uint64_t log_output_timestamp_to_us(uint32_t timestamp)
{
timestamp /= timestamp_div;
return ((uint64_t) timestamp * 1000000U) / freq;
}