Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  * Copyright 2020 IBM Corporation
0004  *
0005  */
0006 
0007 #ifndef _NXU_DBG_H_
0008 #define _NXU_DBG_H_
0009 
0010 #include <sys/file.h>
0011 #include <stdint.h>
0012 #include <stdio.h>
0013 #include <time.h>
0014 #include <pthread.h>
0015 
0016 extern FILE * nx_gzip_log;
0017 extern int nx_gzip_trace;
0018 extern unsigned int nx_gzip_inflate_impl;
0019 extern unsigned int nx_gzip_deflate_impl;
0020 extern unsigned int nx_gzip_inflate_flags;
0021 extern unsigned int nx_gzip_deflate_flags;
0022 
0023 extern int nx_dbg;
0024 pthread_mutex_t mutex_log;
0025 
0026 #define nx_gzip_trace_enabled()       (nx_gzip_trace & 0x1)
0027 #define nx_gzip_hw_trace_enabled()    (nx_gzip_trace & 0x2)
0028 #define nx_gzip_sw_trace_enabled()    (nx_gzip_trace & 0x4)
0029 #define nx_gzip_gather_statistics()   (nx_gzip_trace & 0x8)
0030 #define nx_gzip_per_stream_stat()     (nx_gzip_trace & 0x10)
0031 
0032 #define prt(fmt, ...) do { \
0033     pthread_mutex_lock(&mutex_log);                 \
0034     flock(nx_gzip_log->_fileno, LOCK_EX);               \
0035     time_t t; struct tm *m; time(&t); m = localtime(&t);        \
0036     fprintf(nx_gzip_log, "[%04d/%02d/%02d %02d:%02d:%02d] "     \
0037         "pid %d: " fmt, \
0038         (int)m->tm_year + 1900, (int)m->tm_mon+1, (int)m->tm_mday, \
0039         (int)m->tm_hour, (int)m->tm_min, (int)m->tm_sec,    \
0040         (int)getpid(), ## __VA_ARGS__);             \
0041     fflush(nx_gzip_log);                        \
0042     flock(nx_gzip_log->_fileno, LOCK_UN);               \
0043     pthread_mutex_unlock(&mutex_log);               \
0044 } while (0)
0045 
0046 /* Use in case of an error */
0047 #define prt_err(fmt, ...) do { if (nx_dbg >= 0) {           \
0048     prt("%s:%u: Error: "fmt,                    \
0049         __FILE__, __LINE__, ## __VA_ARGS__);            \
0050 }} while (0)
0051 
0052 /* Use in case of an warning */
0053 #define prt_warn(fmt, ...) do { if (nx_dbg >= 1) {          \
0054     prt("%s:%u: Warning: "fmt,                  \
0055         __FILE__, __LINE__, ## __VA_ARGS__);            \
0056 }} while (0)
0057 
0058 /* Informational printouts */
0059 #define prt_info(fmt, ...) do { if (nx_dbg >= 2) {          \
0060     prt("Info: "fmt, ## __VA_ARGS__);               \
0061 }} while (0)
0062 
0063 /* Trace zlib wrapper code */
0064 #define prt_trace(fmt, ...) do { if (nx_gzip_trace_enabled()) {     \
0065     prt("### "fmt, ## __VA_ARGS__);                 \
0066 }} while (0)
0067 
0068 /* Trace statistics */
0069 #define prt_stat(fmt, ...) do { if (nx_gzip_gather_statistics()) {  \
0070     prt("### "fmt, ## __VA_ARGS__);                 \
0071 }} while (0)
0072 
0073 /* Trace zlib hardware implementation */
0074 #define hw_trace(fmt, ...) do {                     \
0075         if (nx_gzip_hw_trace_enabled())             \
0076             fprintf(nx_gzip_log, "hhh " fmt, ## __VA_ARGS__); \
0077     } while (0)
0078 
0079 /* Trace zlib software implementation */
0080 #define sw_trace(fmt, ...) do {                     \
0081         if (nx_gzip_sw_trace_enabled())             \
0082             fprintf(nx_gzip_log, "sss " fmt, ## __VA_ARGS__); \
0083     } while (0)
0084 
0085 
0086 /**
0087  * str_to_num - Convert string into number and copy with endings like
0088  *              KiB for kilobyte
0089  *              MiB for megabyte
0090  *              GiB for gigabyte
0091  */
0092 uint64_t str_to_num(char *str);
0093 void nx_lib_debug(int onoff);
0094 
0095 #endif  /* _NXU_DBG_H_ */