Browse Source

Implement --verbose option

Serj Kalichev 10 years ago
parent
commit
3fd9c80e48
3 changed files with 13 additions and 4 deletions
  1. 9 2
      birq.c
  2. 3 1
      statistics.c
  3. 1 1
      statistics.h

+ 9 - 2
birq.c

@@ -52,6 +52,7 @@ struct options {
 	int debug; /* Don't daemonize in debug mode */
 	int log_facility;
 	float threshold;
+	int verbose;
 };
 
 /*--------------------------------------------------------- */
@@ -136,7 +137,7 @@ int main(int argc, char **argv)
 
 		/* Gather statistics on CPU load and number of interrupts. */
 		gather_statistics(cpus, irqs);
-		show_statistics(cpus);
+		show_statistics(cpus, opts->verbose);
 		/* Choose IRQ to move to another CPU.
 		   Don't choose IRQ if we already have new IRQs to balance */
 		if (lub_list_len(balance_irqs) == 0) {
@@ -208,6 +209,7 @@ static struct options *opts_init(void)
 	opts->pidfile = strdup(BIRQ_PIDFILE);
 	opts->log_facility = LOG_DAEMON;
 	opts->threshold = BIRQ_DEFAULT_THRESHOLD;
+	opts->verbose = 0;
 
 	return opts;
 }
@@ -225,7 +227,7 @@ static void opts_free(struct options *opts)
 /* Parse command line options */
 static int opts_parse(int argc, char *argv[], struct options *opts)
 {
-	static const char *shortopts = "hvp:dO:t:";
+	static const char *shortopts = "hvp:dO:t:i";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
@@ -234,6 +236,7 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		{"debug",	0, NULL, 'd'},
 		{"facility",	1, NULL, 'O'},
 		{"threshold",	1, NULL, 't'},
+		{"verbose",	0, NULL, 'i'},
 		{NULL,		0, NULL, 0}
 	};
 #endif
@@ -256,6 +259,9 @@ static int opts_parse(int argc, char *argv[], struct options *opts)
 		case 'd':
 			opts->debug = 1;
 			break;
+		case 'i':
+			opts->verbose = 1;
+			break;
 		case 'O':
 			if (lub_log_facility(optarg, &(opts->log_facility))) {
 				fprintf(stderr, "Error: Illegal syslog facility %s.\n", optarg);
@@ -323,6 +329,7 @@ static void help(int status, const char *argv0)
 		printf("\t-v, --version\tPrint version.\n");
 		printf("\t-h, --help\tPrint this help.\n");
 		printf("\t-d, --debug\tDebug mode. Don't daemonize.\n");
+		printf("\t-i, --verbose\tBe verbose.\n");
 		printf("\t-p <path>, --pid=<path>\tFile to save daemon's PID to.\n");
 		printf("\t-O, --facility\tSyslog facility. Default is DAEMON.\n");
 		printf("\t-t <float>, --threshold=<float>\tThreshold to consider CPU is overloaded, in percents.\n");

+ 3 - 1
statistics.c

@@ -117,7 +117,7 @@ void gather_statistics(lub_list_t *cpus, lub_list_t *irqs)
 	free(line);
 }
 
-void show_statistics(lub_list_t *cpus)
+void show_statistics(lub_list_t *cpus, int verbose)
 {
 	lub_list_node_t *iter;
 	char outstr[10];
@@ -138,6 +138,8 @@ void show_statistics(lub_list_t *cpus)
 			cpu->id, cpu->package_id, cpu->core_id,
 			lub_list_len(cpu->irqs), cpu->load);
 
+		if (!verbose)
+			continue;
 		for (irq_iter = lub_list_iterator_init(cpu->irqs); irq_iter;
 		irq_iter = lub_list_iterator_next(irq_iter)) {
 			irq_t *irq;

+ 1 - 1
statistics.h

@@ -4,6 +4,6 @@
 #include "lub/list.h"
 
 void gather_statistics(lub_list_t *cpus, lub_list_t *irqs);
-void show_statistics(lub_list_t *cpus);
+void show_statistics(lub_list_t *cpus, int verbose);
 
 #endif