|
10 | 10 | #include <sys/utsname.h>
|
11 | 11 | #include <stdlib.h>
|
12 | 12 | #include <string.h>
|
| 13 | +#include "strbuf.h" |
13 | 14 |
|
14 | 15 | struct perf_env perf_env;
|
15 | 16 |
|
@@ -306,6 +307,45 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
|
306 | 307 | return 0;
|
307 | 308 | }
|
308 | 309 |
|
| 310 | +int perf_env__read_pmu_mappings(struct perf_env *env) |
| 311 | +{ |
| 312 | + struct perf_pmu *pmu = NULL; |
| 313 | + u32 pmu_num = 0; |
| 314 | + struct strbuf sb; |
| 315 | + |
| 316 | + while ((pmu = perf_pmu__scan(pmu))) { |
| 317 | + if (!pmu->name) |
| 318 | + continue; |
| 319 | + pmu_num++; |
| 320 | + } |
| 321 | + if (!pmu_num) { |
| 322 | + pr_debug("pmu mappings not available\n"); |
| 323 | + return -ENOENT; |
| 324 | + } |
| 325 | + env->nr_pmu_mappings = pmu_num; |
| 326 | + |
| 327 | + if (strbuf_init(&sb, 128 * pmu_num) < 0) |
| 328 | + return -ENOMEM; |
| 329 | + |
| 330 | + while ((pmu = perf_pmu__scan(pmu))) { |
| 331 | + if (!pmu->name) |
| 332 | + continue; |
| 333 | + if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0) |
| 334 | + goto error; |
| 335 | + /* include a NULL character at the end */ |
| 336 | + if (strbuf_add(&sb, "", 1) < 0) |
| 337 | + goto error; |
| 338 | + } |
| 339 | + |
| 340 | + env->pmu_mappings = strbuf_detach(&sb, NULL); |
| 341 | + |
| 342 | + return 0; |
| 343 | + |
| 344 | +error: |
| 345 | + strbuf_release(&sb); |
| 346 | + return -1; |
| 347 | +} |
| 348 | + |
309 | 349 | int perf_env__read_cpuid(struct perf_env *env)
|
310 | 350 | {
|
311 | 351 | char cpuid[128];
|
@@ -404,6 +444,44 @@ const char *perf_env__arch(struct perf_env *env)
|
404 | 444 | return normalize_arch(arch_name);
|
405 | 445 | }
|
406 | 446 |
|
| 447 | +const char *perf_env__cpuid(struct perf_env *env) |
| 448 | +{ |
| 449 | + int status; |
| 450 | + |
| 451 | + if (!env || !env->cpuid) { /* Assume local operation */ |
| 452 | + status = perf_env__read_cpuid(env); |
| 453 | + if (status) |
| 454 | + return NULL; |
| 455 | + } |
| 456 | + |
| 457 | + return env->cpuid; |
| 458 | +} |
| 459 | + |
| 460 | +int perf_env__nr_pmu_mappings(struct perf_env *env) |
| 461 | +{ |
| 462 | + int status; |
| 463 | + |
| 464 | + if (!env || !env->nr_pmu_mappings) { /* Assume local operation */ |
| 465 | + status = perf_env__read_pmu_mappings(env); |
| 466 | + if (status) |
| 467 | + return 0; |
| 468 | + } |
| 469 | + |
| 470 | + return env->nr_pmu_mappings; |
| 471 | +} |
| 472 | + |
| 473 | +const char *perf_env__pmu_mappings(struct perf_env *env) |
| 474 | +{ |
| 475 | + int status; |
| 476 | + |
| 477 | + if (!env || !env->pmu_mappings) { /* Assume local operation */ |
| 478 | + status = perf_env__read_pmu_mappings(env); |
| 479 | + if (status) |
| 480 | + return NULL; |
| 481 | + } |
| 482 | + |
| 483 | + return env->pmu_mappings; |
| 484 | +} |
407 | 485 |
|
408 | 486 | int perf_env__numa_node(struct perf_env *env, int cpu)
|
409 | 487 | {
|
|
0 commit comments