tools:acrn-crashlog: check the folder size by calculating the increment

This patch refines the process of log space check.
Check a folder's size need to traverse all nodes of files and subdirs,
in the case of extreme memory strain, accessing these log file nodes
frequently will increase the IO pressure on the eMMC.
Previously, all log files will be accessed and counted in each space
check, this patch refines it by only calculating the increment of new logs.

Tracked-On: #1024
Signed-off-by: Liu, Xinwu <xinwu.liu@intel.com>
Reviewed-by: Liu, Xiaojing <xiaojing.liu@intel.com>
Acked-by: Chen, Gang <gang.c.chen@intel.com>
This commit is contained in:
Liu, Xinwu 2019-04-19 14:12:13 +08:00 committed by ACRN System Integration
parent 38cd3f74bd
commit ae11bd403d
3 changed files with 31 additions and 9 deletions

View File

@ -137,6 +137,7 @@ struct sender_t {
void (*send)(struct event_t *);
struct vmrecord_t vmrecord;
size_t outdir_blocks_size;
int sw_updated; /* each sender has their own record */
};

View File

@ -43,7 +43,6 @@ static int crashlog_check_space(void)
{
struct sender_t *crashlog = get_sender_by_name("crashlog");
int quota;
size_t dsize;
int cfg_size;
@ -57,19 +56,34 @@ static int crashlog_check_space(void)
if (!space_available(crashlog->outdir, quota))
return -1;
if (dir_blocks_size(crashlog->outdir, crashlog->outdir_len,
&dsize) == -1) {
LOGE("failed to check outdir size\n");
return -1;
}
if (cfg_atoi(crashlog->foldersize, crashlog->foldersize_len,
&cfg_size) == -1)
return -1;
if (dsize/MB >= (size_t)cfg_size)
if (crashlog->outdir_blocks_size/MB >= (size_t)cfg_size) {
LOGD("the total blocks size (%zu) meets the quota (%zu)\n",
crashlog->outdir_blocks_size/MB, (size_t)cfg_size);
return -1;
}
return 0;
}
static int log_grows(char *dir, size_t len)
{
size_t add;
struct sender_t *crashlog = get_sender_by_name("crashlog");
if (!crashlog)
return -1;
if (dir_blocks_size(dir, len, &add) == -1) {
LOGE("failed to check outdir size\n");
return -1;
}
add += 4 * KB;
crashlog->outdir_blocks_size += add;
LOGD("log size + %zu = %zu\n", add, crashlog->outdir_blocks_size);
return 0;
}
@ -1127,6 +1141,8 @@ static void crashlog_send(struct event_t *e)
default:
LOGE("unsupoorted event type %d\n", e->event_type);
}
if (e->dir)
log_grows(e->dir, e->dlen);
if (eid)
free(eid);
if (result)
@ -1179,6 +1195,12 @@ int init_sender(void)
return -1;
}
pthread_mutex_init(&sender->vmrecord.mtx, NULL);
if (dir_blocks_size(sender->outdir, sender->outdir_len,
&sender->outdir_blocks_size)
== -1) {
LOGE("failed to init outdir size\n");
return -1;
}
#ifdef HAVE_TELEMETRICS_CLIENT
} else if (!strcmp(sender->name, "telemd")) {

View File

@ -17,7 +17,6 @@
<sender id="2" enable="true">
<name>telemd</name>
<outdir>/var/log/acrnprobe</outdir>
<foldersize>10</foldersize>
<uptime>
<name>UPTIME</name>
<frequency>5</frequency>