mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-25 06:51:49 +00:00
tools: acrn-crashlog: Improve the efficiency of do_log
Get the header size by receiving return value of snprintf instead of initialize log buffer and strlen. Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com> Reviewed-by: Eddie Dong <eddie.dong@intel.com> Acked-by: Chen Gang <gang.c.chen@intel.com>
This commit is contained in:
parent
c52afb1452
commit
fa5229052c
@ -8,17 +8,18 @@
|
|||||||
#include <systemd/sd-journal.h>
|
#include <systemd/sd-journal.h>
|
||||||
#include "log_sys.h"
|
#include "log_sys.h"
|
||||||
|
|
||||||
void do_log(int level,
|
void do_log(const int level,
|
||||||
#ifdef DEBUG_ACRN_CRASHLOG
|
#ifdef DEBUG_ACRN_CRASHLOG
|
||||||
const char *func, int line,
|
const char *func, const int line,
|
||||||
#endif
|
#endif
|
||||||
...)
|
...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
char *fmt;
|
char *fmt;
|
||||||
char log[MAX_LOG_LEN] = {0};
|
char log[MAX_LOG_LEN];
|
||||||
|
int n = 0;
|
||||||
#ifdef DEBUG_ACRN_CRASHLOG
|
#ifdef DEBUG_ACRN_CRASHLOG
|
||||||
char header_fmt[] = "<%-20s%d>: ";
|
const char header_fmt[] = "<%-20s%d>: ";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (level > LOG_LEVEL)
|
if (level > LOG_LEVEL)
|
||||||
@ -35,10 +36,13 @@ void do_log(int level,
|
|||||||
|
|
||||||
#ifdef DEBUG_ACRN_CRASHLOG
|
#ifdef DEBUG_ACRN_CRASHLOG
|
||||||
/* header */
|
/* header */
|
||||||
snprintf(log, sizeof(log) - 1, header_fmt, func, line);
|
n = snprintf(log, sizeof(log), header_fmt, func, line);
|
||||||
|
if (n < 0 || n >= sizeof(log))
|
||||||
|
n = 0;
|
||||||
#endif
|
#endif
|
||||||
/* msg */
|
/* msg */
|
||||||
vsnprintf(log + strlen(log), sizeof(log) - strlen(log) - 1, fmt, args);
|
vsnprintf(log + n, sizeof(log) - n, fmt, args);
|
||||||
|
log[sizeof(log) - 1] = 0;
|
||||||
va_end(args);
|
va_end(args);
|
||||||
|
|
||||||
sd_journal_print(level, log);
|
sd_journal_print(level, log);
|
||||||
|
Loading…
Reference in New Issue
Block a user