@@ -77,24 +77,26 @@ int main(int argc, char ** argv) {
77
77
char * labels ;
78
78
int labelCount = 0 ;
79
79
int should_write_marker = 0 ;
80
+ int reopen_files = 0 ;
80
81
int ret ;
81
82
82
- static char usage [] = "usage: %s [-h] [-m] [-t INTERVAL] FILE [FILE ...]\n"
83
+ static char usage [] = "usage: %s [-h] [-m] [-r] [- t INTERVAL] FILE [FILE ...]\n"
83
84
"polls FILE(s) every INTERVAL microseconds and outputs\n"
84
85
"the results in CSV format including a timestamp to STDOUT\n"
85
86
"\n"
86
87
" -h Display this message\n"
87
88
" -m Insert a marker into ftrace at the time of the first\n"
88
89
" sample. This marker may be used to align the timestamps\n"
89
90
" produced by the poller with those of ftrace events.\n"
91
+ " -r Reopen files on each read (needed for some sysfs/debugfs files)\n"
90
92
" -t The polling sample interval in microseconds\n"
91
93
" Defaults to 1000000 (1 second)\n"
92
94
" -l Comma separated list of labels to use in the CSV\n"
93
95
" output. This should match the number of files\n" ;
94
96
95
97
96
98
//Handling command line arguments
97
- while ((c = getopt (argc , argv , "hmt :l:" )) != -1 )
99
+ while ((c = getopt (argc , argv , "hmrt :l:" )) != -1 )
98
100
{
99
101
switch (c ) {
100
102
case 'h' :
@@ -104,7 +106,10 @@ int main(int argc, char ** argv) {
104
106
break ;
105
107
case 'm' :
106
108
should_write_marker = 1 ;
107
- break ;
109
+ break ;
110
+ case 'r' :
111
+ reopen_files = 1 ;
112
+ break ;
108
113
case 't' :
109
114
interval = (useconds_t )atoi (optarg );
110
115
break ;
@@ -184,7 +189,20 @@ int main(int argc, char ** argv) {
184
189
time_float += ((double )current_time .tv_nsec )/1000 /1000 /1000 ;
185
190
printf ("%f" , time_float );
186
191
for (i = 0 ; i < num_files ; i ++ ) {
187
- lseek (files_to_poll [i ].fd , 0 , SEEK_SET );
192
+ if (reopen_files ) {
193
+ // Close and reopen the file to get fresh data
194
+ close (files_to_poll [i ].fd );
195
+ files_to_poll [i ].fd = open (files_to_poll [i ].path , O_RDONLY );
196
+ if (files_to_poll [i ].fd == -1 ) {
197
+ fprintf (stderr , "WARNING: Could not reopen \"%s\", got: %s\n" ,
198
+ files_to_poll [i ].path , strerror (errno ));
199
+ printf ("," );
200
+ continue ;
201
+ }
202
+ } else {
203
+ lseek (files_to_poll [i ].fd , 0 , SEEK_SET );
204
+ }
205
+
188
206
bytes_read = read (files_to_poll [i ].fd , buf , 1024 );
189
207
190
208
if (bytes_read < 0 ) {
0 commit comments