Commit 02829888 authored by Joanne Hugé's avatar Joanne Hugé

Making tracing optional

parent a7d3c837
......@@ -24,6 +24,7 @@ typedef struct thread_stat {
typedef struct thread_param {
int priority;
int max_cycles;
int enable_tracing;
uint64_t interval;
uint64_t latency_threshold;
thread_stat_t stat;
......@@ -31,6 +32,7 @@ typedef struct thread_param {
typedef struct main_param {
int refresh_rate;
int enable_tracing;
} main_param_t;
static void process_options(int argc, char *argv[], thread_param_t *param,
......@@ -60,9 +62,13 @@ static void *timerthread(void *p) {
for (stat->nb_cycles = 0;; stat->nb_cycles++) {
if (param->max_cycles && (stat->nb_cycles >= param->max_cycles)) break;
if(param->enable_tracing)
tracing(1);
clock_gettime(CLOCK_ID, &previous);
clock_gettime(CLOCK_ID, &current);
if(param->enable_tracing)
tracing(0);
diff = calcdiff_ns(current, previous);
......@@ -70,7 +76,7 @@ static void *timerthread(void *p) {
stat->max_res = max(stat->max_res, diff);
stat->min_res = min(stat->min_res, diff);
if( diff > param->latency_threshold ) break;
if( param->enable_tracing && (diff > param->latency_threshold) ) break;
usleep(param->interval);
}
......@@ -89,10 +95,16 @@ int main(int argc, char *argv[]) {
param.interval = 1000;
param.max_cycles = 100000;
param.priority = 99;
param.enable_tracing = 0;
main_param.enable_tracing = 0;
main_param.refresh_rate = 10000;
process_options(argc, argv, &param, &main_param);
if(main_param.enable_tracing) {
param.enable_tracing = 1;
setup_tracer();
}
usleep(10000);
......@@ -108,7 +120,7 @@ int main(int argc, char *argv[]) {
param.stat.nb_cycles);
if (param.max_cycles == param.stat.nb_cycles) break;
if (param.stat.max_res >= param.latency_threshold) break;
if (main_param.enable_tracing && (param.stat.max_res >= param.latency_threshold)) break;
}
tracing(0);
......@@ -119,7 +131,7 @@ int main(int argc, char *argv[]) {
static void process_options(int argc, char *argv[], thread_param_t *param,
main_param_t *main_param) {
for (;;) {
int c = getopt(argc, argv, "l:p:i:r:b:");
int c = getopt(argc, argv, "l:p:i:r:b:f:");
if (c == -1) break;
......@@ -139,6 +151,9 @@ static void process_options(int argc, char *argv[], thread_param_t *param,
case 'r':
main_param->refresh_rate = atoi(optarg);
break;
case 'f':
main_param->enable_tracing = 1;
break;
default:
exit(EXIT_FAILURE);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment