mirror of
				https://github.com/ARM-software/workload-automation.git
				synced 2025-10-31 07:04:17 +00:00 
			
		
		
		
	Added option to re-open files to poller.
Some times a sysfs/debug fs will only generate a value on open. Subsequent seek/read will not vield any new values. This patch adds the option to reopen all files on each read.
This commit is contained in:
		
				
					committed by
					
						 Marc Bonnici
						Marc Bonnici
					
				
			
			
				
	
			
			
			
						parent
						
							8598d1ba3c
						
					
				
				
					commit
					2d14c82f92
				
			| @@ -59,6 +59,12 @@ class FilePoller(Instrument): | ||||
|                   Whether or not the poller will be run as root. This should be | ||||
|                   used when the file you need to poll can only be accessed by root. | ||||
|                   """), | ||||
|         Parameter('reopen', kind=bool, default=False, | ||||
|                   description=""" | ||||
|                   When enabled files will be re-opened with each read. This is | ||||
|                   useful for some sysfs/debugfs entries that only generate a | ||||
|                   value when opened. | ||||
|                   """), | ||||
|     ] | ||||
|  | ||||
|     def validate(self): | ||||
| @@ -91,13 +97,17 @@ class FilePoller(Instrument): | ||||
|         if self.align_with_ftrace: | ||||
|             marker_option = '-m' | ||||
|             signal.connect(self._adjust_timestamps, signal.AFTER_JOB_OUTPUT_PROCESSED) | ||||
|         self.command = '{} -t {} {} -l {} {} > {} 2>{}'.format(target_poller, | ||||
|                                                                self.sample_interval * 1000, | ||||
|                                                                marker_option, | ||||
|                                                                ','.join(self.labels), | ||||
|                                                                ' '.join(self.files), | ||||
|                                                                self.target_output_path, | ||||
|                                                                self.target_log_path) | ||||
|         reopen_option = '' | ||||
|         if self.reopen: | ||||
|             reopen_option = '-r' | ||||
|         self.command = '{} {} -t {} {} -l {} {} > {} 2>{}'.format(target_poller, | ||||
|                                                                   reopen_option, | ||||
|                                                                   self.sample_interval * 1000, | ||||
|                                                                   marker_option, | ||||
|                                                                   ','.join(self.labels), | ||||
|                                                                   ' '.join(self.files), | ||||
|                                                                   self.target_output_path, | ||||
|                                                                   self.target_log_path) | ||||
|  | ||||
|     def start(self, context): | ||||
|         self.target.kick_off(self.command, as_root=self.as_root) | ||||
|   | ||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							| @@ -77,9 +77,10 @@ int main(int argc, char ** argv) { | ||||
|     char *labels; | ||||
|     int labelCount = 0; | ||||
|     int should_write_marker = 0; | ||||
|     int reopen_files = 0; | ||||
|     int ret; | ||||
|  | ||||
|     static char usage[] = "usage: %s [-h] [-m] [-t INTERVAL] FILE [FILE ...]\n" | ||||
|     static char usage[] = "usage: %s [-h] [-m] [-r] [-t INTERVAL] FILE [FILE ...]\n" | ||||
|                           "polls FILE(s) every INTERVAL microseconds and outputs\n" | ||||
|                           "the results in CSV format including a timestamp to STDOUT\n" | ||||
|                           "\n" | ||||
| @@ -87,6 +88,7 @@ int main(int argc, char ** argv) { | ||||
|                           "    -m     Insert a marker into ftrace at the time of the first\n" | ||||
|                           "           sample. This marker may be used to align the timestamps\n" | ||||
|                           "           produced by the poller with those of ftrace events.\n" | ||||
|                           "    -r     Reopen files on each read (needed for some sysfs/debugfs files)\n" | ||||
|                           "    -t     The polling sample interval in microseconds\n" | ||||
|                           "           Defaults to 1000000 (1 second)\n" | ||||
|                           "    -l     Comma separated list of labels to use in the CSV\n" | ||||
| @@ -94,7 +96,7 @@ int main(int argc, char ** argv) { | ||||
|  | ||||
|  | ||||
|     //Handling command line arguments | ||||
|     while ((c = getopt(argc, argv, "hmt:l:")) != -1) | ||||
|     while ((c = getopt(argc, argv, "hmrt:l:")) != -1) | ||||
|     { | ||||
|         switch(c) { | ||||
|             case 'h': | ||||
| @@ -104,7 +106,10 @@ int main(int argc, char ** argv) { | ||||
|                 break; | ||||
|             case 'm': | ||||
|                 should_write_marker = 1; | ||||
| 		break; | ||||
|                 break; | ||||
|             case 'r': | ||||
|                 reopen_files = 1; | ||||
|                 break; | ||||
|             case 't': | ||||
|                 interval = (useconds_t)atoi(optarg); | ||||
|                 break; | ||||
| @@ -184,7 +189,20 @@ int main(int argc, char ** argv) { | ||||
|         time_float += ((double)current_time.tv_nsec)/1000/1000/1000; | ||||
|         printf("%f", time_float); | ||||
|         for (i = 0; i < num_files; i++) { | ||||
|             lseek(files_to_poll[i].fd, 0, SEEK_SET); | ||||
|             if (reopen_files) { | ||||
|                 // Close and reopen the file to get fresh data | ||||
|                 close(files_to_poll[i].fd); | ||||
|                 files_to_poll[i].fd = open(files_to_poll[i].path, O_RDONLY); | ||||
|                 if (files_to_poll[i].fd == -1) { | ||||
|                     fprintf(stderr, "WARNING: Could not reopen \"%s\", got: %s\n", | ||||
|                             files_to_poll[i].path, strerror(errno)); | ||||
|                     printf(","); | ||||
|                     continue; | ||||
|                 } | ||||
|             } else { | ||||
|                 lseek(files_to_poll[i].fd, 0, SEEK_SET); | ||||
|             } | ||||
|  | ||||
|             bytes_read = read(files_to_poll[i].fd, buf, 1024); | ||||
|  | ||||
|             if (bytes_read < 0) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user