mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
improved logging system by adding a line() function
This commit is contained in:
parent
7d33a2cf7b
commit
6b4fd61817
6 changed files with 32 additions and 18 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#define HIST_HEIGHT 50
|
||||
#define HIST_HEIGHT 75
|
||||
#define HIST_SEQ 17
|
||||
|
||||
typedef unsigned hist_cnt_t;
|
||||
|
|
|
@ -16,12 +16,14 @@
|
|||
#define INDENT ;
|
||||
#endif
|
||||
|
||||
/** The log level which is passed as first argument to print() */
|
||||
/** Width of log output in characters */
|
||||
#define LOG_WIDTH 100
|
||||
|
||||
#define DEBUG GRY("Debug")
|
||||
#define INFO ""
|
||||
#define WARN YEL("Warn")
|
||||
#define ERROR RED("Error")
|
||||
/* The log level which is passed as first argument to print() */
|
||||
#define DEBUG GRY("Debug")
|
||||
#define INFO ""
|
||||
#define WARN YEL("Warn")
|
||||
#define ERROR RED("Error")
|
||||
|
||||
/** Change log indention for current thread.
|
||||
*
|
||||
|
@ -65,6 +67,10 @@ void log_vprint(const char *lvl, const char *fmt, va_list va);
|
|||
void debug(int lvl, const char *fmt, ...)
|
||||
__attribute__ ((format(printf, 2, 3)));
|
||||
|
||||
|
||||
/** Print a horizontal line. */
|
||||
void line();
|
||||
|
||||
/** Printf alike info message. */
|
||||
void info(const char *fmt, ...)
|
||||
__attribute__ ((format(printf, 1, 2)));
|
||||
|
|
|
@ -36,9 +36,11 @@
|
|||
|
||||
/* Alternate character set */
|
||||
#define ACS(chr) "\e(0" chr "\e(B"
|
||||
#define ACS_VERTICAL ACS("\x78")
|
||||
#define ACS_VERTRIGHT ACS("\x74s")
|
||||
s
|
||||
#define ACS_VERTICAL "|"
|
||||
#define ACS_HORIZONTAL ACS("\x71")
|
||||
//#define ACS_VERTICAL ACS("\x78")
|
||||
#define ACS_VERTRIGHT ACS("\x74")
|
||||
|
||||
/* UTF-8 Line drawing characters */
|
||||
#define UTF8_BOX "\xE2\x96\x88"
|
||||
#define UTF8_VERTICAL "\xE2\x94\x82"
|
||||
|
|
|
@ -111,7 +111,9 @@ void hist_print(struct hist *h)
|
|||
|
||||
void hist_plot(struct hist *h)
|
||||
{
|
||||
char buf[HIST_HEIGHT] = { '#' };
|
||||
char buf[HIST_HEIGHT];
|
||||
memset(buf, '#', sizeof(buf));
|
||||
|
||||
unsigned int min = UINT_MAX, max = 0;
|
||||
|
||||
/* Get max, first & last */
|
||||
|
@ -124,6 +126,8 @@ void hist_plot(struct hist *h)
|
|||
|
||||
/* Print plot */
|
||||
info("%9s | %5s | %s", "Value", "Occur", "Histogram Plot:");
|
||||
line();
|
||||
|
||||
for (int i = 0; i < h->length; i++) {
|
||||
int bar = HIST_HEIGHT * ((double) h->data[i] / max);
|
||||
|
||||
|
|
|
@ -85,7 +85,14 @@ void log_vprint(const char *lvl, const char *fmt, va_list ap)
|
|||
fprintf(stderr, "\r%s\n", buf);
|
||||
}
|
||||
|
||||
/** Printf alike debug message with level. */
|
||||
void line()
|
||||
{
|
||||
char buf[LOG_WIDTH];
|
||||
memset(buf, 0x71, sizeof(buf));
|
||||
|
||||
log_print("", "\b" ACS("%.*s"), LOG_WIDTH, buf);
|
||||
}
|
||||
|
||||
void debug(int lvl, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -97,7 +104,6 @@ void debug(int lvl, const char *fmt, ...)
|
|||
}
|
||||
}
|
||||
|
||||
/** Printf alike info message. */
|
||||
void info(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -107,7 +113,6 @@ void info(const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
/** Printf alike warning message. */
|
||||
void warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -117,7 +122,6 @@ void warn(const char *fmt, ...)
|
|||
va_end(ap);
|
||||
}
|
||||
|
||||
/** Print error and exit. */
|
||||
void error(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -129,7 +133,6 @@ void error(const char *fmt, ...)
|
|||
die();
|
||||
}
|
||||
|
||||
/** Print error and strerror(errno). */
|
||||
void serror(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -143,7 +146,6 @@ void serror(const char *fmt, ...)
|
|||
die();
|
||||
}
|
||||
|
||||
/** Print configuration error and exit. */
|
||||
void cerror(config_setting_t *cfg, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
|
|
@ -174,8 +174,8 @@ int main(int argc, char *argv[])
|
|||
info("Runtime Statistics:");
|
||||
info("%-32s : %-8s %-8s %-8s %-8s %-8s",
|
||||
"Source " MAG("=>") " Destination", "#Sent", "#Recv", "#Drop", "#Skip", "#Inval");
|
||||
info("---------------------------------------------------------------------------");
|
||||
|
||||
line();
|
||||
|
||||
do { FOREACH(&paths, it) {
|
||||
usleep(settings.stats * 1e6);
|
||||
path_print_stats(it->path);
|
||||
|
|
Loading…
Add table
Reference in a new issue