mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-24 06:29:19 +00:00
tools:acrn-crashlog: simplify the logic in sender
Function sender_id need to traverse all senders and then find the matched id. This patch adds property "id" for each configuration object and removes function sender_id. 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:
parent
53b2bd5811
commit
9d22a18659
@ -145,20 +145,16 @@ static int refresh_key_synced_stage1(const struct sender_t *sender,
|
||||
{
|
||||
char log_new[64];
|
||||
char *log_vmrecordid;
|
||||
int sid;
|
||||
int nlen;
|
||||
|
||||
sid = sender_id(sender);
|
||||
if (sid == -1)
|
||||
return -1;
|
||||
log_vmrecordid = sender->log_vmrecordid;
|
||||
/* the length of key must be 20, and its value can not be
|
||||
* 00000000000000000000.
|
||||
*/
|
||||
if ((klen == ANDROID_EVT_KEY_LEN) &&
|
||||
strcmp(key, "00000000000000000000")) {
|
||||
memcpy(vm->last_synced_line_key[sid], key, klen);
|
||||
vm->last_synced_line_key[sid][klen] = '\0';
|
||||
memcpy(vm->last_synced_line_key[sender->id], key, klen);
|
||||
vm->last_synced_line_key[sender->id][klen] = '\0';
|
||||
if (type == MM_ONLY)
|
||||
return 0;
|
||||
|
||||
@ -219,13 +215,8 @@ static int get_vms_history(const struct sender_t *sender)
|
||||
struct vm_t *vm;
|
||||
unsigned long size;
|
||||
int ret;
|
||||
int sid;
|
||||
int id;
|
||||
|
||||
sid = sender_id(sender);
|
||||
if (sid == -1)
|
||||
return -1;
|
||||
|
||||
for_each_vm(id, vm, conf) {
|
||||
if (!vm)
|
||||
continue;
|
||||
@ -251,7 +242,7 @@ static int get_vms_history(const struct sender_t *sender)
|
||||
}
|
||||
|
||||
/* warning large history file once */
|
||||
if (size == vm->history_size[sid])
|
||||
if (size == vm->history_size[sender->id])
|
||||
continue;
|
||||
|
||||
ret = strcnt(vm->history_data, '\n');
|
||||
@ -259,7 +250,7 @@ static int get_vms_history(const struct sender_t *sender)
|
||||
LOGW("File too large, (%d) lines in (%s) of (%s)\n",
|
||||
ret, android_histpath, vm->name);
|
||||
|
||||
vm->history_size[sid] = size;
|
||||
vm->history_size[sender->id] = size;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -267,13 +258,9 @@ static int get_vms_history(const struct sender_t *sender)
|
||||
|
||||
static void sync_lines_stage1(const struct sender_t *sender)
|
||||
{
|
||||
int id, sid;
|
||||
int id;
|
||||
struct vm_t *vm;
|
||||
|
||||
sid = sender_id(sender);
|
||||
if (sid == -1)
|
||||
return;
|
||||
|
||||
for_each_vm(id, vm, conf) {
|
||||
char *data;
|
||||
size_t data_size;
|
||||
@ -285,8 +272,8 @@ static void sync_lines_stage1(const struct sender_t *sender)
|
||||
continue;
|
||||
|
||||
data = vm->history_data;
|
||||
data_size = vm->history_size[sid];
|
||||
last_key = &vm->last_synced_line_key[sid][0];
|
||||
data_size = vm->history_size[sender->id];
|
||||
last_key = &vm->last_synced_line_key[sender->id][0];
|
||||
if (*last_key) {
|
||||
start = strstr(data, last_key);
|
||||
if (start == NULL) {
|
||||
@ -351,11 +338,6 @@ static void sync_lines_stage2(const struct sender_t *sender,
|
||||
struct mm_file_t *recos;
|
||||
char *record;
|
||||
size_t recolen;
|
||||
int sid;
|
||||
|
||||
sid = sender_id(sender);
|
||||
if (sid == -1)
|
||||
return;
|
||||
|
||||
recos = mmap_file(sender->log_vmrecordid);
|
||||
if (!recos) {
|
||||
@ -394,7 +376,8 @@ static void sync_lines_stage2(const struct sender_t *sender,
|
||||
continue;
|
||||
|
||||
hist_line = get_line(vmkey, strnlen(vmkey, sizeof(vmkey)),
|
||||
vm->history_data, vm->history_size[sid],
|
||||
vm->history_data,
|
||||
vm->history_size[sender->id],
|
||||
vm->history_data, &len);
|
||||
if (!hist_line) {
|
||||
LOGW("mark vmevent(%s) as not-found\n", vmkey);
|
||||
@ -417,13 +400,8 @@ out:
|
||||
static void get_last_line_synced(const struct sender_t *sender)
|
||||
{
|
||||
int id;
|
||||
int sid;
|
||||
struct vm_t *vm;
|
||||
|
||||
sid = sender_id(sender);
|
||||
if (sid == -1)
|
||||
return;
|
||||
|
||||
for_each_vm(id, vm, conf) {
|
||||
int ret;
|
||||
char *p;
|
||||
@ -434,7 +412,7 @@ static void get_last_line_synced(const struct sender_t *sender)
|
||||
continue;
|
||||
|
||||
/* generally only exec for each vm once */
|
||||
if (vm->last_synced_line_key[sid][0])
|
||||
if (vm->last_synced_line_key[sender->id][0])
|
||||
continue;
|
||||
|
||||
ret = snprintf(vm_name, sizeof(vm_name), "%s ", vm->name);
|
||||
|
@ -24,6 +24,7 @@
|
||||
#define VM_EVENT_TYPE_MAX 20
|
||||
|
||||
struct trigger_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *type;
|
||||
@ -33,6 +34,7 @@ struct trigger_t {
|
||||
};
|
||||
|
||||
struct vm_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *channel;
|
||||
@ -49,6 +51,7 @@ struct vm_t {
|
||||
};
|
||||
|
||||
struct log_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *type;
|
||||
@ -64,6 +67,7 @@ struct log_t {
|
||||
};
|
||||
|
||||
struct crash_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *channel;
|
||||
@ -92,6 +96,7 @@ struct crash_t {
|
||||
};
|
||||
|
||||
struct info_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *channel;
|
||||
@ -115,6 +120,7 @@ struct uptime_t {
|
||||
};
|
||||
|
||||
struct sender_t {
|
||||
int id;
|
||||
const char *name;
|
||||
size_t name_len;
|
||||
const char *outdir;
|
||||
@ -239,7 +245,6 @@ int load_conf(const char *path);
|
||||
struct trigger_t *get_trigger_by_name(const char *name);
|
||||
struct log_t *get_log_by_name(const char *name);
|
||||
struct vm_t *get_vm_by_name(const char *name);
|
||||
int sender_id(const struct sender_t *sender);
|
||||
struct sender_t *get_sender_by_name(const char *name);
|
||||
enum event_type_t get_conf_by_wd(int wd, void **private);
|
||||
struct crash_t *get_crash_by_wd(int wd);
|
||||
|
@ -291,22 +291,6 @@ enum event_type_t get_conf_by_wd(int wd, void **private)
|
||||
|
||||
}
|
||||
|
||||
int sender_id(const struct sender_t *s)
|
||||
{
|
||||
int id;
|
||||
struct sender_t *sender;
|
||||
|
||||
for_each_sender(id, sender, conf) {
|
||||
if (!sender)
|
||||
continue;
|
||||
|
||||
if (s == sender)
|
||||
return id;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct sender_t *get_sender_by_name(const char *name)
|
||||
{
|
||||
int id;
|
||||
@ -724,6 +708,7 @@ static int parse_sender(xmlNodePtr cur, struct sender_t *sender)
|
||||
} \
|
||||
memset(mem, 0, sizeof(*mem)); \
|
||||
conf.mem[id] = mem; \
|
||||
mem->id = id; \
|
||||
res = parse_##mem(node, mem); \
|
||||
if (res) { \
|
||||
free(mem); \
|
||||
|
Loading…
Reference in New Issue
Block a user