Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timeout handling for slog messages #635

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
17 changes: 12 additions & 5 deletions src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,32 +141,36 @@ static DltContext *dlt_context_from_slog2file(const char *file_name) {
}

template <class time, class period>
static void wait_for_buffer_space(const double max_usage_threshold,
static bool wait_for_buffer_space(const double max_usage_threshold,
const std::chrono::duration<time, period> max_wait_time) {
int total_size = 0;
int used_size = 0;
double used_percent = 100.0;
bool timeout = false;
static bool warning_sent = false;

const auto end_time = std::chrono::steady_clock::now() + max_wait_time;

do {
dlt_user_check_buffer(&total_size, &used_size);
used_percent = static_cast<double>(used_size) / total_size;
if (used_percent < max_usage_threshold) {
warning_sent=false;
break;
}

dlt_user_log_resend_buffer();

std::this_thread::sleep_for(10ms);
timeout = std::chrono::steady_clock::now() < end_time;
timeout = std::chrono::steady_clock::now() >= end_time;
} while (!timeout);

if (timeout) {
if (timeout && !warning_sent) {
DLT_LOG(dltQnxSystem, DLT_LOG_ERROR,
DLT_STRING("failed to get enough buffer space"));

warning_sent = true;
}
return timeout;
}

/**
Expand Down Expand Up @@ -217,7 +221,10 @@ static int sloggerinfo_callback(slog2_packet_info_t *info, void *payload, void *
DltContextData log_local; /* Used in DLT_* macros, do not rename */
DltContext *ctxt = dlt_context_from_slog2file(info->file_name);

wait_for_buffer_space(0.8, std::chrono::milliseconds(DLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS));
if( wait_for_buffer_space(0.8, std::chrono::milliseconds(DLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS))
{
return 0; // discard message
}

int ret;
ret = dlt_user_log_write_start(ctxt, &log_local, loglevel);
Expand Down
Loading