Skip to content

Add date and time to log entries #615

@AltraMayor

Description

@AltraMayor

Adding date and time to log entries will help to investigate bugs during development and issues in production.

Getting time and putting it in a human-readable format is not a cheap operation, so the implementation must only do it when a log entry is logged. A solution to delay getting the time just before logging is to add the field char str_date_time[32]; to struct log_ratelimit_state, and pass this field to rte_log_ratelimit() at macro G_LOG(). Thus, rte_log_ratelimit() can update the field str_date_time before calling rte_vlog(). This change requires adding the time string to the define G_LOG_PREFIX, which, in turn, requires adjusting log_ratelimit_reset().

The string format of the time added to log entries should be the same format used in log_stats(). Once time is being added to all log entries, log_stats() must no longer add time on its own.

To further reduce the number of times that time is obtained, one can add the field uint64_t update_time_at, so the field str_date_time is only updated once one second has passed. One should update the field uint64_t update_time_at with rte_rdtsc(). Replacing time(2) with clock_gettime(2) gives the time needed for logging and how much time is left until the next second in nanoseconds.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions