Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
* [ltt-dev] PATCH] Make lttcrl/lttd show error when channel not exist
@ 2008-10-21  5:39 Zhaolei
  2008-10-21 14:05 ` Mathieu Desnoyers
  0 siblings, 1 reply; 8+ messages in thread
From: Zhaolei @ 2008-10-21  5:39 UTC (permalink / raw)


Hello, Mathieu

When run lttctl with a no-exist debugfs's channel dir,
it don't report error:
  # lttctl -n channel1 -d -l /no_exist -t /tmp/channel1
  Linux Trace Toolkit Trace Control 0.54-10102008
  
  Controlling trace : channel1
  
  Linux Trace Toolkit Trace Daemon 0.54-10102008
  
  Reading from debugfs directory : /no_exist/channel1
  Writing to trace directory : /tmp/channel1

  #

It is because lttd don't return error in daemon mode:
  # lttd -d -t /tmp/channel1 -c /no_exist
  Linux Trace Toolkit Trace Daemon 0.54-10102008
  
  Reading from debugfs directory : /no_exist
  Writing to trace directory : /tmp/channel1
  
  # echo $?
  0
  #

I moved daemon() after channels_init() and make it seems fixed.
I tested patched program and haven't found problem:
  # lttctl -n channel1 -d -l /no_exist -t /tmp/channel1
  Linux Trace Toolkit Trace Control 0.54-10102008

  Controlling trace : channel1

  Linux Trace Toolkit Trace Daemon 0.54-10102008

  Reading from debugfs directory : /no_exist/channel1
  Writing to trace directory : /tmp/channel1

  /no_exist/channel1: No such file or directory
  Trace start error
  #
  #
  # lttd -d -t /tmp/channel1 -c /no_exist
  Linux Trace Toolkit Trace Daemon 0.54-10102008

  Reading from debugfs directory : /no_exist
  Writing to trace directory : /tmp/channel1
  
  /no_exist: No such file or directory
  #
  #
  # lttctl -n channel1 -d -l /mnt/debugfs/ltt/ -t /tmp/channel1
  Linux Trace Toolkit Trace Control 0.54-10102008

  Controlling trace : channel1

  Linux Trace Toolkit Trace Daemon 0.54-10102008

  Reading from debugfs directory : /mnt/debugfs/ltt//channel1
  Writing to trace directory : /tmp/channel1

  Creating trace subdirectory /tmp/channel1
  Adding inotify for channel /mnt/debugfs/ltt//channel1/
  Added inotify for channel /mnt/debugfs/ltt//channel1/, wd 1
  Channel file : /mnt/debugfs/ltt//channel1/cpu_0
  Opening file.
  Channel file : /mnt/debugfs/ltt//channel1/control
  Entering channel subdirectory...
  Creating trace subdirectory /tmp/channel1/control
  Adding inotify for channel /mnt/debugfs/ltt//channel1/control/
  Added inotify for channel /mnt/debugfs/ltt//channel1/control/, wd 2
  Channel file : /mnt/debugfs/ltt//channel1/control/network_0
  Opening file.
  Channel file : /mnt/debugfs/ltt//channel1/control/modules_0
  Opening file.
  Channel file : /mnt/debugfs/ltt//channel1/control/processes_0
  Opening file.
  Channel file : /mnt/debugfs/ltt//channel1/control/interrupts_0
  Opening file.
  Channel file : /mnt/debugfs/ltt//channel1/control/metadata_0
  Opening file.
  #

Cound you review it?

Btw, this patch will make lttctl and lttv show more detail message, is it necessary to cut them?

Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
---
diff -Nur ltt-control-0.54-10102008.org/lttd/lttd.c ltt-control-0.54-10102008/lttd/lttd.c
--- ltt-control-0.54-10102008.org/lttd/lttd.c	2008-10-15 15:29:54.000000000 +0800
+++ ltt-control-0.54-10102008/lttd/lttd.c	2008-10-21 13:15:06.000000000 +0800
@@ -911,15 +911,6 @@
 
 	show_info();
 
-	if(daemon_mode) {
-		ret = daemon(0, 0);
-		
-		if(ret == -1) {
-			perror("An error occured while daemonizing.");
-			exit(-1);
-		}
-	}
-
 	/* Connect the signal handlers */
 	act.sa_handler = handler;
 	act.sa_flags = 0;
@@ -934,6 +925,15 @@
 	if(ret = channels_init())
 		return ret;
 
+	if(daemon_mode) {
+		ret = daemon(0, 0);
+
+		if(ret == -1) {
+			perror("An error occured while daemonizing.");
+			exit(-1);
+		}
+	}
+
 	tids = malloc(sizeof(pthread_t) * num_threads);
 	for(i=0; i<num_threads; i++) {
 






^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] PATCH] Make lttcrl/lttd show error when channel not exist
  2008-10-21  5:39 [ltt-dev] PATCH] Make lttcrl/lttd show error when channel not exist Zhaolei
@ 2008-10-21 14:05 ` Mathieu Desnoyers
  2008-10-22  3:18   ` [ltt-dev] [PATCH v2 1/2] " Zhaolei
  2008-10-22  3:23   ` [ltt-dev] [PATCH v2 2/2] Add -v option for lttd Zhaolei
  0 siblings, 2 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2008-10-21 14:05 UTC (permalink / raw)


* Zhaolei (zhaolei at cn.fujitsu.com) wrote:
> Hello, Mathieu
> 
> When run lttctl with a no-exist debugfs's channel dir,
> it don't report error:
>   # lttctl -n channel1 -d -l /no_exist -t /tmp/channel1
>   Linux Trace Toolkit Trace Control 0.54-10102008
>   
>   Controlling trace : channel1
>   
>   Linux Trace Toolkit Trace Daemon 0.54-10102008
>   
>   Reading from debugfs directory : /no_exist/channel1
>   Writing to trace directory : /tmp/channel1
> 
>   #
> 
> It is because lttd don't return error in daemon mode:
>   # lttd -d -t /tmp/channel1 -c /no_exist
>   Linux Trace Toolkit Trace Daemon 0.54-10102008
>   
>   Reading from debugfs directory : /no_exist
>   Writing to trace directory : /tmp/channel1
>   
>   # echo $?
>   0
>   #
> 
> I moved daemon() after channels_init() and make it seems fixed.
> I tested patched program and haven't found problem:
>   # lttctl -n channel1 -d -l /no_exist -t /tmp/channel1
>   Linux Trace Toolkit Trace Control 0.54-10102008
> 
>   Controlling trace : channel1
> 
>   Linux Trace Toolkit Trace Daemon 0.54-10102008
> 
>   Reading from debugfs directory : /no_exist/channel1
>   Writing to trace directory : /tmp/channel1
> 
>   /no_exist/channel1: No such file or directory
>   Trace start error
>   #
>   #
>   # lttd -d -t /tmp/channel1 -c /no_exist
>   Linux Trace Toolkit Trace Daemon 0.54-10102008
> 
>   Reading from debugfs directory : /no_exist
>   Writing to trace directory : /tmp/channel1
>   
>   /no_exist: No such file or directory
>   #
>   #
>   # lttctl -n channel1 -d -l /mnt/debugfs/ltt/ -t /tmp/channel1
>   Linux Trace Toolkit Trace Control 0.54-10102008
> 
>   Controlling trace : channel1
> 
>   Linux Trace Toolkit Trace Daemon 0.54-10102008
> 
>   Reading from debugfs directory : /mnt/debugfs/ltt//channel1
>   Writing to trace directory : /tmp/channel1
> 
>   Creating trace subdirectory /tmp/channel1
>   Adding inotify for channel /mnt/debugfs/ltt//channel1/
>   Added inotify for channel /mnt/debugfs/ltt//channel1/, wd 1
>   Channel file : /mnt/debugfs/ltt//channel1/cpu_0
>   Opening file.
>   Channel file : /mnt/debugfs/ltt//channel1/control
>   Entering channel subdirectory...
>   Creating trace subdirectory /tmp/channel1/control
>   Adding inotify for channel /mnt/debugfs/ltt//channel1/control/
>   Added inotify for channel /mnt/debugfs/ltt//channel1/control/, wd 2
>   Channel file : /mnt/debugfs/ltt//channel1/control/network_0
>   Opening file.
>   Channel file : /mnt/debugfs/ltt//channel1/control/modules_0
>   Opening file.
>   Channel file : /mnt/debugfs/ltt//channel1/control/processes_0
>   Opening file.
>   Channel file : /mnt/debugfs/ltt//channel1/control/interrupts_0
>   Opening file.
>   Channel file : /mnt/debugfs/ltt//channel1/control/metadata_0
>   Opening file.
>   #
> 
> Cound you review it?
> 
> Btw, this patch will make lttctl and lttv show more detail message, is it necessary to cut them?
> 

Good idea. I think it would be good to add a "-v" (verbose) option to
lttd. Could you resubmit a patch that includes this change ?

Thanks,

Mathieu

> Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
> ---
> diff -Nur ltt-control-0.54-10102008.org/lttd/lttd.c ltt-control-0.54-10102008/lttd/lttd.c
> --- ltt-control-0.54-10102008.org/lttd/lttd.c	2008-10-15 15:29:54.000000000 +0800
> +++ ltt-control-0.54-10102008/lttd/lttd.c	2008-10-21 13:15:06.000000000 +0800
> @@ -911,15 +911,6 @@
>  
>  	show_info();
>  
> -	if(daemon_mode) {
> -		ret = daemon(0, 0);
> -		
> -		if(ret == -1) {
> -			perror("An error occured while daemonizing.");
> -			exit(-1);
> -		}
> -	}
> -
>  	/* Connect the signal handlers */
>  	act.sa_handler = handler;
>  	act.sa_flags = 0;
> @@ -934,6 +925,15 @@
>  	if(ret = channels_init())
>  		return ret;
>  
> +	if(daemon_mode) {
> +		ret = daemon(0, 0);
> +
> +		if(ret == -1) {
> +			perror("An error occured while daemonizing.");
> +			exit(-1);
> +		}
> +	}
> +
>  	tids = malloc(sizeof(pthread_t) * num_threads);
>  	for(i=0; i<num_threads; i++) {
>  
> 
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v2 1/2] Make lttcrl/lttd show error when channel not exist
  2008-10-21 14:05 ` Mathieu Desnoyers
@ 2008-10-22  3:18   ` Zhaolei
  2008-10-24 14:12     ` Mathieu Desnoyers
  2008-10-22  3:23   ` [ltt-dev] [PATCH v2 2/2] Add -v option for lttd Zhaolei
  1 sibling, 1 reply; 8+ messages in thread
From: Zhaolei @ 2008-10-22  3:18 UTC (permalink / raw)


Moved daemon() after channels_init() to make lttd return !0 on error.
Applies on top of ltt-control-0.55-16102008.

Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
---
diff -Nur ltt-control-0.54-10102008.org/lttd/lttd.c ltt-control-0.54-10102008/lttd/lttd.c
--- ltt-control-0.54-10102008.org/lttd/lttd.c	2008-10-15 15:29:54.000000000 +0800
+++ ltt-control-0.54-10102008/lttd/lttd.c	2008-10-21 13:15:06.000000000 +0800
@@ -911,15 +911,6 @@
 
 	show_info();
 
-	if(daemon_mode) {
-		ret = daemon(0, 0);
-		
-		if(ret == -1) {
-			perror("An error occured while daemonizing.");
-			exit(-1);
-		}
-	}
-
 	/* Connect the signal handlers */
 	act.sa_handler = handler;
 	act.sa_flags = 0;
@@ -934,6 +925,15 @@
 	if(ret = channels_init())
 		return ret;
 
+	if(daemon_mode) {
+		ret = daemon(0, 0);
+
+		if(ret == -1) {
+			perror("An error occured while daemonizing.");
+			exit(-1);
+		}
+	}
+
 	tids = malloc(sizeof(pthread_t) * num_threads);
 	for(i=0; i<num_threads; i++) {
 




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v2 2/2] Add -v option for lttd
  2008-10-21 14:05 ` Mathieu Desnoyers
  2008-10-22  3:18   ` [ltt-dev] [PATCH v2 1/2] " Zhaolei
@ 2008-10-22  3:23   ` Zhaolei
  2008-10-24 14:15     ` Mathieu Desnoyers
  1 sibling, 1 reply; 8+ messages in thread
From: Zhaolei @ 2008-10-22  3:23 UTC (permalink / raw)


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;






^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v2 1/2] Make lttcrl/lttd show error when channel not exist
  2008-10-22  3:18   ` [ltt-dev] [PATCH v2 1/2] " Zhaolei
@ 2008-10-24 14:12     ` Mathieu Desnoyers
  0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2008-10-24 14:12 UTC (permalink / raw)


* Zhaolei (zhaolei at cn.fujitsu.com) wrote:
> Moved daemon() after channels_init() to make lttd return !0 on error.
> Applies on top of ltt-control-0.55-16102008.
> 

Merged, thanks !

Mathieu

> Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
> ---
> diff -Nur ltt-control-0.54-10102008.org/lttd/lttd.c ltt-control-0.54-10102008/lttd/lttd.c
> --- ltt-control-0.54-10102008.org/lttd/lttd.c	2008-10-15 15:29:54.000000000 +0800
> +++ ltt-control-0.54-10102008/lttd/lttd.c	2008-10-21 13:15:06.000000000 +0800
> @@ -911,15 +911,6 @@
>  
>  	show_info();
>  
> -	if(daemon_mode) {
> -		ret = daemon(0, 0);
> -		
> -		if(ret == -1) {
> -			perror("An error occured while daemonizing.");
> -			exit(-1);
> -		}
> -	}
> -
>  	/* Connect the signal handlers */
>  	act.sa_handler = handler;
>  	act.sa_flags = 0;
> @@ -934,6 +925,15 @@
>  	if(ret = channels_init())
>  		return ret;
>  
> +	if(daemon_mode) {
> +		ret = daemon(0, 0);
> +
> +		if(ret == -1) {
> +			perror("An error occured while daemonizing.");
> +			exit(-1);
> +		}
> +	}
> +
>  	tids = malloc(sizeof(pthread_t) * num_threads);
>  	for(i=0; i<num_threads; i++) {
>  
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v2 2/2] Add -v option for lttd
  2008-10-22  3:23   ` [ltt-dev] [PATCH v2 2/2] Add -v option for lttd Zhaolei
@ 2008-10-24 14:15     ` Mathieu Desnoyers
  2008-10-27  5:32       ` [ltt-dev] [PATCH v3] " Zhaolei
  0 siblings, 1 reply; 8+ messages in thread
From: Mathieu Desnoyers @ 2008-10-24 14:15 UTC (permalink / raw)


* Zhaolei (zhaolei at cn.fujitsu.com) wrote:
> 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.
> 

Hrm, could you slightly change this patch to do something like this ?

#define printf_verbose(fmt, args...) \
  do {                               \
    if (verbose)                     \
      printf(fmt, args);             \
  } while (0)

And use printf_verbose instead ?

Thanks,

Mathieu

> 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;
> 
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68




^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v3] Add -v option for lttd
  2008-10-24 14:15     ` Mathieu Desnoyers
@ 2008-10-27  5:32       ` Zhaolei
  2008-10-28 14:27         ` Mathieu Desnoyers
  0 siblings, 1 reply; 8+ messages in thread
From: Zhaolei @ 2008-10-27  5:32 UTC (permalink / raw)


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>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>
---
diff -Nur ltt-control-0.56-24102008.org/lttd/lttd.c ltt-control-0.56-24102008/lttd/lttd.c
--- ltt-control-0.56-24102008.org/lttd/lttd.c	2008-10-24 22:03:14.000000000 +0800
+++ ltt-control-0.56-24102008/lttd/lttd.c	2008-10-27 13:27:41.000000000 +0800
@@ -136,14 +136,21 @@
 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;
+
+#define printf_verbose(fmt, args...) \
+  do {                               \
+    if (verbose_mode)                \
+      printf(fmt, ##args);           \
+  } while (0)
 
 /* Args :
  *
  * -t directory		Directory name of the trace to write to. Will be created.
  * -c directory		Root directory of the debugfs trace channels.
  * -d          		Run in background (daemon).
- * -a							Trace append mode.
- * -s							Send SIGUSR1 to parent when ready for IO.
+ * -a			Trace append mode.
+ * -s			Send SIGUSR1 to parent when ready for IO.
  */
 void show_arguments(void)
 {
@@ -157,6 +164,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 +222,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 +282,18 @@
 
 	if(strncmp(filename, "flight-", sizeof("flight-")-1) != 0) {
 		if(dump_flight_only) {
-			printf("Skipping normal channel %s\n", path_channel);
+			printf_verbose("Skipping normal channel %s\n",
+				path_channel);
 			return 0;
 		}
 	} else {
 		if(dump_normal_only) {
-			printf("Skipping flight channel %s\n", path_channel);
+			printf_verbose("Skipping flight channel %s\n",
+				path_channel);
 			return 0;
 		}
 	}
-	printf("Opening file.\n");
+	printf_verbose("Opening file.\n");
 	
 	fd_pairs->pair = realloc(fd_pairs->pair,
 			++fd_pairs->num_pairs * sizeof(struct fd_pair));
@@ -297,7 +310,8 @@
 	ret = stat(path_trace, &stat_buf);
 	if(ret == 0) {
 		if(append_mode) {
-			printf("Appending to file %s as requested\n", path_trace);
+			printf_verbose("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 +361,7 @@
 		goto end;
 	}
 
-	printf("Creating trace subdirectory %s\n", subtrace_name);
+	printf_verbose("Creating trace subdirectory %s\n", subtrace_name);
 	ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO);
 	if(ret == -1) {
 		if(errno != EEXIST) {
@@ -373,11 +387,12 @@
 	iwatch_array->elem = realloc(iwatch_array->elem,
 		++iwatch_array->num * sizeof(struct inotify_watch));
 	
-	printf("Adding inotify for channel %s\n", path_channel);
+	printf_verbose("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,
+	printf_verbose("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
 
@@ -394,11 +409,11 @@
 			continue;
 		}
 		
-		printf("Channel file : %s\n", path_channel);
+		printf_verbose("Channel file : %s\n", path_channel);
 		
 		if(S_ISDIR(stat_buf.st_mode)) {
 
-			printf("Entering channel subdirectory...\n");
+			printf_verbose("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 +441,7 @@
 
 
 	err = ioctl(pair->channel, RELAY_GET_SUBBUF, &consumed_old);
-	printf("cookie : %u\n", consumed_old);
+	printf_verbose("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,17 @@
 	len = pair->subbuf_size;
 	offset = 0;
 	while (len > 0) {
-		printf("splice chan to pipe offset %lu\n", offset);
+		printf_verbose("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);
+		printf_verbose("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);
+		printf_verbose("splice pipe to file %ld\n", ret);
 		if (ret < 0) {
 			perror("Error in file splice");
 			goto write_error;
@@ -624,9 +639,11 @@
 		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",
+				printf_verbose(
+					"inotify wd %u event mask : %u for %s%s\n",
 					ievent->wd, ievent->mask,
-					iwatch_array->elem[i].path_channel, ievent->name);
+					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 +741,29 @@
 			goto free_fd;
 		}
 
-		printf("Data received\n");
+		printf_verbose("Data received\n");
 #ifdef HAS_INOTIFY
 		switch(pollfd[0].revents) {
 			case POLLERR:
-				printf("Error returned in polling inotify fd %d.\n", pollfd[0].fd);
+				printf_verbose(
+					"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);
+				printf_verbose(
+					"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);
+				printf_verbose(
+					"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);
+				printf_verbose(
+					"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 +776,29 @@
 		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);
+					printf_verbose(
+						"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);
+					printf_verbose(
+						"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);
+					printf_verbose(
+						"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);
+						printf_verbose(
+							"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 +823,9 @@
 						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);
+							printf_verbose(
+								"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;






^ permalink raw reply	[flat|nested] 8+ messages in thread

* [ltt-dev] [PATCH v3] Add -v option for lttd
  2008-10-27  5:32       ` [ltt-dev] [PATCH v3] " Zhaolei
@ 2008-10-28 14:27         ` Mathieu Desnoyers
  0 siblings, 0 replies; 8+ messages in thread
From: Mathieu Desnoyers @ 2008-10-28 14:27 UTC (permalink / raw)


* Zhaolei (zhaolei at cn.fujitsu.com) wrote:
> 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.
> 

Merged, thanks !

Mathieu

> Signed-off-by: Zhao Lei <zhaolei at cn.fujitsu.com>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers at polymtl.ca>
> ---
> diff -Nur ltt-control-0.56-24102008.org/lttd/lttd.c ltt-control-0.56-24102008/lttd/lttd.c
> --- ltt-control-0.56-24102008.org/lttd/lttd.c	2008-10-24 22:03:14.000000000 +0800
> +++ ltt-control-0.56-24102008/lttd/lttd.c	2008-10-27 13:27:41.000000000 +0800
> @@ -136,14 +136,21 @@
>  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;
> +
> +#define printf_verbose(fmt, args...) \
> +  do {                               \
> +    if (verbose_mode)                \
> +      printf(fmt, ##args);           \
> +  } while (0)
>  
>  /* Args :
>   *
>   * -t directory		Directory name of the trace to write to. Will be created.
>   * -c directory		Root directory of the debugfs trace channels.
>   * -d          		Run in background (daemon).
> - * -a							Trace append mode.
> - * -s							Send SIGUSR1 to parent when ready for IO.
> + * -a			Trace append mode.
> + * -s			Send SIGUSR1 to parent when ready for IO.
>   */
>  void show_arguments(void)
>  {
> @@ -157,6 +164,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 +222,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 +282,18 @@
>  
>  	if(strncmp(filename, "flight-", sizeof("flight-")-1) != 0) {
>  		if(dump_flight_only) {
> -			printf("Skipping normal channel %s\n", path_channel);
> +			printf_verbose("Skipping normal channel %s\n",
> +				path_channel);
>  			return 0;
>  		}
>  	} else {
>  		if(dump_normal_only) {
> -			printf("Skipping flight channel %s\n", path_channel);
> +			printf_verbose("Skipping flight channel %s\n",
> +				path_channel);
>  			return 0;
>  		}
>  	}
> -	printf("Opening file.\n");
> +	printf_verbose("Opening file.\n");
>  	
>  	fd_pairs->pair = realloc(fd_pairs->pair,
>  			++fd_pairs->num_pairs * sizeof(struct fd_pair));
> @@ -297,7 +310,8 @@
>  	ret = stat(path_trace, &stat_buf);
>  	if(ret == 0) {
>  		if(append_mode) {
> -			printf("Appending to file %s as requested\n", path_trace);
> +			printf_verbose("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 +361,7 @@
>  		goto end;
>  	}
>  
> -	printf("Creating trace subdirectory %s\n", subtrace_name);
> +	printf_verbose("Creating trace subdirectory %s\n", subtrace_name);
>  	ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO);
>  	if(ret == -1) {
>  		if(errno != EEXIST) {
> @@ -373,11 +387,12 @@
>  	iwatch_array->elem = realloc(iwatch_array->elem,
>  		++iwatch_array->num * sizeof(struct inotify_watch));
>  	
> -	printf("Adding inotify for channel %s\n", path_channel);
> +	printf_verbose("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,
> +	printf_verbose("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
>  
> @@ -394,11 +409,11 @@
>  			continue;
>  		}
>  		
> -		printf("Channel file : %s\n", path_channel);
> +		printf_verbose("Channel file : %s\n", path_channel);
>  		
>  		if(S_ISDIR(stat_buf.st_mode)) {
>  
> -			printf("Entering channel subdirectory...\n");
> +			printf_verbose("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 +441,7 @@
>  
>  
>  	err = ioctl(pair->channel, RELAY_GET_SUBBUF, &consumed_old);
> -	printf("cookie : %u\n", consumed_old);
> +	printf_verbose("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,17 @@
>  	len = pair->subbuf_size;
>  	offset = 0;
>  	while (len > 0) {
> -		printf("splice chan to pipe offset %lu\n", offset);
> +		printf_verbose("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);
> +		printf_verbose("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);
> +		printf_verbose("splice pipe to file %ld\n", ret);
>  		if (ret < 0) {
>  			perror("Error in file splice");
>  			goto write_error;
> @@ -624,9 +639,11 @@
>  		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",
> +				printf_verbose(
> +					"inotify wd %u event mask : %u for %s%s\n",
>  					ievent->wd, ievent->mask,
> -					iwatch_array->elem[i].path_channel, ievent->name);
> +					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 +741,29 @@
>  			goto free_fd;
>  		}
>  
> -		printf("Data received\n");
> +		printf_verbose("Data received\n");
>  #ifdef HAS_INOTIFY
>  		switch(pollfd[0].revents) {
>  			case POLLERR:
> -				printf("Error returned in polling inotify fd %d.\n", pollfd[0].fd);
> +				printf_verbose(
> +					"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);
> +				printf_verbose(
> +					"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);
> +				printf_verbose(
> +					"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);
> +				printf_verbose(
> +					"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 +776,29 @@
>  		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);
> +					printf_verbose(
> +						"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);
> +					printf_verbose(
> +						"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);
> +					printf_verbose(
> +						"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);
> +						printf_verbose(
> +							"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 +823,9 @@
>  						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);
> +							printf_verbose(
> +								"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;
> 
> 
> 
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
> 

-- 
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-10-28 14:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-21  5:39 [ltt-dev] PATCH] Make lttcrl/lttd show error when channel not exist Zhaolei
2008-10-21 14:05 ` Mathieu Desnoyers
2008-10-22  3:18   ` [ltt-dev] [PATCH v2 1/2] " Zhaolei
2008-10-24 14:12     ` Mathieu Desnoyers
2008-10-22  3:23   ` [ltt-dev] [PATCH v2 2/2] Add -v option for lttd Zhaolei
2008-10-24 14:15     ` Mathieu Desnoyers
2008-10-27  5:32       ` [ltt-dev] [PATCH v3] " Zhaolei
2008-10-28 14:27         ` Mathieu Desnoyers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox