@@ -1953,10 +1953,8 @@ int main(int argc, char **argv)
for (k=0; k < times; k++)
clock_gettime(clock, &time[k]);
- if (ct_debug) {
- info("For %d consecutive calls to clock_gettime():\n", times);
- info("time, delta time (nsec)\n");
- }
+ info(ct_debug, "For %d consecutive calls to clock_gettime():\n", times);
+ info(ct_debug, "time, delta time (nsec)\n");
prev = time[0];
for (k=1; k < times; k++) {
@@ -1967,10 +1965,9 @@ int main(int argc, char **argv)
if (diff && (diff < min_non_zero_diff))
min_non_zero_diff = diff;
- if (ct_debug)
- info("%ld.%06ld %5llu\n",
- time[k].tv_sec, time[k].tv_nsec,
- (unsigned long long)diff);
+ info(ct_debug, "%ld.%06ld %5llu\n",
+ time[k].tv_sec, time[k].tv_nsec,
+ (unsigned long long)diff);
}
free(time);
@@ -11,8 +11,8 @@ void err_exit(int err, char *fmt, ...) __attribute__((noreturn));
void err_msg(char *fmt, ...);
void err_msg_n(int err, char *fmt, ...);
void err_quit(char *fmt, ...) __attribute__((noreturn));
-void debug(char *fmt, ...);
-void info(char *fmt, ...);
+void debug(int enable, char *fmt, ...);
+void info(int enable, char *fmt, ...);
void warn(char *fmt, ...);
void fatal(char *fmt, ...) __attribute__((noreturn));
void err_doit(int err, const char *fmt, va_list ap);
@@ -47,24 +47,28 @@ void err_quit(char *fmt, ...)
exit(1);
}
-void debug(char *fmt, ...)
+void debug(int enable, char *fmt, ...)
{
- va_list ap;
+ if (enable) {
+ va_list ap;
- va_start(ap, fmt);
- fputs("DEBUG: ", stderr);
- err_doit(0, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ fputs("DEBUG: ", stderr);
+ err_doit(0, fmt, ap);
+ va_end(ap);
+ }
}
-void info(char *fmt, ...)
+void info(int enable, char *fmt, ...)
{
- va_list ap;
+ if (enable) {
+ va_list ap;
- va_start(ap, fmt);
- fputs("INFO: ", stderr);
- err_doit(0, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ fputs("INFO: ", stderr);
+ err_doit(0, fmt, ap);
+ va_end(ap);
+ }
}
void warn(char *fmt, ...)
@@ -109,7 +109,7 @@ int mount_debugfs(char *path)
/* if it's already mounted just return */
prefix = get_debugfileprefix();
if (strlen(prefix) != 0) {
- info("debugfs mountpoint: %s\n", prefix);
+ info(1, "debugfs mountpoint: %s\n", prefix);
return 0;
}
if (!mountpoint)
@@ -71,9 +71,9 @@
#define DOWN_ONE "\033[1B"
#define pi_info(fmt, arg...) \
- do { if (verbose) info(fmt, ## arg); } while (0)
+ do { info(verbose, fmt, ## arg); } while (0)
#define pi_debug(fmt, arg...) \
- do { if (debugging) debug(fmt, ## arg); } while (0)
+ do { debug(debugging, fmt, ## arg); } while (0)
#define pi_error(fmt, arg...) \
do { err_msg(fmt, ## arg); have_errors = 1; } while (0)
@@ -80,6 +80,8 @@ struct sched_data {
};
static int shutdown;
+static int info_enable;
+static int debug_enable;
static int tracelimit;
static int trace_marker;
static pthread_mutex_t break_thread_id_lock = PTHREAD_MUTEX_INITIALIZER;
@@ -698,6 +700,8 @@ static void usage(int error)
"-q --quiet print a summary only on exit\n"
"-b USEC --breaktrace=USEC send break trace command when latency > USEC\n"
" --tracemark write a trace mark when -b latency is exceeded\n"
+ " --debug Print debugging info for cyclicdeadline\n"
+ " --verbose Print useful information about the test\n"
);
exit(error);
}
@@ -794,7 +798,7 @@ void *run_deadline(void *data)
u64 period;
int ret;
- printf("deadline thread %ld\n", tid);
+ debug(debug_enable, "deadline thread %ld\n", tid);
// set up for each measurment thread
stat->tid = tid;
@@ -811,7 +815,7 @@ void *run_deadline(void *data)
attr.sched_runtime = sd->runtime_us * 1000;
attr.sched_deadline = sd->deadline_us * 1000;
- printf("thread[%d] runtime=%lldus deadline=%lldus\n",
+ debug(debug_enable, "thread[%d] runtime=%lldus deadline=%lldus\n",
gettid(), sd->runtime_us, sd->deadline_us);
ret = sched_setattr(0, &attr, 0);
@@ -1084,7 +1088,7 @@ static void write_stats(FILE *f, void *data)
enum options_values {
OPT_AFFINITY=1, OPT_DURATION, OPT_HELP, OPT_INTERVAL,
OPT_JSON, OPT_STEP, OPT_THREADS, OPT_QUIET,
- OPT_BREAKTRACE, OPT_TRACEMARK,
+ OPT_BREAKTRACE, OPT_TRACEMARK, OPT_INFO, OPT_DEBUG,
};
int main(int argc, char **argv)
@@ -1125,6 +1129,8 @@ int main(int argc, char **argv)
{ "quiet", no_argument, NULL, OPT_QUIET },
{ "breaktrace", required_argument, NULL, OPT_BREAKTRACE },
{ "tracemark", no_argument, NULL, OPT_TRACEMARK },
+ { "verbose", no_argument, NULL, OPT_INFO},
+ { "debug", no_argument, NULL, OPT_DEBUG},
{ NULL, 0, NULL, 0 },
};
c = getopt_long(argc, argv, "a::c:D:hi:s:t:b:q", options, NULL);
@@ -1177,6 +1183,12 @@ int main(int argc, char **argv)
case OPT_TRACEMARK:
trace_marker = 1;
break;
+ case OPT_INFO:
+ info_enable = 1;
+ break;
+ case OPT_DEBUG:
+ debug_enable = 1;
+ break;
default:
usage(1);
}
@@ -1251,7 +1263,7 @@ int main(int argc, char **argv)
sd->runtime_us = runtime;
sd->deadline_us = interval;
- printf("interval: %lld:%lld\n", sd->runtime_us, sd->deadline_us);
+ info(info_enable, "interval: %lld:%lld\n", sd->runtime_us, sd->deadline_us);
/* Make sure that we can make our deadlines */
start_period = get_time_us();
@@ -1261,7 +1273,7 @@ int main(int argc, char **argv)
fatal("Failed to perform task within runtime: Missed by %lld us\n",
end_period - start_period - sd->runtime_us);
- printf(" Tested at %lldus of %lldus\n",
+ info(info_enable, " Tested at %lldus of %lldus\n",
end_period - start_period, sd->runtime_us);
interval += step;
@@ -1304,7 +1316,7 @@ int main(int argc, char **argv)
system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
}
- printf("main thread %d\n", gettid());
+ debug(debug_enable, "main thread %d\n", gettid());
if (shutdown)
fatal("failed to setup child threads at step 2");
This change was motivated by the desire to clean up the output of cyclicdeadline, and include the extra info only when requested. Instead of having to check if the program is in debugging mode, the rt-error functions will automatically check by passing in an argument. The other changes in this patch edit the function calls to debug() and info() to work with the changes in rt-error. Signed-off-by: Anubhav Shelat <ashelat@redhat.com> --- src/cyclictest/cyclictest.c | 13 +++++-------- src/include/rt-error.h | 4 ++-- src/lib/rt-error.c | 28 ++++++++++++++++------------ src/lib/rt-utils.c | 2 +- src/pi_tests/pi_stress.c | 4 ++-- src/sched_deadline/cyclicdeadline.c | 24 ++++++++++++++++++------ 6 files changed, 44 insertions(+), 31 deletions(-)