Skip to content

Commit

Permalink
Merge pull request #61 from v0lker/dynamic_debug
Browse files Browse the repository at this point in the history
add option to change debug/log level per invocation
  • Loading branch information
jlelli committed Sep 18, 2018
2 parents 62a088d + 825a226 commit 4ee1b96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
33 changes: 25 additions & 8 deletions src/rt-app_args.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <getopt.h>

#include "rt-app_parse_config.h"
#include "rt-app_utils.h"

char help_usage[] = \
"Usage: rt-app <taskset.json>\n"
"Usage: rt-app [-l <debug_level>] <taskset.json>\n"
"Try 'rt-app --help' for more information.\n";

char help_full[] = \
"Usage:\n"
" rt-app <taskset.json>\n"
" rt-app [-l <debug_level>] <taskset.json>\n"
" cat taskset.json | rt-app -\n\n"
"taskset.json is a json file describing the workload that will be generated"
"by rt-app.\n\n"
"In the first example, the json file is opened and parsed by rt-app.\n"
"In the second example, rt-app reads the workload description in json format\n"
"through the standard input.\n\n"
"Miscellaneous:\n"
" -v, --version display version information and exit\n"
" -h, --help display this help text and exit\n";
" -v, --version display version information and exit\n"
" -l, --log set verbosity level (10: ERROR/CRITICAL, 50: NOTICE (default)\n"
" 75: INFO, 100: DEBUG)\n"
" -h, --help display this help text and exit\n";

void
usage(const char* msg, int ex_code)
Expand All @@ -55,9 +58,10 @@ usage(const char* msg, int ex_code)
}

struct option long_args[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{0, 0, 0, 0}
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'v'},
{"log", required_argument, 0, 'l'},
{0, 0, 0, 0}
};

void
Expand All @@ -67,7 +71,7 @@ parse_command_line(int argc, char **argv, rtapp_options_t *opts)
int c;

while (1) {
c = getopt_long(argc, argv, "hv", long_args, 0);
c = getopt_long(argc, argv, "hvl:", long_args, 0);
if (c == -1)
break;

Expand All @@ -83,6 +87,19 @@ parse_command_line(int argc, char **argv, rtapp_options_t *opts)
BUILD_DATE);
exit(0);
break;
case 'l':
if (!optarg) {
usage(NULL, EXIT_INV_COMMANDLINE);
} else {
char *endptr;
long int ll = strtol(optarg, &endptr, 10);
if (*endptr) {
usage(NULL, EXIT_INV_COMMANDLINE);
break;
}
log_level = ll;
}
break;
default:
usage(NULL, EXIT_INV_COMMANDLINE);
break;
Expand Down
3 changes: 3 additions & 0 deletions src/rt-app_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#include "rt-app_utils.h"


int log_level = 50; // default

unsigned long
timespec_to_usec(struct timespec *ts)
{
Expand Down
9 changes: 4 additions & 5 deletions src/rt-app_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#ifndef LOG_PREFIX
#define LOG_PREFIX "[rt-app] "
#endif
#ifndef LOG_LEVEL
#define LOG_LEVEL 50
#endif

#define LOG_LEVEL_DEBUG 100
#define LOG_LEVEL_INFO 75
Expand All @@ -43,10 +40,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#define BUF_SIZE 100

/* This prepend a string to a message */
extern int log_level;

/* This prepends a string to a message */
#define rtapp_log_to(where, level, level_pfx, msg, args...) \
do { \
if (level <= LOG_LEVEL) { \
if (level <= log_level) { \
fprintf(where, LOG_PREFIX level_pfx msg "\n", ##args); \
} \
} while (0)
Expand Down

0 comments on commit 4ee1b96

Please sign in to comment.