Skip to content

Commit a35ef1a

Browse files
lauxinwlijinxia
authored andcommitted
tools: acrn-crashlog: configuration module of acrnprobe
To show the relationship between configuration items more clearly, acrnprobe chose xml as its configuration file format. This file provides functions to parse configuration and load them into global variable conf. Signed-off-by: Liu Xinwu <xinwu.liu@intel.com> Reviewed-by: Zhang Yanmin <yanmin.zhang@intel.com> Reviewed-by: Liu Chuansheng <chuansheng.liu@intel.com> Reviewed-by: Zhao Yakui <yakui.zhao@intel.com> Reviewed-by: Geoffroy Van Cutsem <geoffroy.vancutsem@intel.com> Acked-by: Eddie Dong <Eddie.dong@intel.com>
1 parent e86da09 commit a35ef1a

File tree

4 files changed

+767
-2
lines changed

4 files changed

+767
-2
lines changed

tools/acrn-crashlog/acrnprobe/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
BASEDIR := $(shell pwd)
22

33
LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry
4-
INCLUDE += -I $(BASEDIR)/include
4+
INCLUDE += -I $(BASEDIR)/include -I /usr/include/libxml2
55
CFLAGS += $(INCLUDE)
66
CFLAGS += -g -O0 -std=gnu11
77
CFLAGS += -ffunction-sections -fdata-sections

tools/acrn-crashlog/acrnprobe/include/event_queue.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@
66
#ifndef __EVENT_QUEUE_H__
77
#define __EVENT_QUEUE_H__
88

9+
#include <sys/queue.h>
10+
11+
enum event_type_t {
12+
CRASH,
13+
INFO,
14+
UPTIME,
15+
HEART_BEAT,
16+
REBOOT,
17+
VM,
18+
UNKNOWN
19+
};
20+
21+
__extension__
22+
struct event_t {
23+
int watchfd;
24+
enum event_type_t event_type;
25+
char *channel;
26+
void *private;
27+
28+
TAILQ_ENTRY(event_t) entries;
29+
30+
/* dir to storage logs */
31+
char *dir;
32+
int len;
33+
char path[0]; /* keep this at tail*/
34+
};
35+
936
void init_event_queue(void);
1037

1138
#endif

tools/acrn-crashlog/acrnprobe/include/load_conf.h

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,76 @@
66
#ifndef __LOAD_CONF_H__
77
#define __LOAD_CONF_H__
88

9+
#include <stdio.h>
10+
#include <sys/queue.h>
11+
#include <openssl/sha.h>
12+
#include "event_queue.h"
13+
14+
#define CONTENT_MAX 10
15+
#define EXPRESSION_MAX 5
16+
#define LOG_MAX 20
17+
#define TRIGGER_MAX 20
918
#define SENDER_MAX 3
19+
#define DATA_MAX 3
20+
#define CRASH_MAX 20
21+
#define INFO_MAX 20
22+
#define VM_MAX 4
23+
#define VM_EVENT_TYPE_MAX 20
24+
25+
struct trigger_t {
26+
char *name;
27+
char *type;
28+
char *path;
29+
};
30+
31+
struct vm_t {
32+
char *name;
33+
char *channel;
34+
char *interval;
35+
char *syncevent[VM_EVENT_TYPE_MAX];
36+
37+
int online;
38+
unsigned long history_size[SENDER_MAX];
39+
char last_synced_line_key[SENDER_MAX][SHA_DIGEST_LENGTH + 1];
40+
};
41+
42+
struct log_t {
43+
char *name;
44+
char *type;
45+
char *path;
46+
char *lines;
47+
48+
void (*get)(struct log_t *, void *);
49+
};
50+
51+
struct crash_t {
52+
char *name;
53+
char *channel;
54+
char *interval;
55+
struct trigger_t *trigger;
56+
char *content[CONTENT_MAX];
57+
char *mightcontent[EXPRESSION_MAX][CONTENT_MAX];
58+
struct log_t *log[LOG_MAX];
59+
char *data[DATA_MAX];
60+
61+
struct crash_t *parents;
62+
63+
TAILQ_ENTRY(crash_t) entries;
64+
TAILQ_HEAD(, crash_t) children;
65+
66+
int wd;
67+
int level;
68+
struct crash_t *(*reclassify)(struct crash_t *, char*, char**, char**,
69+
char**);
70+
};
71+
72+
struct info_t {
73+
char *name;
74+
char *channel;
75+
char *interval;
76+
struct trigger_t *trigger;
77+
struct log_t *log[LOG_MAX];
78+
};
1079

1180
struct uptime_t {
1281
char *name;
@@ -18,11 +87,25 @@ struct uptime_t {
1887
};
1988

2089
struct sender_t {
90+
char *name;
91+
char *outdir;
92+
char *maxcrashdirs;
93+
char *maxlines;
94+
char *spacequota;
2195
struct uptime_t *uptime;
96+
97+
void (*send)(struct event_t *);
98+
char *log_vmrecordid;
99+
int sw_updated; /* each sender has their own record */
22100
};
23101

24102
struct conf_t {
25103
struct sender_t *sender[SENDER_MAX];
104+
struct vm_t *vm[VM_MAX];
105+
struct trigger_t *trigger[TRIGGER_MAX];
106+
struct log_t *log[LOG_MAX];
107+
struct crash_t *crash[CRASH_MAX];
108+
struct info_t *info[INFO_MAX];
26109
};
27110

28111
struct conf_t conf;
@@ -32,6 +115,98 @@ struct conf_t conf;
32115
id < SENDER_MAX; \
33116
id++, sender = conf.sender[id])
34117

118+
#define for_each_trigger(id, trigger, conf) \
119+
for (id = 0, trigger = conf.trigger[0]; \
120+
id < TRIGGER_MAX; \
121+
id++, trigger = conf.trigger[id])
122+
123+
#define for_each_vm(id, vm, conf) \
124+
for (id = 0, vm = conf.vm[0]; \
125+
id < VM_MAX; \
126+
id++, vm = conf.vm[id])
127+
128+
#define for_each_syncevent_vm(id, event, vm) \
129+
for (id = 0, event = vm->syncevent[0]; \
130+
id < VM_EVENT_TYPE_MAX; \
131+
id++, event = vm->syncevent[id])
132+
133+
#define for_each_info(id, info, conf) \
134+
for (id = 0, info = conf.info[0]; \
135+
id < INFO_MAX; \
136+
id++, info = conf.info[id])
137+
138+
#define for_each_log(id, log, conf) \
139+
for (id = 0, log = conf.log[0]; \
140+
id < LOG_MAX; \
141+
id++, log = conf.log[id])
142+
143+
#define for_each_crash(id, crash, conf) \
144+
for (id = 0, crash = conf.crash[0]; \
145+
id < CRASH_MAX; \
146+
id++, crash = conf.crash[id])
147+
148+
#define for_each_log_collect(id, log, type) \
149+
for (id = 0, log = type->log[0]; \
150+
id < LOG_MAX; \
151+
id++, log = type->log[id])
152+
153+
#define for_each_content_crash(id, content, crash) \
154+
for (id = 0, content = crash->content[0]; \
155+
id < CONTENT_MAX; \
156+
id++, content = crash->content[id])
157+
158+
#define for_each_content_expression(id, content, exp) \
159+
for (id = 0, content = exp[0]; \
160+
id < CONTENT_MAX; \
161+
id++, content = exp[id])
162+
163+
#define exp_valid(exp) \
164+
(__extension__ \
165+
({ \
166+
int _ret = 0; \
167+
int _id; \
168+
char *content; \
169+
for_each_content_expression(_id, content, exp) { \
170+
if (content) \
171+
_ret = 1; \
172+
} \
173+
_ret; \
174+
}) \
175+
)
176+
177+
#define for_each_expression_crash(id, exp, crash) \
178+
for (id = 0, exp = crash->mightcontent[0]; \
179+
id < EXPRESSION_MAX; \
180+
id++, exp = crash->mightcontent[id])
181+
182+
#define for_crash_children(crash, tcrash) \
183+
TAILQ_FOREACH(crash, &tcrash->children, entries)
184+
185+
#define is_leaf_crash(crash) \
186+
(crash && TAILQ_EMPTY(&crash->children))
187+
188+
#define is_root_crash(crash) \
189+
(crash && crash->parents == NULL)
190+
191+
#define to_collect_logs(type) \
192+
(__extension__ \
193+
({ \
194+
int _id; \
195+
int _ret = 0; \
196+
for (_id = 0; _id < LOG_MAX; _id++) \
197+
if (type->log[_id]) \
198+
_ret = 1; \
199+
_ret; \
200+
}) \
201+
)
202+
35203
int load_conf(char *path);
204+
struct trigger_t *get_trigger_by_name(char *name);
205+
struct log_t *get_log_by_name(char *name);
206+
int sender_id(struct sender_t *sender);
207+
struct sender_t *get_sender_by_name(char *name);
208+
enum event_type_t get_conf_by_wd(int wd, void **private);
209+
struct crash_t *get_crash_by_wd(int wd);
210+
int crash_depth(struct crash_t *tcrash);
36211

37212
#endif

0 commit comments

Comments
 (0)