Skip to content

Commit

Permalink
Add the current high res clock value to every log invocation in android
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Nov 7, 2023
1 parent fb3182c commit 9c22862
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/android/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

#include <android/log.h>

#include <aws/common/clock.h>
#include <aws/common/logging.h>
#include <aws/common/string.h>

#include <inttypes.h>
#include <stdarg.h>

#define LOGCAT_MAX_BUFFER_SIZE (4 * 1024)
Expand Down Expand Up @@ -58,6 +60,18 @@ static int s_logcat_format(struct logcat_format_data *formatting_data, va_list a
current_index = s_advance_and_clamp_index(current_index, thread_id_written, fake_total_length);
}

if (current_index < fake_total_length) {
uint64_t now = 0;
aws_high_res_clock_get_ticks(&now);

int current_time_written = snprintf(
formatting_data->buffer + current_index, fake_total_length - current_index, "(HRC:%" PRIu64 ") ", now);
if (current_time_written < 0) {
return aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
}
current_index = s_advance_and_clamp_index(current_index, current_time_written, fake_total_length);
}

if (current_index < fake_total_length) {
int separator_written =
snprintf(formatting_data->buffer + current_index, fake_total_length - current_index, " - ");
Expand Down

0 comments on commit 9c22862

Please sign in to comment.