|
19 | 19 | #include "tool_pmu.h"
|
20 | 20 | #include "print-events.h"
|
21 | 21 | #include "strbuf.h"
|
| 22 | +#include "string2.h" |
22 | 23 |
|
23 | 24 | /*
|
24 | 25 | * core_pmus: A PMU belongs to core_pmus if it's name is "cpu" or it's sysfs
|
@@ -350,6 +351,82 @@ struct perf_pmu *perf_pmus__scan_core(struct perf_pmu *pmu)
|
350 | 351 | return NULL;
|
351 | 352 | }
|
352 | 353 |
|
| 354 | +struct perf_pmu *perf_pmus__scan_for_event(struct perf_pmu *pmu, const char *event) |
| 355 | +{ |
| 356 | + bool use_core_pmus = !pmu || pmu->is_core; |
| 357 | + |
| 358 | + if (!pmu) { |
| 359 | + /* Hwmon filename values that aren't used. */ |
| 360 | + enum hwmon_type type; |
| 361 | + int number; |
| 362 | + /* |
| 363 | + * Core PMUs, other sysfs PMUs and tool PMU can take all event |
| 364 | + * types or aren't wother optimizing for. |
| 365 | + */ |
| 366 | + unsigned int to_read_pmus = PERF_TOOL_PMU_TYPE_PE_CORE_MASK | |
| 367 | + PERF_TOOL_PMU_TYPE_PE_OTHER_MASK | |
| 368 | + PERF_TOOL_PMU_TYPE_TOOL_MASK; |
| 369 | + |
| 370 | + /* Could the event be a hwmon event? */ |
| 371 | + if (parse_hwmon_filename(event, &type, &number, /*item=*/NULL, /*alarm=*/NULL)) |
| 372 | + to_read_pmus |= PERF_TOOL_PMU_TYPE_HWMON_MASK; |
| 373 | + |
| 374 | + pmu_read_sysfs(to_read_pmus); |
| 375 | + pmu = list_prepare_entry(pmu, &core_pmus, list); |
| 376 | + } |
| 377 | + if (use_core_pmus) { |
| 378 | + list_for_each_entry_continue(pmu, &core_pmus, list) |
| 379 | + return pmu; |
| 380 | + |
| 381 | + pmu = NULL; |
| 382 | + pmu = list_prepare_entry(pmu, &other_pmus, list); |
| 383 | + } |
| 384 | + list_for_each_entry_continue(pmu, &other_pmus, list) |
| 385 | + return pmu; |
| 386 | + return NULL; |
| 387 | +} |
| 388 | + |
| 389 | +struct perf_pmu *perf_pmus__scan_matching_wildcard(struct perf_pmu *pmu, const char *wildcard) |
| 390 | +{ |
| 391 | + bool use_core_pmus = !pmu || pmu->is_core; |
| 392 | + |
| 393 | + if (!pmu) { |
| 394 | + /* |
| 395 | + * Core PMUs, other sysfs PMUs and tool PMU can have any name or |
| 396 | + * aren't wother optimizing for. |
| 397 | + */ |
| 398 | + unsigned int to_read_pmus = PERF_TOOL_PMU_TYPE_PE_CORE_MASK | |
| 399 | + PERF_TOOL_PMU_TYPE_PE_OTHER_MASK | |
| 400 | + PERF_TOOL_PMU_TYPE_TOOL_MASK; |
| 401 | + |
| 402 | + /* |
| 403 | + * Hwmon PMUs have an alias from a sysfs name like hwmon0, |
| 404 | + * hwmon1, etc. or have a name of hwmon_<name>. They therefore |
| 405 | + * can only have a wildcard match if the wildcard begins with |
| 406 | + * "hwmon". |
| 407 | + */ |
| 408 | + if (strisglob(wildcard) || |
| 409 | + (strlen(wildcard) >= 5 && strncmp("hwmon", wildcard, 5) == 0)) |
| 410 | + to_read_pmus |= PERF_TOOL_PMU_TYPE_HWMON_MASK; |
| 411 | + |
| 412 | + pmu_read_sysfs(to_read_pmus); |
| 413 | + pmu = list_prepare_entry(pmu, &core_pmus, list); |
| 414 | + } |
| 415 | + if (use_core_pmus) { |
| 416 | + list_for_each_entry_continue(pmu, &core_pmus, list) { |
| 417 | + if (perf_pmu__wildcard_match(pmu, wildcard)) |
| 418 | + return pmu; |
| 419 | + } |
| 420 | + pmu = NULL; |
| 421 | + pmu = list_prepare_entry(pmu, &other_pmus, list); |
| 422 | + } |
| 423 | + list_for_each_entry_continue(pmu, &other_pmus, list) { |
| 424 | + if (perf_pmu__wildcard_match(pmu, wildcard)) |
| 425 | + return pmu; |
| 426 | + } |
| 427 | + return NULL; |
| 428 | +} |
| 429 | + |
353 | 430 | static struct perf_pmu *perf_pmus__scan_skip_duplicates(struct perf_pmu *pmu)
|
354 | 431 | {
|
355 | 432 | bool use_core_pmus = !pmu || pmu->is_core;
|
|
0 commit comments