libcpumf: Relocate ctr_in_list() for shared use

Move ctr_in_list() from cpumf/lspai.c to a shared location to enable
reuse in other binaries that require counter list filtering.

Reviewed-by:  Thomas Richter <tmricht@linux.ibm.com>
Signed-off-by: Jan Polensky <japo@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Jan Polensky
2025-09-29 12:58:52 +02:00
committed by Jan Höppner
parent 20a4ebd83c
commit 3a0c394fa2
3 changed files with 40 additions and 26 deletions
+23
View File
@@ -14,6 +14,7 @@
#include "lib/libcpumf.h"
#include "lib/util_path.h"
#include "lib/util_libc.h"
#define SERVICELEVEL "/proc/service_levels"
@@ -175,3 +176,25 @@ long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int g
{
return syscall(__NR_perf_event_open, hw_event, pid, cpu, group_fd, flags);
}
bool ctr_in_list(char *name, char *ctrlist)
{
char *token;
char *list;
if (!ctrlist) /* No --counters means all counters */
return true;
list = util_strdup(ctrlist);
token = strtok(list, ",");
while (token) {
if (strcmp(token, name) == 0) {
free(list);
return true;
}
token = strtok(NULL, ",");
}
free(list);
return false;
}