mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-08-08 03:35:14 +00:00
tools: acrn-crashlog: main thread of acrn-crashlog/acrnprobe
This patch implements the main thread of acrnprobe. As a log collection mechanism to record critical events on the platform, acrnprobe provides the following features: 1. detect event. 2. analyze event and determine the event type. 3. collect information for the detected events. 4. archive these information as logs, and generate records. 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>
This commit is contained in:
parent
6e656dfd3c
commit
e86da09974
@ -1,6 +1,7 @@
|
||||
BASEDIR := $(shell pwd)
|
||||
|
||||
LIBS = -lpthread -lxml2 -lcrypto -lrt -lsystemd -ltelemetry
|
||||
INCLUDE += -I $(BASEDIR)/include
|
||||
CFLAGS += $(INCLUDE)
|
||||
CFLAGS += -g -O0 -std=gnu11
|
||||
CFLAGS += -ffunction-sections -fdata-sections
|
||||
@ -14,7 +15,17 @@ all: check_dirs $(TARGET)
|
||||
$(BUILDDIR)/acrnprobe/obj/%.o:%.c
|
||||
$(CC) -c $(CFLAGS) $< -o $@
|
||||
|
||||
$(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o
|
||||
$(BUILDDIR)/acrnprobe/bin/acrnprobe: $(BUILDDIR)/acrnprobe/obj/main.o \
|
||||
$(BUILDDIR)/common/obj/log_sys.o \
|
||||
$(BUILDDIR)/common/obj/cmdutils.o \
|
||||
$(BUILDDIR)/common/obj/fsutils.o \
|
||||
$(BUILDDIR)/common/obj/strutils.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/load_conf.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/channels.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/event_queue.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/event_handler.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/crash_reclassify.o \
|
||||
$(BUILDDIR)/acrnprobe/obj/sender.o
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
|
11
tools/acrn-crashlog/acrnprobe/channels.c
Normal file
11
tools/acrn-crashlog/acrnprobe/channels.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "channels.h"
|
||||
|
||||
int init_channels(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
10
tools/acrn-crashlog/acrnprobe/crash_reclassify.c
Normal file
10
tools/acrn-crashlog/acrnprobe/crash_reclassify.c
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "crash_reclassify.h"
|
||||
|
||||
void init_crash_reclassify(void)
|
||||
{
|
||||
}
|
11
tools/acrn-crashlog/acrnprobe/event_handler.c
Normal file
11
tools/acrn-crashlog/acrnprobe/event_handler.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "event_handler.h"
|
||||
|
||||
int init_event_handler(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
10
tools/acrn-crashlog/acrnprobe/event_queue.c
Normal file
10
tools/acrn-crashlog/acrnprobe/event_queue.c
Normal file
@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "event_queue.h"
|
||||
|
||||
void init_event(void)
|
||||
{
|
||||
}
|
11
tools/acrn-crashlog/acrnprobe/include/channels.h
Normal file
11
tools/acrn-crashlog/acrnprobe/include/channels.h
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef _CHANNELS_H
|
||||
#define _CHANNELS_H
|
||||
|
||||
extern int init_channels(void);
|
||||
|
||||
#endif
|
6
tools/acrn-crashlog/acrnprobe/include/crash_reclassify.h
Normal file
6
tools/acrn-crashlog/acrnprobe/include/crash_reclassify.h
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
extern void init_crash_reclassify(void);
|
6
tools/acrn-crashlog/acrnprobe/include/event_handler.h
Normal file
6
tools/acrn-crashlog/acrnprobe/include/event_handler.h
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
extern int init_event_handler(void);
|
11
tools/acrn-crashlog/acrnprobe/include/event_queue.h
Normal file
11
tools/acrn-crashlog/acrnprobe/include/event_queue.h
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __EVENT_QUEUE_H__
|
||||
#define __EVENT_QUEUE_H__
|
||||
|
||||
void init_event_queue(void);
|
||||
|
||||
#endif
|
37
tools/acrn-crashlog/acrnprobe/include/load_conf.h
Normal file
37
tools/acrn-crashlog/acrnprobe/include/load_conf.h
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#ifndef __LOAD_CONF_H__
|
||||
#define __LOAD_CONF_H__
|
||||
|
||||
#define SENDER_MAX 3
|
||||
|
||||
struct uptime_t {
|
||||
char *name;
|
||||
char *frequency;
|
||||
char *eventhours;
|
||||
|
||||
int wd;
|
||||
char *path;
|
||||
};
|
||||
|
||||
struct sender_t {
|
||||
struct uptime_t *uptime;
|
||||
};
|
||||
|
||||
struct conf_t {
|
||||
struct sender_t *sender[SENDER_MAX];
|
||||
};
|
||||
|
||||
struct conf_t conf;
|
||||
|
||||
#define for_each_sender(id, sender, conf) \
|
||||
for (id = 0, sender = conf.sender[0]; \
|
||||
id < SENDER_MAX; \
|
||||
id++, sender = conf.sender[id])
|
||||
|
||||
int load_conf(char *path);
|
||||
|
||||
#endif
|
6
tools/acrn-crashlog/acrnprobe/include/sender.h
Normal file
6
tools/acrn-crashlog/acrnprobe/include/sender.h
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
extern int init_sender(void);
|
11
tools/acrn-crashlog/acrnprobe/load_conf.c
Normal file
11
tools/acrn-crashlog/acrnprobe/load_conf.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "load_conf.h"
|
||||
|
||||
int load_conf(char *path __attribute__((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -3,11 +3,121 @@
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
int main(void)
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "load_conf.h"
|
||||
#include "fsutils.h"
|
||||
#include "crash_reclassify.h"
|
||||
#include "sender.h"
|
||||
#include "event_queue.h"
|
||||
#include "event_handler.h"
|
||||
#include "channels.h"
|
||||
#include "log_sys.h"
|
||||
|
||||
#define CONFIG_INSTALL "/usr/share/defaults/telemetrics/acrnprobe.xml"
|
||||
#define CONFIG_CUSTOMIZE "/etc/acrnprobe.xml"
|
||||
#define VERSION "1.0"
|
||||
|
||||
void usage(void)
|
||||
{
|
||||
//TO BE DONE
|
||||
//This empty function is to satisfy the dependency of Makefile.
|
||||
//This is the entry of acrnprobe, the implementation will be filled
|
||||
//by following patches.
|
||||
printf("[Usage]\n");
|
||||
printf("\tacrnprobe -c [configuration file path] [-hV]\n");
|
||||
printf("[Options]\n");
|
||||
printf("\t-c, --config Configuration file\n");
|
||||
printf("\t-h, --help print the help message\n");
|
||||
printf("\t-V, --version Print the program version\n");
|
||||
}
|
||||
|
||||
static void uptime(struct sender_t *sender)
|
||||
{
|
||||
int fd;
|
||||
int frequency;
|
||||
struct uptime_t *uptime;
|
||||
|
||||
uptime = sender->uptime;
|
||||
frequency = atoi(uptime->frequency);
|
||||
sleep(frequency);
|
||||
fd = open(uptime->path, O_RDWR | O_CREAT, 0666);
|
||||
if (fd < 0)
|
||||
LOGE("open uptime_file with (%d, %s) failed, error (%s)\n",
|
||||
atoi(uptime->frequency), uptime->path,
|
||||
strerror(errno));
|
||||
else
|
||||
close(fd);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int ret;
|
||||
int id;
|
||||
int op;
|
||||
struct sender_t *sender;
|
||||
char cfg[PATH_MAX] = {0};
|
||||
char *config_path[2] = {CONFIG_CUSTOMIZE,
|
||||
CONFIG_INSTALL};
|
||||
struct option opts[] = {
|
||||
{ "config", required_argument, NULL, 'c' },
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
{ NULL, 0, NULL, 0 }
|
||||
};
|
||||
|
||||
while ((op = getopt_long(argc, argv, "c:hV", opts,
|
||||
NULL)) != -1) {
|
||||
switch (op) {
|
||||
case 'c':
|
||||
strcpy(cfg, optarg);
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
return 0;
|
||||
case 'V':
|
||||
printf(VERSION "\n");
|
||||
return 0;
|
||||
case '?':
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cfg[0]) {
|
||||
if (file_exists(config_path[0]))
|
||||
strcpy(cfg, config_path[0]);
|
||||
else
|
||||
strcpy(cfg, config_path[1]);
|
||||
}
|
||||
|
||||
ret = load_conf(cfg);
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
init_crash_reclassify();
|
||||
ret = init_sender();
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
init_event_queue();
|
||||
ret = init_event_handler();
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
ret = init_channels();
|
||||
if (ret)
|
||||
return -1;
|
||||
|
||||
while (1) {
|
||||
for_each_sender(id, sender, conf) {
|
||||
if (!sender)
|
||||
continue;
|
||||
uptime(sender);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
11
tools/acrn-crashlog/acrnprobe/sender.c
Normal file
11
tools/acrn-crashlog/acrnprobe/sender.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "sender.h"
|
||||
|
||||
int init_sender(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user