IOC mediator: DEBUG: support IOC log file

This patch is used for IOC mediator debugging. Due to IOC message logs are
too much, need to save into one file instead of output stdout directly.
By default, the debug log is disabled.

Signed-off-by: Liu Yuan <yuan1.liu@intel.com>
Reviewed-by: Wang Yu <yu1.wang@intel.com>
Reviewed-by: Liu Shuo <shuo.a.liu@intel.com>
Reviewed-by: Zhao Yakui <yakui.zhao@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Liu Yuan 2018-04-12 21:12:02 +08:00 committed by Jack Ren
parent 746d437642
commit 75b5e670d5
3 changed files with 36 additions and 11 deletions

View File

@ -90,14 +90,21 @@
#include "ioc.h" #include "ioc.h"
/* /* For debugging log to a file */
* Debug printf
*/
static int ioc_debug; static int ioc_debug;
#define DPRINTF(fmt, args...) \ static FILE *dbg_file;
do { if (ioc_debug) printf(fmt, ##args); } while (0) #define IOC_LOG_INIT do { if (ioc_debug) {\
#define WPRINTF(fmt, args...) printf(fmt, ##args) dbg_file = fopen("/tmp/ioc_log", "w+");\
if (!dbg_file)\
printf("ioc log open failed\r\n"); else cbc_set_log_file(dbg_file);\
} } while (0)
#define IOC_LOG_DEINIT do { if (dbg_file) fclose(dbg_file); dbg_file = NULL;\
cbc_set_log_file(dbg_file);\
} while (0)
#define DPRINTF(format, arg...) \
do { if (ioc_debug && dbg_file) { fprintf(dbg_file, format, arg);\
fflush(dbg_file); } } while (0)
#define WPRINTF(format, arg...) printf(format, ##arg)
/* /*
* Type definition for thread function. * Type definition for thread function.
@ -1096,7 +1103,7 @@ ioc_create_thread(const char *name, pthread_t *tid,
ioc_work func, void *arg) ioc_work func, void *arg)
{ {
if (pthread_create(tid, NULL, func, arg) != 0) { if (pthread_create(tid, NULL, func, arg) != 0) {
DPRINTF("ioc can not create thread\r\n"); DPRINTF("%s", "ioc can not create thread\r\n");
return -1; return -1;
} }
pthread_setname_np(*tid, name); pthread_setname_np(*tid, name);
@ -1146,6 +1153,8 @@ ioc_init(void)
int i; int i;
struct ioc_dev *ioc; struct ioc_dev *ioc;
IOC_LOG_INIT;
if (ioc_is_platform_supported() != 0) if (ioc_is_platform_supported() != 0)
goto ioc_err; goto ioc_err;
@ -1261,6 +1270,7 @@ alloc_err:
free(ioc->pool); free(ioc->pool);
free(ioc); free(ioc);
ioc_err: ioc_err:
IOC_LOG_DEINIT;
DPRINTF("%s", "ioc mediator startup failed!!\r\n"); DPRINTF("%s", "ioc mediator startup failed!!\r\n");
return NULL; return NULL;
} }
@ -1281,4 +1291,5 @@ ioc_deinit(struct ioc_dev *ioc)
free(ioc->evts); free(ioc->evts);
free(ioc->pool); free(ioc->pool);
free(ioc); free(ioc);
IOC_LOG_DEINIT;
} }

View File

@ -41,9 +41,11 @@
* Debug printf * Debug printf
*/ */
static int ioc_cbc_debug; static int ioc_cbc_debug;
#define DPRINTF(fmt, args...) \ static FILE *dbg_file;
do { if (ioc_cbc_debug) printf(fmt, ##args); } while (0) #define DPRINTF(format, arg...) \
#define WPRINTF(fmt, args...) printf(fmt, ##args) do { if (ioc_cbc_debug && dbg_file) { fprintf(dbg_file, format, arg);\
fflush(dbg_file); } } while (0)
#define WPRINTF(format, arg...) printf(format, ##arg)
static void cbc_send_pkt(struct cbc_pkt *pkt); static void cbc_send_pkt(struct cbc_pkt *pkt);
@ -895,3 +897,12 @@ wlist_init_signal(struct cbc_signal *cbc_tbl, size_t cbc_size,
} }
} }
} }
/*
* Share log file with IOC.
*/
void
cbc_set_log_file(FILE *f)
{
dbg_file = f;
}

View File

@ -735,4 +735,7 @@ void wlist_init_signal(struct cbc_signal *cbc_tbl, size_t cbc_size,
struct wlist_signal *wlist_tbl, size_t wlist_size); struct wlist_signal *wlist_tbl, size_t wlist_size);
void wlist_init_group(struct cbc_group *cbc_tbl, size_t cbc_size, void wlist_init_group(struct cbc_group *cbc_tbl, size_t cbc_size,
struct wlist_group *wlist_tbl, size_t wlist_size); struct wlist_group *wlist_tbl, size_t wlist_size);
/* Set CBC log file */
void cbc_set_log_file(FILE *f);
#endif #endif