in src/oscounter.c [83:121]
uint64_t get_interrupts_from_proc_by_dev(char *dev_name)
{
FILE *file = fopen(PROC_FILE_INTERRUPTS, "r");
if (file == NULL) {
PRINT_ERR("Cannot open /proc/interrupts");
return 0;
}
if (!strcmp(dev_name, ""))
return 0;
/* the max number of chars in each line = 64 + 12 chars/cpu * 1024 cpus + 128 = 12,480 */
char buffer[12480];
char *line;
char *value;
uint64_t interrupts = 0;
uint64_t total_interrupts = 0;
while ((line = fgets(buffer, 12480, file)) != NULL) {
if (strstr(line, dev_name) == NULL) {
continue;
}
value = strtok(line, " ");
while (value != NULL) {
if (!is_str_number(value)) {
/* go to next element ("value") */
value = strtok(NULL, " ");
continue;
}
errno = 0;
interrupts = strtoull(value, NULL, 10);
total_interrupts += (errno == 0) ? interrupts : 0;
/* go to next element ("value") */
value = strtok(NULL, " ");
}
}
fclose(file);
return total_interrupts;
}