Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf session: Add accessor for session->header.env

The perf_env from the header in the session is frequently accessed,
add an accessor function rather than access directly. Cache the value
to avoid repeated calls. No behavioral change.

Signed-off-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-10-irogers@google.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Ian Rogers and committed by
Namhyung Kim
c3e5b9ec 53b00ff3

+120 -107
+2 -2
tools/perf/builtin-annotate.c
··· 562 562 } 563 563 564 564 if (!annotate_opts.objdump_path) { 565 - ret = perf_env__lookup_objdump(&session->header.env, 565 + ret = perf_env__lookup_objdump(perf_session__env(session), 566 566 &annotate_opts.objdump_path); 567 567 if (ret) 568 568 goto out; ··· 896 896 897 897 symbol_conf.try_vmlinux_path = true; 898 898 899 - ret = symbol__init(&annotate.session->header.env); 899 + ret = symbol__init(perf_session__env(annotate.session)); 900 900 if (ret < 0) 901 901 goto out_delete; 902 902
+1 -1
tools/perf/builtin-buildid-cache.c
··· 453 453 return PTR_ERR(session); 454 454 } 455 455 456 - if (symbol__init(session ? &session->header.env : NULL) < 0) 456 + if (symbol__init(session ? perf_session__env(session) : NULL) < 0) 457 457 goto out; 458 458 459 459 setup_pager();
+9 -7
tools/perf/builtin-c2c.c
··· 2267 2267 int node, idx; 2268 2268 struct perf_cpu cpu; 2269 2269 int *cpu2node; 2270 + struct perf_env *env = perf_session__env(session); 2270 2271 2271 2272 if (c2c.node_info > 2) 2272 2273 c2c.node_info = 2; 2273 2274 2274 - c2c.nodes_cnt = session->header.env.nr_numa_nodes; 2275 - c2c.cpus_cnt = session->header.env.nr_cpus_avail; 2275 + c2c.nodes_cnt = env->nr_numa_nodes; 2276 + c2c.cpus_cnt = env->nr_cpus_avail; 2276 2277 2277 - n = session->header.env.numa_nodes; 2278 + n = env->numa_nodes; 2278 2279 if (!n) 2279 2280 return -EINVAL; 2280 2281 ··· 3031 3030 }; 3032 3031 int err = 0; 3033 3032 const char *output_str, *sort_str = NULL; 3033 + struct perf_env *env; 3034 3034 3035 3035 argc = parse_options(argc, argv, options, report_c2c_usage, 3036 3036 PARSE_OPT_STOP_AT_NON_OPTION); ··· 3074 3072 pr_debug("Error creating perf session\n"); 3075 3073 goto out; 3076 3074 } 3077 - 3075 + env = perf_session__env(session); 3078 3076 /* 3079 3077 * Use the 'tot' as default display type if user doesn't specify it; 3080 3078 * since Arm64 platform doesn't support HITMs flag, use 'peer' as the 3081 3079 * default display type. 3082 3080 */ 3083 3081 if (!display) { 3084 - if (!strcmp(perf_env__arch(&session->header.env), "arm64")) 3082 + if (!strcmp(perf_env__arch(env), "arm64")) 3085 3083 display = "peer"; 3086 3084 else 3087 3085 display = "tot"; ··· 3111 3109 goto out_session; 3112 3110 } 3113 3111 3114 - err = mem2node__init(&c2c.mem2node, &session->header.env); 3112 + err = mem2node__init(&c2c.mem2node, env); 3115 3113 if (err) 3116 3114 goto out_session; 3117 3115 ··· 3119 3117 if (err) 3120 3118 goto out_mem2node; 3121 3119 3122 - if (symbol__init(&session->header.env) < 0) 3120 + if (symbol__init(env) < 0) 3123 3121 goto out_mem2node; 3124 3122 3125 3123 /* No pipe support at the moment. */
+1 -1
tools/perf/builtin-inject.c
··· 2608 2608 inject.tool.finished_round = perf_event__drop_oe; 2609 2609 } 2610 2610 #endif 2611 - ret = symbol__init(&inject.session->header.env); 2611 + ret = symbol__init(perf_session__env(inject.session)); 2612 2612 if (ret < 0) 2613 2613 goto out_delete; 2614 2614
+1 -1
tools/perf/builtin-kmem.c
··· 2024 2024 symbol_conf.use_callchain = true; 2025 2025 } 2026 2026 2027 - symbol__init(&session->header.env); 2027 + symbol__init(perf_session__env(session)); 2028 2028 2029 2029 if (perf_time__parse_str(&ptime, time_str) != 0) { 2030 2030 pr_err("Invalid time string\n");
+2 -2
tools/perf/builtin-kvm.c
··· 1175 1175 } 1176 1176 cpuid = buf; 1177 1177 } else 1178 - cpuid = kvm->session->header.env.cpuid; 1178 + cpuid = perf_session__env(kvm->session)->cpuid; 1179 1179 1180 1180 if (!cpuid) { 1181 1181 pr_err("Failed to look up CPU type\n"); ··· 1561 1561 return PTR_ERR(kvm->session); 1562 1562 } 1563 1563 1564 - symbol__init(&kvm->session->header.env); 1564 + symbol__init(perf_session__env(kvm->session)); 1565 1565 1566 1566 if (!perf_session__has_traces(kvm->session, "kvm record")) { 1567 1567 ret = -EINVAL;
+1 -1
tools/perf/builtin-kwork.c
··· 1804 1804 return PTR_ERR(session); 1805 1805 } 1806 1806 1807 - symbol__init(&session->header.env); 1807 + symbol__init(perf_session__env(session)); 1808 1808 1809 1809 if (perf_kwork__check_config(kwork, session) != 0) 1810 1810 goto out_delete;
+2 -2
tools/perf/builtin-lock.c
··· 1876 1876 } 1877 1877 1878 1878 symbol_conf.allow_aliases = true; 1879 - symbol__init(&session->header.env); 1879 + symbol__init(perf_session__env(session)); 1880 1880 1881 1881 if (!data.is_pipe) { 1882 1882 if (!perf_session__has_traces(session, "lock record")) ··· 2042 2042 con.save_callstack = true; 2043 2043 2044 2044 symbol_conf.allow_aliases = true; 2045 - symbol__init(&session->header.env); 2045 + symbol__init(perf_session__env(session)); 2046 2046 2047 2047 if (use_bpf) { 2048 2048 err = target__validate(&target);
+1 -1
tools/perf/builtin-mem.c
··· 304 304 goto out_delete; 305 305 } 306 306 307 - ret = symbol__init(&session->header.env); 307 + ret = symbol__init(perf_session__env(session)); 308 308 if (ret < 0) 309 309 goto out_delete; 310 310
+12 -10
tools/perf/builtin-record.c
··· 2203 2203 } 2204 2204 } 2205 2205 2206 - if (evlist__add_bpf_sb_event(rec->sb_evlist, &rec->session->header.env)) { 2206 + if (evlist__add_bpf_sb_event(rec->sb_evlist, perf_session__env(rec->session))) { 2207 2207 pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n."); 2208 2208 return -1; 2209 2209 } ··· 2222 2222 struct perf_session *session = rec->session; 2223 2223 struct timespec ref_clockid; 2224 2224 struct timeval ref_tod; 2225 + struct perf_env *env = perf_session__env(session); 2225 2226 u64 ref; 2226 2227 2227 2228 if (!rec->opts.use_clockid) 2228 2229 return 0; 2229 2230 2230 2231 if (rec->opts.use_clockid && rec->opts.clockid_res_ns) 2231 - session->header.env.clock.clockid_res_ns = rec->opts.clockid_res_ns; 2232 + env->clock.clockid_res_ns = rec->opts.clockid_res_ns; 2232 2233 2233 - session->header.env.clock.clockid = rec->opts.clockid; 2234 + env->clock.clockid = rec->opts.clockid; 2234 2235 2235 2236 if (gettimeofday(&ref_tod, NULL) != 0) { 2236 2237 pr_err("gettimeofday failed, cannot set reference time.\n"); ··· 2246 2245 ref = (u64) ref_tod.tv_sec * NSEC_PER_SEC + 2247 2246 (u64) ref_tod.tv_usec * NSEC_PER_USEC; 2248 2247 2249 - session->header.env.clock.tod_ns = ref; 2248 + env->clock.tod_ns = ref; 2250 2249 2251 2250 ref = (u64) ref_clockid.tv_sec * NSEC_PER_SEC + 2252 2251 (u64) ref_clockid.tv_nsec; 2253 2252 2254 - session->header.env.clock.clockid_ns = ref; 2253 + env->clock.clockid_ns = ref; 2255 2254 return 0; 2256 2255 } 2257 2256 ··· 2397 2396 int fd; 2398 2397 float ratio = 0; 2399 2398 enum evlist_ctl_cmd cmd = EVLIST_CTL_CMD_UNSUPPORTED; 2399 + struct perf_env *env; 2400 2400 2401 2401 atexit(record__sig_exit); 2402 2402 signal(SIGCHLD, sig_handler); ··· 2439 2437 pr_err("Perf session creation failed.\n"); 2440 2438 return PTR_ERR(session); 2441 2439 } 2442 - 2440 + env = perf_session__env(session); 2443 2441 if (record__threads_enabled(rec)) { 2444 2442 if (perf_data__is_pipe(&rec->data)) { 2445 2443 pr_err("Parallel trace streaming is not available in pipe mode.\n"); ··· 2473 2471 } 2474 2472 #endif // HAVE_EVENTFD_SUPPORT 2475 2473 2476 - session->header.env.comp_type = PERF_COMP_ZSTD; 2477 - session->header.env.comp_level = rec->opts.comp_level; 2474 + env->comp_type = PERF_COMP_ZSTD; 2475 + env->comp_level = rec->opts.comp_level; 2478 2476 2479 2477 if (rec->opts.kcore && 2480 2478 !record__kcore_readable(&session->machines.host)) { ··· 2527 2525 } 2528 2526 /* Debug message used by test scripts */ 2529 2527 pr_debug3("perf record done opening and mmapping events\n"); 2530 - session->header.env.comp_mmap_len = session->evlist->core.mmap_len; 2528 + env->comp_mmap_len = session->evlist->core.mmap_len; 2531 2529 2532 2530 if (rec->opts.kcore) { 2533 2531 err = record__kcore_copy(&session->machines.host, data); ··· 2857 2855 2858 2856 if (rec->session->bytes_transferred && rec->session->bytes_compressed) { 2859 2857 ratio = (float)rec->session->bytes_transferred/(float)rec->session->bytes_compressed; 2860 - session->header.env.comp_ratio = ratio + 0.5; 2858 + env->comp_ratio = ratio + 0.5; 2861 2859 } 2862 2860 2863 2861 if (forks) {
+4 -4
tools/perf/builtin-report.c
··· 447 447 } 448 448 } 449 449 450 - callchain_param_setup(sample_type, perf_env__arch(&rep->session->header.env)); 450 + callchain_param_setup(sample_type, perf_env__arch(perf_session__env(rep->session))); 451 451 452 452 if (rep->stitch_lbr && (callchain_param.record_mode != CALLCHAIN_LBR)) { 453 453 ui__warning("Can't find LBR callchain. Switch off --stitch-lbr.\n" ··· 550 550 evlist__for_each_entry(evlist, pos) { 551 551 ret = report__browse_block_hists(&rep->block_reports[i++].hist, 552 552 rep->min_percent, pos, 553 - &rep->session->header.env); 553 + perf_session__env(rep->session)); 554 554 if (ret != 0) 555 555 return ret; 556 556 } ··· 685 685 } 686 686 687 687 ret = evlist__tui_browse_hists(evlist, help, NULL, rep->min_percent, 688 - &session->header.env, true); 688 + perf_session__env(session), true); 689 689 /* 690 690 * Usually "ret" is the last pressed key, and we only 691 691 * care if the key notifies us to switch data file. ··· 1842 1842 annotation_config__init(); 1843 1843 } 1844 1844 1845 - if (symbol__init(&session->header.env) < 0) 1845 + if (symbol__init(perf_session__env(session)) < 0) 1846 1846 goto error; 1847 1847 1848 1848 if (report.time_str) {
+5 -3
tools/perf/builtin-sched.c
··· 1939 1939 return PTR_ERR(session); 1940 1940 } 1941 1941 1942 - symbol__init(&session->header.env); 1942 + symbol__init(perf_session__env(session)); 1943 1943 1944 1944 /* prefer sched_waking if it is captured */ 1945 1945 if (evlist__find_tracepoint_by_name(session->evlist, "sched:sched_waking")) ··· 3294 3294 }; 3295 3295 3296 3296 struct perf_session *session; 3297 + struct perf_env *env; 3297 3298 struct evlist *evlist; 3298 3299 int err = -1; 3299 3300 ··· 3319 3318 if (IS_ERR(session)) 3320 3319 return PTR_ERR(session); 3321 3320 3321 + env = perf_session__env(session); 3322 3322 if (cpu_list) { 3323 3323 err = perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap); 3324 3324 if (err < 0) ··· 3328 3326 3329 3327 evlist = session->evlist; 3330 3328 3331 - symbol__init(&session->header.env); 3329 + symbol__init(env); 3332 3330 3333 3331 if (perf_time__parse_str(&sched->ptime, sched->time_str) != 0) { 3334 3332 pr_err("Invalid time string\n"); ··· 3367 3365 goto out; 3368 3366 3369 3367 /* pre-allocate struct for per-CPU idle stats */ 3370 - sched->max_cpu.cpu = session->header.env.nr_cpus_online; 3368 + sched->max_cpu.cpu = env->nr_cpus_online; 3371 3369 if (sched->max_cpu.cpu == 0) 3372 3370 sched->max_cpu.cpu = 4; 3373 3371 if (init_idle_threads(sched->max_cpu.cpu))
+8 -6
tools/perf/builtin-script.c
··· 714 714 } 715 715 } 716 716 717 - if (tod && !session->header.env.clock.enabled) { 717 + if (tod && !perf_session__env(session)->clock.enabled) { 718 718 pr_err("Can't provide 'tod' time, missing clock data. " 719 719 "Please record with -k/--clockid option.\n"); 720 720 return -1; ··· 759 759 if (buflen < 64 || !script) 760 760 return buf; 761 761 762 - env = &script->session->header.env; 762 + env = perf_session__env(script->session); 763 763 if (!env->clock.enabled) { 764 764 scnprintf(buf, buflen, "disabled"); 765 765 return buf; ··· 3863 3863 "perf script [<options>] <top-script> [script-args]", 3864 3864 NULL 3865 3865 }; 3866 + struct perf_env *env; 3866 3867 3867 3868 perf_set_singlethreaded(); 3868 3869 ··· 4110 4109 if (IS_ERR(session)) 4111 4110 return PTR_ERR(session); 4112 4111 4112 + env = perf_session__env(session); 4113 4113 if (header || header_only) { 4114 4114 script.tool.show_feat_hdr = SHOW_FEAT_HEADER; 4115 4115 perf_session__fprintf_info(session, stdout, show_full_info); ··· 4120 4118 if (show_full_info) 4121 4119 script.tool.show_feat_hdr = SHOW_FEAT_HEADER_FULL_INFO; 4122 4120 4123 - if (symbol__init(&session->header.env) < 0) 4121 + if (symbol__init(env) < 0) 4124 4122 goto out_delete; 4125 4123 4126 4124 uname(&uts); 4127 4125 if (data.is_pipe) { /* Assume pipe_mode indicates native_arch */ 4128 4126 native_arch = true; 4129 - } else if (session->header.env.arch) { 4130 - if (!strcmp(uts.machine, session->header.env.arch)) 4127 + } else if (env->arch) { 4128 + if (!strcmp(uts.machine, env->arch)) 4131 4129 native_arch = true; 4132 4130 else if (!strcmp(uts.machine, "x86_64") && 4133 - !strcmp(session->header.env.arch, "i386")) 4131 + !strcmp(env->arch, "i386")) 4134 4132 native_arch = true; 4135 4133 } 4136 4134
+12 -11
tools/perf/builtin-stat.c
··· 1689 1689 static struct aggr_cpu_id perf_stat__get_socket_file(struct perf_stat_config *config __maybe_unused, 1690 1690 struct perf_cpu cpu) 1691 1691 { 1692 - return perf_env__get_socket_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1692 + return perf_env__get_socket_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1693 1693 } 1694 1694 static struct aggr_cpu_id perf_stat__get_die_file(struct perf_stat_config *config __maybe_unused, 1695 1695 struct perf_cpu cpu) 1696 1696 { 1697 - return perf_env__get_die_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1697 + return perf_env__get_die_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1698 1698 } 1699 1699 1700 1700 static struct aggr_cpu_id perf_stat__get_cluster_file(struct perf_stat_config *config __maybe_unused, 1701 1701 struct perf_cpu cpu) 1702 1702 { 1703 - return perf_env__get_cluster_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1703 + return perf_env__get_cluster_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1704 1704 } 1705 1705 1706 1706 static struct aggr_cpu_id perf_stat__get_cache_file(struct perf_stat_config *config __maybe_unused, 1707 1707 struct perf_cpu cpu) 1708 1708 { 1709 - return perf_env__get_cache_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1709 + return perf_env__get_cache_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1710 1710 } 1711 1711 1712 1712 static struct aggr_cpu_id perf_stat__get_core_file(struct perf_stat_config *config __maybe_unused, 1713 1713 struct perf_cpu cpu) 1714 1714 { 1715 - return perf_env__get_core_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1715 + return perf_env__get_core_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1716 1716 } 1717 1717 1718 1718 static struct aggr_cpu_id perf_stat__get_cpu_file(struct perf_stat_config *config __maybe_unused, 1719 1719 struct perf_cpu cpu) 1720 1720 { 1721 - return perf_env__get_cpu_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1721 + return perf_env__get_cpu_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1722 1722 } 1723 1723 1724 1724 static struct aggr_cpu_id perf_stat__get_node_file(struct perf_stat_config *config __maybe_unused, 1725 1725 struct perf_cpu cpu) 1726 1726 { 1727 - return perf_env__get_node_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1727 + return perf_env__get_node_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1728 1728 } 1729 1729 1730 1730 static struct aggr_cpu_id perf_stat__get_global_file(struct perf_stat_config *config __maybe_unused, 1731 1731 struct perf_cpu cpu) 1732 1732 { 1733 - return perf_env__get_global_aggr_by_cpu(cpu, &perf_stat.session->header.env); 1733 + return perf_env__get_global_aggr_by_cpu(cpu, perf_session__env(perf_stat.session)); 1734 1734 } 1735 1735 1736 1736 static aggr_cpu_id_get_t aggr_mode__get_aggr_file(enum aggr_mode aggr_mode) ··· 1789 1789 1790 1790 static int perf_stat_init_aggr_mode_file(struct perf_stat *st) 1791 1791 { 1792 - struct perf_env *env = &st->session->header.env; 1792 + struct perf_env *env = perf_session__env(st->session); 1793 1793 aggr_cpu_id_get_t get_id = aggr_mode__get_aggr_file(stat_config.aggr_mode); 1794 1794 bool needs_sort = stat_config.aggr_mode != AGGR_NONE; 1795 1795 ··· 2112 2112 { 2113 2113 struct perf_record_stat_round *stat_round = &event->stat_round; 2114 2114 struct timespec tsh, *ts = NULL; 2115 - const char **argv = session->header.env.cmdline_argv; 2116 - int argc = session->header.env.nr_cmdline; 2115 + struct perf_env *env = perf_session__env(session); 2116 + const char **argv = env->cmdline_argv; 2117 + int argc = env->nr_cmdline; 2117 2118 2118 2119 process_counters(); 2119 2120
+1 -1
tools/perf/builtin-timechart.c
··· 1618 1618 if (IS_ERR(session)) 1619 1619 return PTR_ERR(session); 1620 1620 1621 - symbol__init(&session->header.env); 1621 + symbol__init(perf_session__env(session)); 1622 1622 1623 1623 (void)perf_header__process_sections(&session->header, 1624 1624 perf_data__fd(session->data),
+3 -2
tools/perf/builtin-top.c
··· 647 647 } 648 648 649 649 ret = evlist__tui_browse_hists(top->evlist, help, &hbt, top->min_percent, 650 - &top->session->header.env, !top->record_opts.overwrite); 650 + perf_session__env(top->session), 651 + !top->record_opts.overwrite); 651 652 if (ret == K_RELOAD) { 652 653 top->zero = true; 653 654 goto repeat; ··· 1254 1253 int ret; 1255 1254 1256 1255 if (!annotate_opts.objdump_path) { 1257 - ret = perf_env__lookup_objdump(&top->session->header.env, 1256 + ret = perf_env__lookup_objdump(perf_session__env(top->session), 1258 1257 &annotate_opts.objdump_path); 1259 1258 if (ret) 1260 1259 return ret;
+1 -1
tools/perf/builtin-trace.c
··· 4701 4701 if (trace->opts.target.tid) 4702 4702 symbol_conf.tid_list_str = strdup(trace->opts.target.tid); 4703 4703 4704 - if (symbol__init(&session->header.env) < 0) 4704 + if (symbol__init(perf_session__env(session)) < 0) 4705 4705 goto out; 4706 4706 4707 4707 trace->host = &session->machines.host;
+17 -21
tools/perf/tests/topology.c
··· 69 69 int i; 70 70 struct aggr_cpu_id id; 71 71 struct perf_cpu cpu; 72 + struct perf_env *env; 72 73 73 74 session = perf_session__new(&data, NULL); 74 75 TEST_ASSERT_VAL("can't get session", !IS_ERR(session)); 76 + env = perf_session__env(session); 75 77 cpu__setup_cpunode_map(); 76 78 77 79 /* On platforms with large numbers of CPUs process_cpu_topology() ··· 97 95 * condition is true (see do_core_id_test in header.c). So always 98 96 * run this test on those platforms. 99 97 */ 100 - if (!session->header.env.cpu 101 - && strncmp(session->header.env.arch, "s390", 4) 102 - && strncmp(session->header.env.arch, "aarch64", 7)) 98 + if (!env->cpu && strncmp(env->arch, "s390", 4) && strncmp(env->arch, "aarch64", 7)) 103 99 return TEST_SKIP; 104 100 105 101 /* ··· 106 106 * physical_package_id will be set to -1. Hence skip this 107 107 * test if physical_package_id returns -1 for cpu from perf_cpu_map. 108 108 */ 109 - if (!strncmp(session->header.env.arch, "ppc64le", 7)) { 109 + if (!strncmp(env->arch, "ppc64le", 7)) { 110 110 if (cpu__get_socket_id(perf_cpu_map__cpu(map, 0)) == -1) 111 111 return TEST_SKIP; 112 112 } 113 113 114 - TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu); 114 + TEST_ASSERT_VAL("Session header CPU map not set", env->cpu); 115 115 116 - for (i = 0; i < session->header.env.nr_cpus_avail; i++) { 116 + for (i = 0; i < env->nr_cpus_avail; i++) { 117 117 cpu.cpu = i; 118 118 if (!perf_cpu_map__has(map, cpu)) 119 119 continue; 120 120 pr_debug("CPU %d, core %d, socket %d\n", i, 121 - session->header.env.cpu[i].core_id, 122 - session->header.env.cpu[i].socket_id); 121 + env->cpu[i].core_id, 122 + env->cpu[i].socket_id); 123 123 } 124 124 125 125 // Test that CPU ID contains socket, die, core and CPU ··· 129 129 cpu.cpu == id.cpu.cpu); 130 130 131 131 TEST_ASSERT_VAL("Cpu map - Core ID doesn't match", 132 - session->header.env.cpu[cpu.cpu].core_id == id.core); 132 + env->cpu[cpu.cpu].core_id == id.core); 133 133 TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match", 134 - session->header.env.cpu[cpu.cpu].socket_id == 135 - id.socket); 134 + env->cpu[cpu.cpu].socket_id == id.socket); 136 135 137 136 TEST_ASSERT_VAL("Cpu map - Die ID doesn't match", 138 - session->header.env.cpu[cpu.cpu].die_id == id.die); 137 + env->cpu[cpu.cpu].die_id == id.die); 139 138 TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1); 140 139 TEST_ASSERT_VAL("Cpu map - Thread IDX is set", id.thread_idx == -1); 141 140 } ··· 143 144 perf_cpu_map__for_each_cpu(cpu, i, map) { 144 145 id = aggr_cpu_id__core(cpu, NULL); 145 146 TEST_ASSERT_VAL("Core map - Core ID doesn't match", 146 - session->header.env.cpu[cpu.cpu].core_id == id.core); 147 + env->cpu[cpu.cpu].core_id == id.core); 147 148 148 149 TEST_ASSERT_VAL("Core map - Socket ID doesn't match", 149 - session->header.env.cpu[cpu.cpu].socket_id == 150 - id.socket); 150 + env->cpu[cpu.cpu].socket_id == id.socket); 151 151 152 152 TEST_ASSERT_VAL("Core map - Die ID doesn't match", 153 - session->header.env.cpu[cpu.cpu].die_id == id.die); 153 + env->cpu[cpu.cpu].die_id == id.die); 154 154 TEST_ASSERT_VAL("Core map - Node ID is set", id.node == -1); 155 155 TEST_ASSERT_VAL("Core map - Thread IDX is set", id.thread_idx == -1); 156 156 } ··· 158 160 perf_cpu_map__for_each_cpu(cpu, i, map) { 159 161 id = aggr_cpu_id__die(cpu, NULL); 160 162 TEST_ASSERT_VAL("Die map - Socket ID doesn't match", 161 - session->header.env.cpu[cpu.cpu].socket_id == 162 - id.socket); 163 + env->cpu[cpu.cpu].socket_id == id.socket); 163 164 164 165 TEST_ASSERT_VAL("Die map - Die ID doesn't match", 165 - session->header.env.cpu[cpu.cpu].die_id == id.die); 166 + env->cpu[cpu.cpu].die_id == id.die); 166 167 167 168 TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1); 168 169 TEST_ASSERT_VAL("Die map - Core is set", id.core == -1); ··· 173 176 perf_cpu_map__for_each_cpu(cpu, i, map) { 174 177 id = aggr_cpu_id__socket(cpu, NULL); 175 178 TEST_ASSERT_VAL("Socket map - Socket ID doesn't match", 176 - session->header.env.cpu[cpu.cpu].socket_id == 177 - id.socket); 179 + env->cpu[cpu.cpu].socket_id == id.socket); 178 180 179 181 TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); 180 182 TEST_ASSERT_VAL("Socket map - Die ID is set", id.die == -1);
+1 -1
tools/perf/util/bpf-event.c
··· 549 549 * for perf-record and perf-report use header.env; 550 550 * otherwise, use global perf_env. 551 551 */ 552 - env = session->data ? &session->header.env : &perf_env; 552 + env = session->data ? perf_session__env(session) : &perf_env; 553 553 554 554 arrays = 1UL << PERF_BPIL_JITED_KSYMS; 555 555 arrays |= 1UL << PERF_BPIL_JITED_FUNC_LENS;
+1 -1
tools/perf/util/branch.c
··· 46 46 "FAULT_DATA", 47 47 "FAULT_INST", 48 48 /* 49 - * TODO: This switch should happen on 'session->header.env.arch' 49 + * TODO: This switch should happen on 'perf_session__env(session)->arch' 50 50 * instead, because an arm64 platform perf recording could be 51 51 * opened for analysis on other platforms as well. 52 52 */
+8 -8
tools/perf/util/data-convert-bt.c
··· 1338 1338 static int setup_streams(struct ctf_writer *cw, struct perf_session *session) 1339 1339 { 1340 1340 struct ctf_stream **stream; 1341 - struct perf_header *ph = &session->header; 1341 + struct perf_env *env = perf_session__env(session); 1342 1342 int ncpus; 1343 1343 1344 1344 /* 1345 1345 * Try to get the number of cpus used in the data file, 1346 1346 * if not present fallback to the MAX_CPUS. 1347 1347 */ 1348 - ncpus = ph->env.nr_cpus_avail ?: MAX_CPUS; 1348 + ncpus = env->nr_cpus_avail ?: MAX_CPUS; 1349 1349 1350 1350 stream = zalloc(sizeof(*stream) * ncpus); 1351 1351 if (!stream) { ··· 1371 1371 static int ctf_writer__setup_env(struct ctf_writer *cw, 1372 1372 struct perf_session *session) 1373 1373 { 1374 - struct perf_header *header = &session->header; 1374 + struct perf_env *env = perf_session__env(session); 1375 1375 struct bt_ctf_writer *writer = cw->writer; 1376 1376 1377 1377 #define ADD(__n, __v) \ ··· 1380 1380 return -1; \ 1381 1381 } while (0) 1382 1382 1383 - ADD("host", header->env.hostname); 1383 + ADD("host", env->hostname); 1384 1384 ADD("sysname", "Linux"); 1385 - ADD("release", header->env.os_release); 1386 - ADD("version", header->env.version); 1387 - ADD("machine", header->env.arch); 1385 + ADD("release", env->os_release); 1386 + ADD("version", env->version); 1387 + ADD("machine", env->arch); 1388 1388 ADD("domain", "kernel"); 1389 1389 ADD("tracer_name", "perf"); 1390 1390 ··· 1401 1401 int64_t offset = 0; 1402 1402 1403 1403 if (tod) { 1404 - struct perf_env *env = &session->header.env; 1404 + struct perf_env *env = perf_session__env(session); 1405 1405 1406 1406 if (!env->clock.enabled) { 1407 1407 pr_err("Can't provide --tod time, missing clock data. "
+18 -18
tools/perf/util/data-convert-json.c
··· 257 257 static void output_headers(struct perf_session *session, struct convert_json *c) 258 258 { 259 259 struct stat st; 260 - struct perf_header *header = &session->header; 260 + const struct perf_header *header = &session->header; 261 + const struct perf_env *env = perf_session__env(session); 261 262 int ret; 262 263 int fd = perf_data__fd(session->data); 263 264 int i; ··· 281 280 output_json_key_format(out, true, 2, "data-size", "%" PRIu64, header->data_size); 282 281 output_json_key_format(out, true, 2, "feat-offset", "%" PRIu64, header->feat_offset); 283 282 284 - output_json_key_string(out, true, 2, "hostname", header->env.hostname); 285 - output_json_key_string(out, true, 2, "os-release", header->env.os_release); 286 - output_json_key_string(out, true, 2, "arch", header->env.arch); 283 + output_json_key_string(out, true, 2, "hostname", env->hostname); 284 + output_json_key_string(out, true, 2, "os-release", env->os_release); 285 + output_json_key_string(out, true, 2, "arch", env->arch); 287 286 288 - if (header->env.cpu_desc) 289 - output_json_key_string(out, true, 2, "cpu-desc", header->env.cpu_desc); 287 + if (env->cpu_desc) 288 + output_json_key_string(out, true, 2, "cpu-desc", env->cpu_desc); 290 289 291 - output_json_key_string(out, true, 2, "cpuid", header->env.cpuid); 292 - output_json_key_format(out, true, 2, "nrcpus-online", "%u", header->env.nr_cpus_online); 293 - output_json_key_format(out, true, 2, "nrcpus-avail", "%u", header->env.nr_cpus_avail); 290 + output_json_key_string(out, true, 2, "cpuid", env->cpuid); 291 + output_json_key_format(out, true, 2, "nrcpus-online", "%u", env->nr_cpus_online); 292 + output_json_key_format(out, true, 2, "nrcpus-avail", "%u", env->nr_cpus_avail); 294 293 295 - if (header->env.clock.enabled) { 294 + if (env->clock.enabled) { 296 295 output_json_key_format(out, true, 2, "clockid", 297 - "%u", header->env.clock.clockid); 296 + "%u", env->clock.clockid); 298 297 output_json_key_format(out, true, 2, "clock-time", 299 - "%" PRIu64, header->env.clock.clockid_ns); 298 + "%" PRIu64, env->clock.clockid_ns); 300 299 output_json_key_format(out, true, 2, "real-time", 301 - "%" PRIu64, header->env.clock.tod_ns); 300 + "%" PRIu64, env->clock.tod_ns); 302 301 } 303 302 304 - output_json_key_string(out, true, 2, "perf-version", header->env.version); 303 + output_json_key_string(out, true, 2, "perf-version", env->version); 305 304 306 305 output_json_key_format(out, true, 2, "cmdline", "["); 307 - for (i = 0; i < header->env.nr_cmdline; i++) { 306 + for (i = 0; i < env->nr_cmdline; i++) { 308 307 output_json_delimiters(out, i != 0, 3); 309 - output_json_string(c->out, header->env.cmdline_argv[i]); 308 + output_json_string(c->out, env->cmdline_argv[i]); 310 309 } 311 310 output_json_format(out, false, 2, "]"); 312 311 } ··· 377 376 fprintf(stderr, "Error creating perf session!\n"); 378 377 goto err_fclose; 379 378 } 380 - 381 - if (symbol__init(&session->header.env) < 0) { 379 + if (symbol__init(perf_session__env(session)) < 0) { 382 380 fprintf(stderr, "Symbol init error!\n"); 383 381 goto err_session_delete; 384 382 }
+6 -1
tools/perf/util/session.c
··· 2558 2558 { 2559 2559 int i, err = -1; 2560 2560 struct perf_cpu_map *map; 2561 - int nr_cpus = min(session->header.env.nr_cpus_avail, MAX_NR_CPUS); 2561 + int nr_cpus = min(perf_session__env(session)->nr_cpus_avail, MAX_NR_CPUS); 2562 2562 struct perf_cpu cpu; 2563 2563 2564 2564 for (i = 0; i < PERF_TYPE_MAX; ++i) { ··· 2746 2746 } 2747 2747 2748 2748 return 0; 2749 + } 2750 + 2751 + struct perf_env *perf_session__env(struct perf_session *session) 2752 + { 2753 + return &session->header.env; 2749 2754 }
+2
tools/perf/util/session.h
··· 208 208 union perf_event *event, 209 209 struct ordered_events *oe); 210 210 211 + struct perf_env *perf_session__env(struct perf_session *session); 212 + 211 213 #endif /* __PERF_SESSION_H */
+1 -1
tools/perf/util/tool.c
··· 20 20 void *src; 21 21 size_t decomp_size, src_size; 22 22 u64 decomp_last_rem = 0; 23 - size_t mmap_len, decomp_len = session->header.env.comp_mmap_len; 23 + size_t mmap_len, decomp_len = perf_session__env(session)->comp_mmap_len; 24 24 struct decomp *decomp, *decomp_last = session->active_decomp->decomp_last; 25 25 26 26 if (decomp_last) {