aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern Brandenburg <bbb@mpi-sws.org>2013-10-10 10:27:12 -0400
committerBjoern Brandenburg <bbb@mpi-sws.org>2014-01-14 04:37:12 -0500
commitbf319d4af32822c04ffd59ab83afaf132d44784e (patch)
treed4d93bc5a7e3e7a2b3e5efe735a1f17efd829e09
parent55cd4e54c67b0886447070a609d11779728b81e6 (diff)
Implement -v (verbose messages) option in ftcat
-rw-r--r--src/ftcat.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/ftcat.c b/src/ftcat.c
index b8c6f0c..483bc6e 100644
--- a/src/ftcat.c
+++ b/src/ftcat.c
@@ -31,6 +31,9 @@
31 31
32#define MAX_EVENTS 128 32#define MAX_EVENTS 128
33 33
34int verbose = 0;
35#define vprintf(fmt, args...) if (verbose) { printf(fmt, ## args); }
36
34static int fd; 37static int fd;
35static int event_count = 0; 38static int event_count = 0;
36static cmd_t ids[MAX_EVENTS]; 39static cmd_t ids[MAX_EVENTS];
@@ -76,19 +79,19 @@ static int enable_event(int fd, char* str)
76static int calibrate_cycle_offsets(int fd) 79static int calibrate_cycle_offsets(int fd)
77{ 80{
78 int cpu, err; 81 int cpu, err;
79 int max_cpus = sysconf(_SC_NPROCESSORS_CONF); 82 int max_cpus = sysconf(_SC_NPROCESSORS_CONF);
80 83
81 for (cpu = 0; cpu < max_cpus; cpu++) { 84 for (cpu = 0; cpu < max_cpus; cpu++) {
82 err = be_migrate_to_cpu(cpu); 85 err = be_migrate_to_cpu(cpu);
83 if (!err) { 86 if (!err) {
84 printf("Calibrating CPU %d...", cpu); 87 vprintf("Calibrating CPU %d...", cpu);
85 err = ioctl(fd, CALIBRATE_CMD, 0); 88 err = ioctl(fd, CALIBRATE_CMD, verbose);
86 if (err) { 89 if (err) {
87 printf("\n"); 90 vprintf("\n");
88 fprintf(stderr, "ioctl(CALIBRATE_CMD) => %d (errno: %d, %m)\n", err, errno); 91 fprintf(stderr, "ioctl(CALIBRATE_CMD) => %d (errno: %d, %m)\n", err, errno);
89 return 0; 92 return 0;
90 } else 93 } else
91 printf(" done.\n"); 94 vprintf(" done.\n");
92 } else { 95 } else {
93 fprintf(stderr, "Could not migrate to CPU %d (%m).\n", cpu); 96 fprintf(stderr, "Could not migrate to CPU %d (%m).\n", cpu);
94 } 97 }
@@ -117,6 +120,7 @@ static void _usage(void)
117 "\nOptions:\n" 120 "\nOptions:\n"
118 " -s SIZE -- stop tracing afer recording SIZE bytes\n" 121 " -s SIZE -- stop tracing afer recording SIZE bytes\n"
119 " -c -- calibrate the CPU cycle counter offsets\n" 122 " -c -- calibrate the CPU cycle counter offsets\n"
123 " -v -- enable verbose output\n"
120 "\n"); 124 "\n");
121 exit(1); 125 exit(1);
122} 126}
@@ -131,7 +135,7 @@ static void shutdown(int sig)
131 fprintf(stderr, "disable_all: %m\n"); 135 fprintf(stderr, "disable_all: %m\n");
132} 136}
133 137
134#define OPTSTR "s:c" 138#define OPTSTR "s:cv"
135 139
136int main(int argc, char** argv) 140int main(int argc, char** argv)
137{ 141{
@@ -150,6 +154,9 @@ int main(int argc, char** argv)
150 case 'c': 154 case 'c':
151 want_calibrate = 1; 155 want_calibrate = 1;
152 break; 156 break;
157 case 'v':
158 verbose = 1;
159 break;
153 case ':': 160 case ':':
154 usage("Argument missing."); 161 usage("Argument missing.");
155 break; 162 break;
@@ -163,7 +170,7 @@ int main(int argc, char** argv)
163 argc -= optind; 170 argc -= optind;
164 argv += optind; 171 argv += optind;
165 172
166 if (argc < 3) 173 if (argc < 1)
167 usage("Argument missing."); 174 usage("Argument missing.");
168 175
169 trace_file = argv[0]; 176 trace_file = argv[0];