1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-03-21 01:59:13 +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:
Sebastian Goscik 2025-02-28 16:14:59 +00:00 committed by Marc Bonnici
parent 8598d1ba3c
commit 2d14c82f92
4 changed files with 39 additions and 11 deletions

View File

@ -59,6 +59,12 @@ class FilePoller(Instrument):
Whether or not the poller will be run as root. This should be 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. 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): def validate(self):
@ -91,13 +97,17 @@ class FilePoller(Instrument):
if self.align_with_ftrace: if self.align_with_ftrace:
marker_option = '-m' marker_option = '-m'
signal.connect(self._adjust_timestamps, signal.AFTER_JOB_OUTPUT_PROCESSED) signal.connect(self._adjust_timestamps, signal.AFTER_JOB_OUTPUT_PROCESSED)
self.command = '{} -t {} {} -l {} {} > {} 2>{}'.format(target_poller, reopen_option = ''
self.sample_interval * 1000, if self.reopen:
marker_option, reopen_option = '-r'
','.join(self.labels), self.command = '{} {} -t {} {} -l {} {} > {} 2>{}'.format(target_poller,
' '.join(self.files), reopen_option,
self.target_output_path, self.sample_interval * 1000,
self.target_log_path) marker_option,
','.join(self.labels),
' '.join(self.files),
self.target_output_path,
self.target_log_path)
def start(self, context): def start(self, context):
self.target.kick_off(self.command, as_root=self.as_root) self.target.kick_off(self.command, as_root=self.as_root)

View File

@ -77,9 +77,10 @@ int main(int argc, char ** argv) {
char *labels; char *labels;
int labelCount = 0; int labelCount = 0;
int should_write_marker = 0; int should_write_marker = 0;
int reopen_files = 0;
int ret; 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" "polls FILE(s) every INTERVAL microseconds and outputs\n"
"the results in CSV format including a timestamp to STDOUT\n" "the results in CSV format including a timestamp to STDOUT\n"
"\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" " -m Insert a marker into ftrace at the time of the first\n"
" sample. This marker may be used to align the timestamps\n" " sample. This marker may be used to align the timestamps\n"
" produced by the poller with those of ftrace events.\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" " -t The polling sample interval in microseconds\n"
" Defaults to 1000000 (1 second)\n" " Defaults to 1000000 (1 second)\n"
" -l Comma separated list of labels to use in the CSV\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 //Handling command line arguments
while ((c = getopt(argc, argv, "hmt:l:")) != -1) while ((c = getopt(argc, argv, "hmrt:l:")) != -1)
{ {
switch(c) { switch(c) {
case 'h': case 'h':
@ -104,7 +106,10 @@ int main(int argc, char ** argv) {
break; break;
case 'm': case 'm':
should_write_marker = 1; should_write_marker = 1;
break; break;
case 'r':
reopen_files = 1;
break;
case 't': case 't':
interval = (useconds_t)atoi(optarg); interval = (useconds_t)atoi(optarg);
break; break;
@ -184,7 +189,20 @@ int main(int argc, char ** argv) {
time_float += ((double)current_time.tv_nsec)/1000/1000/1000; time_float += ((double)current_time.tv_nsec)/1000/1000/1000;
printf("%f", time_float); printf("%f", time_float);
for (i = 0; i < num_files; i++) { 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); bytes_read = read(files_to_poll[i].fd, buf, 1024);
if (bytes_read < 0) { if (bytes_read < 0) {