Skip to content

Commit 4d60c31

Browse files
michael-methnerahmetfindi
authored and
LUU QUANG MINH
committed
Fix timeout handling for slog messages (#635)
* Fix timeout handling for slog messages - Discard messages after timeout - Log warning message only once until a new slog message was logged successful Signed-off-by: Michael Methner <michael.methner@de.bosch.com> * Update src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp Co-authored-by: ahmetfindi <113675774+ahmetfindi@users.noreply.github.com> --------- Signed-off-by: Michael Methner <michael.methner@de.bosch.com> Co-authored-by: ahmetfindi <113675774+ahmetfindi@users.noreply.github.com>
1 parent 8c2d4a8 commit 4d60c31

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/dlt-qnx-system/dlt-qnx-slogger2-adapter.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -141,32 +141,36 @@ static DltContext *dlt_context_from_slog2file(const char *file_name) {
141141
}
142142

143143
template <class time, class period>
144-
static void wait_for_buffer_space(const double max_usage_threshold,
144+
static bool wait_for_buffer_space(const double max_usage_threshold,
145145
const std::chrono::duration<time, period> max_wait_time) {
146146
int total_size = 0;
147147
int used_size = 0;
148148
double used_percent = 100.0;
149149
bool timeout = false;
150+
static bool warning_sent = false;
151+
150152
const auto end_time = std::chrono::steady_clock::now() + max_wait_time;
151153

152154
do {
153155
dlt_user_check_buffer(&total_size, &used_size);
154156
used_percent = static_cast<double>(used_size) / total_size;
155157
if (used_percent < max_usage_threshold) {
158+
warning_sent=false;
156159
break;
157160
}
158161

159162
dlt_user_log_resend_buffer();
160163

161164
std::this_thread::sleep_for(10ms);
162-
timeout = std::chrono::steady_clock::now() < end_time;
165+
timeout = std::chrono::steady_clock::now() >= end_time;
163166
} while (!timeout);
164167

165-
if (timeout) {
168+
if (timeout && !warning_sent) {
166169
DLT_LOG(dltQnxSystem, DLT_LOG_ERROR,
167170
DLT_STRING("failed to get enough buffer space"));
168-
171+
warning_sent = true;
169172
}
173+
return timeout;
170174
}
171175

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

220-
wait_for_buffer_space(0.8, std::chrono::milliseconds(DLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS));
224+
if( wait_for_buffer_space(0.8, std::chrono::milliseconds(DLT_QNX_SLOG_ADAPTER_WAIT_BUFFER_TIMEOUT_MS))
225+
{
226+
return 0; // discard message
227+
}
221228

222229
int ret;
223230
ret = dlt_user_log_write_start(ctxt, &log_local, loglevel);

0 commit comments

Comments
 (0)