[ltt-dev] [PATCH v2 2/2] Add -v option for lttd

Zhaolei zhaolei at cn.fujitsu.com
Tue Oct 21 23:23:38 EDT 2008


Add -v option for lttd, and output verbose message only if -v enabled.
It will allow lttctl to avoid outputing lots of lttd's verbose message on -d option.

Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
---
diff -Nur ltt-control-0.54-10102008.org1/lttd/lttd.c ltt-control-0.54-10102008/lttd/lttd.c
--- ltt-control-0.54-10102008.org1/lttd/lttd.c	2008-10-22 10:56:24.000000000 +0800
+++ ltt-control-0.54-10102008/lttd/lttd.c	2008-10-22 10:54:51.000000000 +0800
@@ -136,6 +136,7 @@
 volatile static int	quit_program = 0;	/* For signal handler */
 static int		dump_flight_only = 0;
 static int		dump_normal_only = 0;
+static int		verbose_mode = 0;
 
 /* Args :
  *
@@ -157,6 +158,7 @@
 	printf("-N            Number of threads to start.\n");
 	printf("-f            Dump only flight recorder channels.\n");
 	printf("-n            Dump only normal channels.\n");
+	printf("-v            Verbose mode.\n");
 	printf("\n");
 }
 
@@ -214,6 +216,9 @@
 					case 'n':
 						dump_normal_only = 1;
 						break;
+					case 'v':
+						verbose_mode = 1;
+						break;
 					default:
 						printf("Invalid argument '%s'.\n", argv[argn]);
 						printf("\n");
@@ -271,16 +276,19 @@
 
 	if(strncmp(filename, "flight-", sizeof("flight-")-1) != 0) {
 		if(dump_flight_only) {
-			printf("Skipping normal channel %s\n", path_channel);
+			if (verbose_mode)
+				printf("Skipping normal channel %s\n", path_channel);
 			return 0;
 		}
 	} else {
 		if(dump_normal_only) {
-			printf("Skipping flight channel %s\n", path_channel);
+			if (verbose_mode)
+				printf("Skipping flight channel %s\n", path_channel);
 			return 0;
 		}
 	}
-	printf("Opening file.\n");
+	if (verbose_mode)
+		printf("Opening file.\n");
 	
 	fd_pairs->pair = realloc(fd_pairs->pair,
 			++fd_pairs->num_pairs * sizeof(struct fd_pair));
@@ -297,7 +305,8 @@
 	ret = stat(path_trace, &stat_buf);
 	if(ret == 0) {
 		if(append_mode) {
-			printf("Appending to file %s as requested\n", path_trace);
+			if (verbose_mode)
+				printf("Appending to file %s as requested\n", path_trace);
 
 			fd_pairs->pair[fd_pairs->num_pairs-1].trace = 
 				open(path_trace, O_WRONLY|O_APPEND,
@@ -347,7 +356,8 @@
 		goto end;
 	}
 
-	printf("Creating trace subdirectory %s\n", subtrace_name);
+	if (verbose_mode)
+		printf("Creating trace subdirectory %s\n", subtrace_name);
 	ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO);
 	if(ret == -1) {
 		if(errno != EEXIST) {
@@ -372,13 +382,15 @@
 #ifdef HAS_INOTIFY
 	iwatch_array->elem = realloc(iwatch_array->elem,
 		++iwatch_array->num * sizeof(struct inotify_watch));
-	
-	printf("Adding inotify for channel %s\n", path_channel);
+		
+	if (verbose_mode)
+		printf("Adding inotify for channel %s\n", path_channel);
 	iwatch_array->elem[iwatch_array->num-1].wd = inotify_add_watch(*inotify_fd, path_channel, IN_CREATE);
 	strcpy(iwatch_array->elem[iwatch_array->num-1].path_channel, path_channel);
 	strcpy(iwatch_array->elem[iwatch_array->num-1].path_trace, path_trace);
-	printf("Added inotify for channel %s, wd %u\n", iwatch_array->elem[iwatch_array->num-1].path_channel,
-		iwatch_array->elem[iwatch_array->num-1].wd);
+	if (verbose_mode)
+		printf("Added inotify for channel %s, wd %u\n", iwatch_array->elem[iwatch_array->num-1].path_channel,
+			iwatch_array->elem[iwatch_array->num-1].wd);
 #endif
 
 	while((entry = readdir(channel_dir)) != NULL) {
@@ -394,11 +406,13 @@
 			continue;
 		}
 		
-		printf("Channel file : %s\n", path_channel);
+		if (verbose_mode)
+			printf("Channel file : %s\n", path_channel);
 		
 		if(S_ISDIR(stat_buf.st_mode)) {
 
-			printf("Entering channel subdirectory...\n");
+			if (verbose_mode)
+				printf("Entering channel subdirectory...\n");
 			ret = open_channel_trace_pairs(path_channel, path_trace, fd_pairs,
 				inotify_fd, iwatch_array);
 			if(ret < 0) continue;
@@ -426,7 +440,8 @@
 
 
 	err = ioctl(pair->channel, RELAY_GET_SUBBUF, &consumed_old);
-	printf("cookie : %u\n", consumed_old);
+	if (verbose_mode)
+		printf("cookie : %u\n", consumed_old);
 	if(err != 0) {
 		ret = errno;
 		perror("Reserving sub buffer failed (everything is normal, it is due to concurrency)");
@@ -447,17 +462,20 @@
 	len = pair->subbuf_size;
 	offset = 0;
 	while (len > 0) {
-		printf("splice chan to pipe offset %lu\n", offset);
+		if (verbose_mode)
+			printf("splice chan to pipe offset %lu\n", offset);
 		ret = splice(pair->channel, &offset, thread_pipe[1], NULL,
 			len, SPLICE_F_MOVE);
-		printf("splice chan to pipe ret %ld\n", ret);
+		if (verbose_mode)
+			printf("splice chan to pipe ret %ld\n", ret);
 		if (ret < 0) {
 			perror("Error in relay splice");
 			goto write_error;
 		}
 		ret = splice(thread_pipe[0], NULL, pair->trace, NULL,
 			ret, SPLICE_F_MOVE);
-		printf("splice pipe to file %ld\n", ret);
+		if (verbose_mode)
+			printf("splice pipe to file %ld\n", ret);
 		if (ret < 0) {
 			perror("Error in file splice");
 			goto write_error;
@@ -624,9 +642,10 @@
 		for(i=0; i<iwatch_array->num; i++) {
 			if(iwatch_array->elem[i].wd == ievent->wd &&
 				ievent->mask == IN_CREATE) {
-				printf("inotify wd %u event mask : %u for %s%s\n",
-					ievent->wd, ievent->mask,
-					iwatch_array->elem[i].path_channel, ievent->name);
+				if (verbose_mode)
+					printf("inotify wd %u event mask : %u for %s%s\n",
+						ievent->wd, ievent->mask,
+						iwatch_array->elem[i].path_channel, ievent->name);
 				old_num = fd_pairs->num_pairs;
 				strcpy(path_channel, iwatch_array->elem[i].path_channel);
 				strcat(path_channel, ievent->name);
@@ -724,22 +743,26 @@
 			goto free_fd;
 		}
 
-		printf("Data received\n");
+		if (verbose_mode)
+			printf("Data received\n");
 #ifdef HAS_INOTIFY
 		switch(pollfd[0].revents) {
 			case POLLERR:
-				printf("Error returned in polling inotify fd %d.\n", pollfd[0].fd);
+				if (verbose_mode)
+					printf("Error returned in polling inotify fd %d.\n", pollfd[0].fd);
 				break;
 			case POLLHUP:
-				printf("Polling inotify fd %d tells it has hung up.\n", pollfd[0].fd);
+				if (verbose_mode)
+					printf("Polling inotify fd %d tells it has hung up.\n", pollfd[0].fd);
 				break;
 			case POLLNVAL:
-				printf("Polling inotify fd %d tells fd is not open.\n", pollfd[0].fd);
+				if (verbose_mode)
+					printf("Polling inotify fd %d tells fd is not open.\n", pollfd[0].fd);
 				break;
 			case POLLPRI:
 			case POLLIN:
-
-				printf("Polling inotify fd %d : data ready.\n", pollfd[0].fd);
+				if (verbose_mode)
+					printf("Polling inotify fd %d : data ready.\n", pollfd[0].fd);
 
 				pthread_rwlock_wrlock(&fd_pairs_lock);
 				read_inotify(inotify_fd, fd_pairs, iwatch_array);
@@ -752,21 +775,25 @@
 		for(i=inotify_fds;i<num_pollfd;i++) {
 			switch(pollfd[i].revents) {
 				case POLLERR:
-					printf("Error returned in polling fd %d.\n", pollfd[i].fd);
+					if (verbose_mode)
+						printf("Error returned in polling fd %d.\n", pollfd[i].fd);
 					num_hup++;
 					break;
 				case POLLHUP:
-					printf("Polling fd %d tells it has hung up.\n", pollfd[i].fd);
+					if (verbose_mode)
+						printf("Polling fd %d tells it has hung up.\n", pollfd[i].fd);
 					num_hup++;
 					break;
 				case POLLNVAL:
-					printf("Polling fd %d tells fd is not open.\n", pollfd[i].fd);
+					if (verbose_mode)
+						printf("Polling fd %d tells fd is not open.\n", pollfd[i].fd);
 					num_hup++;
 					break;
 				case POLLPRI:
 					pthread_rwlock_rdlock(&fd_pairs_lock);
 					if(pthread_mutex_trylock(&fd_pairs->pair[i-inotify_fds].mutex) == 0) {
-						printf("Urgent read on fd %d\n", pollfd[i].fd);
+						if (verbose_mode)
+							printf("Urgent read on fd %d\n", pollfd[i].fd);
 						/* Take care of high priority channels first. */
 						high_prio = 1;
 						/* it's ok to have an unavailable subbuffer */
@@ -791,7 +818,8 @@
 						pthread_rwlock_rdlock(&fd_pairs_lock);
 						if(pthread_mutex_trylock(&fd_pairs->pair[i-inotify_fds].mutex) == 0) {
 							/* Take care of low priority channels. */
-							printf("Normal read on fd %d\n", pollfd[i].fd);
+							if (verbose_mode)
+								printf("Normal read on fd %d\n", pollfd[i].fd);
 							/* it's ok to have an unavailable subbuffer */
 							ret = read_subbuffer(&fd_pairs->pair[i-inotify_fds]);
 							if(ret == EAGAIN) ret = 0;






More information about the lttng-dev mailing list