Skip to content

Commit c3e5b9e

Browse files
captain5050namhyung
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 53b00ff commit c3e5b9e

25 files changed

+120
-107
lines changed

tools/perf/builtin-annotate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ static int __cmd_annotate(struct perf_annotate *ann)
562562
}
563563

564564
if (!annotate_opts.objdump_path) {
565-
ret = perf_env__lookup_objdump(&session->header.env,
565+
ret = perf_env__lookup_objdump(perf_session__env(session),
566566
&annotate_opts.objdump_path);
567567
if (ret)
568568
goto out;
@@ -896,7 +896,7 @@ int cmd_annotate(int argc, const char **argv)
896896

897897
symbol_conf.try_vmlinux_path = true;
898898

899-
ret = symbol__init(&annotate.session->header.env);
899+
ret = symbol__init(perf_session__env(annotate.session));
900900
if (ret < 0)
901901
goto out_delete;
902902

tools/perf/builtin-buildid-cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ int cmd_buildid_cache(int argc, const char **argv)
453453
return PTR_ERR(session);
454454
}
455455

456-
if (symbol__init(session ? &session->header.env : NULL) < 0)
456+
if (symbol__init(session ? perf_session__env(session) : NULL) < 0)
457457
goto out;
458458

459459
setup_pager();

tools/perf/builtin-c2c.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2267,14 +2267,15 @@ static int setup_nodes(struct perf_session *session)
22672267
int node, idx;
22682268
struct perf_cpu cpu;
22692269
int *cpu2node;
2270+
struct perf_env *env = perf_session__env(session);
22702271

22712272
if (c2c.node_info > 2)
22722273
c2c.node_info = 2;
22732274

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;
22762277

2277-
n = session->header.env.numa_nodes;
2278+
n = env->numa_nodes;
22782279
if (!n)
22792280
return -EINVAL;
22802281

@@ -3030,6 +3031,7 @@ static int perf_c2c__report(int argc, const char **argv)
30303031
};
30313032
int err = 0;
30323033
const char *output_str, *sort_str = NULL;
3034+
struct perf_env *env;
30333035

30343036
argc = parse_options(argc, argv, options, report_c2c_usage,
30353037
PARSE_OPT_STOP_AT_NON_OPTION);
@@ -3072,14 +3074,14 @@ static int perf_c2c__report(int argc, const char **argv)
30723074
pr_debug("Error creating perf session\n");
30733075
goto out;
30743076
}
3075-
3077+
env = perf_session__env(session);
30763078
/*
30773079
* Use the 'tot' as default display type if user doesn't specify it;
30783080
* since Arm64 platform doesn't support HITMs flag, use 'peer' as the
30793081
* default display type.
30803082
*/
30813083
if (!display) {
3082-
if (!strcmp(perf_env__arch(&session->header.env), "arm64"))
3084+
if (!strcmp(perf_env__arch(env), "arm64"))
30833085
display = "peer";
30843086
else
30853087
display = "tot";
@@ -3109,15 +3111,15 @@ static int perf_c2c__report(int argc, const char **argv)
31093111
goto out_session;
31103112
}
31113113

3112-
err = mem2node__init(&c2c.mem2node, &session->header.env);
3114+
err = mem2node__init(&c2c.mem2node, env);
31133115
if (err)
31143116
goto out_session;
31153117

31163118
err = setup_callchain(session->evlist);
31173119
if (err)
31183120
goto out_mem2node;
31193121

3120-
if (symbol__init(&session->header.env) < 0)
3122+
if (symbol__init(env) < 0)
31213123
goto out_mem2node;
31223124

31233125
/* No pipe support at the moment. */

tools/perf/builtin-inject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ int cmd_inject(int argc, const char **argv)
26082608
inject.tool.finished_round = perf_event__drop_oe;
26092609
}
26102610
#endif
2611-
ret = symbol__init(&inject.session->header.env);
2611+
ret = symbol__init(perf_session__env(inject.session));
26122612
if (ret < 0)
26132613
goto out_delete;
26142614

tools/perf/builtin-kmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,7 +2024,7 @@ int cmd_kmem(int argc, const char **argv)
20242024
symbol_conf.use_callchain = true;
20252025
}
20262026

2027-
symbol__init(&session->header.env);
2027+
symbol__init(perf_session__env(session));
20282028

20292029
if (perf_time__parse_str(&ptime, time_str) != 0) {
20302030
pr_err("Invalid time string\n");

tools/perf/builtin-kvm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ static int cpu_isa_config(struct perf_kvm_stat *kvm)
11751175
}
11761176
cpuid = buf;
11771177
} else
1178-
cpuid = kvm->session->header.env.cpuid;
1178+
cpuid = perf_session__env(kvm->session)->cpuid;
11791179

11801180
if (!cpuid) {
11811181
pr_err("Failed to look up CPU type\n");
@@ -1561,7 +1561,7 @@ static int read_events(struct perf_kvm_stat *kvm)
15611561
return PTR_ERR(kvm->session);
15621562
}
15631563

1564-
symbol__init(&kvm->session->header.env);
1564+
symbol__init(perf_session__env(kvm->session));
15651565

15661566
if (!perf_session__has_traces(kvm->session, "kvm record")) {
15671567
ret = -EINVAL;

tools/perf/builtin-kwork.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1804,7 +1804,7 @@ static int perf_kwork__read_events(struct perf_kwork *kwork)
18041804
return PTR_ERR(session);
18051805
}
18061806

1807-
symbol__init(&session->header.env);
1807+
symbol__init(perf_session__env(session));
18081808

18091809
if (perf_kwork__check_config(kwork, session) != 0)
18101810
goto out_delete;

tools/perf/builtin-lock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ static int __cmd_report(bool display_info)
18761876
}
18771877

18781878
symbol_conf.allow_aliases = true;
1879-
symbol__init(&session->header.env);
1879+
symbol__init(perf_session__env(session));
18801880

18811881
if (!data.is_pipe) {
18821882
if (!perf_session__has_traces(session, "lock record"))
@@ -2042,7 +2042,7 @@ static int __cmd_contention(int argc, const char **argv)
20422042
con.save_callstack = true;
20432043

20442044
symbol_conf.allow_aliases = true;
2045-
symbol__init(&session->header.env);
2045+
symbol__init(perf_session__env(session));
20462046

20472047
if (use_bpf) {
20482048
err = target__validate(&target);

tools/perf/builtin-mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ static int report_raw_events(struct perf_mem *mem)
304304
goto out_delete;
305305
}
306306

307-
ret = symbol__init(&session->header.env);
307+
ret = symbol__init(perf_session__env(session));
308308
if (ret < 0)
309309
goto out_delete;
310310

tools/perf/builtin-record.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,7 +2203,7 @@ static int record__setup_sb_evlist(struct record *rec)
22032203
}
22042204
}
22052205

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))) {
22072207
pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
22082208
return -1;
22092209
}
@@ -2222,15 +2222,16 @@ static int record__init_clock(struct record *rec)
22222222
struct perf_session *session = rec->session;
22232223
struct timespec ref_clockid;
22242224
struct timeval ref_tod;
2225+
struct perf_env *env = perf_session__env(session);
22252226
u64 ref;
22262227

22272228
if (!rec->opts.use_clockid)
22282229
return 0;
22292230

22302231
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;
22322233

2233-
session->header.env.clock.clockid = rec->opts.clockid;
2234+
env->clock.clockid = rec->opts.clockid;
22342235

22352236
if (gettimeofday(&ref_tod, NULL) != 0) {
22362237
pr_err("gettimeofday failed, cannot set reference time.\n");
@@ -2245,12 +2246,12 @@ static int record__init_clock(struct record *rec)
22452246
ref = (u64) ref_tod.tv_sec * NSEC_PER_SEC +
22462247
(u64) ref_tod.tv_usec * NSEC_PER_USEC;
22472248

2248-
session->header.env.clock.tod_ns = ref;
2249+
env->clock.tod_ns = ref;
22492250

22502251
ref = (u64) ref_clockid.tv_sec * NSEC_PER_SEC +
22512252
(u64) ref_clockid.tv_nsec;
22522253

2253-
session->header.env.clock.clockid_ns = ref;
2254+
env->clock.clockid_ns = ref;
22542255
return 0;
22552256
}
22562257

@@ -2396,6 +2397,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
23962397
int fd;
23972398
float ratio = 0;
23982399
enum evlist_ctl_cmd cmd = EVLIST_CTL_CMD_UNSUPPORTED;
2400+
struct perf_env *env;
23992401

24002402
atexit(record__sig_exit);
24012403
signal(SIGCHLD, sig_handler);
@@ -2437,7 +2439,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
24372439
pr_err("Perf session creation failed.\n");
24382440
return PTR_ERR(session);
24392441
}
2440-
2442+
env = perf_session__env(session);
24412443
if (record__threads_enabled(rec)) {
24422444
if (perf_data__is_pipe(&rec->data)) {
24432445
pr_err("Parallel trace streaming is not available in pipe mode.\n");
@@ -2471,8 +2473,8 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
24712473
}
24722474
#endif // HAVE_EVENTFD_SUPPORT
24732475

2474-
session->header.env.comp_type = PERF_COMP_ZSTD;
2475-
session->header.env.comp_level = rec->opts.comp_level;
2476+
env->comp_type = PERF_COMP_ZSTD;
2477+
env->comp_level = rec->opts.comp_level;
24762478

24772479
if (rec->opts.kcore &&
24782480
!record__kcore_readable(&session->machines.host)) {
@@ -2525,7 +2527,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
25252527
}
25262528
/* Debug message used by test scripts */
25272529
pr_debug3("perf record done opening and mmapping events\n");
2528-
session->header.env.comp_mmap_len = session->evlist->core.mmap_len;
2530+
env->comp_mmap_len = session->evlist->core.mmap_len;
25292531

25302532
if (rec->opts.kcore) {
25312533
err = record__kcore_copy(&session->machines.host, data);
@@ -2855,7 +2857,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
28552857

28562858
if (rec->session->bytes_transferred && rec->session->bytes_compressed) {
28572859
ratio = (float)rec->session->bytes_transferred/(float)rec->session->bytes_compressed;
2858-
session->header.env.comp_ratio = ratio + 0.5;
2860+
env->comp_ratio = ratio + 0.5;
28592861
}
28602862

28612863
if (forks) {

0 commit comments

Comments
 (0)