Commit e4810663 authored by Ian Rogers's avatar Ian Rogers Committed by Namhyung Kim
Browse files

perf machine: Explicitly pass in host perf_env



When creating a machine for the host explicitly pass in a scoped
perf_env. This removes a use of the global perf_env.

Signed-off-by: default avatarIan Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250724163302.596743-17-irogers@google.com


Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent aa91baa0
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -45,11 +45,14 @@ static int buildid__map_cb(struct map *map, void *arg __maybe_unused)

static void buildid__show_kernel_maps(void)
{
	struct perf_env host_env;
	struct machine *machine;

	machine = machine__new_host();
	perf_env__init(&host_env);
	machine = machine__new_host(&host_env);
	machine__for_each_kernel_map(machine, buildid__map_cb, NULL);
	machine__delete(machine);
	perf_env__exit(&host_env);
}

static int sysfs__fprintf_build_id(FILE *fp)
+16 −5
Original line number Diff line number Diff line
@@ -12,18 +12,28 @@
#include <subcmd/parse-options.h>
#include "debug.h"
#include "dso.h"
#include "env.h"
#include "machine.h"
#include "map.h"
#include "symbol.h"

static int __cmd_kallsyms(int argc, const char **argv)
{
	int i;
	struct machine *machine = machine__new_kallsyms();
	int i, err;
	struct perf_env host_env;
	struct machine *machine = NULL;


	perf_env__init(&host_env);
	err = perf_env__set_cmdline(&host_env, argc, argv);
	if (err)
		goto out;

	machine = machine__new_kallsyms(&host_env);
	if (machine == NULL) {
		pr_err("Couldn't read /proc/kallsyms\n");
		return -1;
		err = -1;
		goto out;
	}

	for (i = 0; i < argc; ++i) {
@@ -42,9 +52,10 @@ static int __cmd_kallsyms(int argc, const char **argv)
			map__unmap_ip(map, symbol->start), map__unmap_ip(map, symbol->end),
			symbol->start, symbol->end);
	}

out:
	machine__delete(machine);
	return 0;
	perf_env__exit(&host_env);
	return err;
}

int cmd_kallsyms(int argc, const char **argv)
+17 −7
Original line number Diff line number Diff line
@@ -140,6 +140,7 @@ struct syscall_fmt {
};

struct trace {
	struct perf_env		host_env;
	struct perf_tool	tool;
	struct {
		/** Sorted sycall numbers used by the trace. */
@@ -1977,17 +1978,24 @@ static char *trace__machine__resolve_kernel_addr(void *vmachine, unsigned long l
	return machine__resolve_kernel_addr(vmachine, addrp, modp);
}

static int trace__symbols_init(struct trace *trace, struct evlist *evlist)
static int trace__symbols_init(struct trace *trace, int argc, const char **argv,
			       struct evlist *evlist)
{
	int err = symbol__init(NULL);

	if (err)
		return err;

	trace->host = machine__new_host();
	if (trace->host == NULL)
		return -ENOMEM;
	perf_env__init(&trace->host_env);
	err = perf_env__set_cmdline(&trace->host_env, argc, argv);
	if (err)
		goto out;

	trace->host = machine__new_host(&trace->host_env);
	if (trace->host == NULL) {
		err = -ENOMEM;
		goto out;
	}
	thread__set_priv_destructor(thread_trace__delete);

	err = trace_event__register_resolver(trace->host, trace__machine__resolve_kernel_addr);
@@ -1998,9 +2006,10 @@ static int trace__symbols_init(struct trace *trace, struct evlist *evlist)
					    evlist->core.threads, trace__tool_process,
					    true, false, 1);
out:
	if (err)
	if (err) {
		perf_env__exit(&trace->host_env);
		symbol__exit();

	}
	return err;
}

@@ -2009,6 +2018,7 @@ static void trace__symbols__exit(struct trace *trace)
	machine__exit(trace->host);
	trace->host = NULL;

	perf_env__exit(&trace->host_env);
	symbol__exit();
}

@@ -4428,7 +4438,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
		goto out_delete_evlist;
	}

	err = trace__symbols_init(trace, evlist);
	err = trace__symbols_init(trace, argc, argv, evlist);
	if (err < 0) {
		fprintf(trace->output, "Problems initializing symbol libraries!\n");
		goto out_delete_evlist;
+1 −2
Original line number Diff line number Diff line
@@ -655,9 +655,8 @@ static int do_test_code_reading(bool try_kcore)

	pid = getpid();

	machine = machine__new_host();
	perf_env__init(&host_env);
	machine->env = &host_env;
	machine = machine__new_host(&host_env);

	ret = machine__create_kernel_maps(machine);
	if (ret < 0) {
+1 −2
Original line number Diff line number Diff line
@@ -353,9 +353,8 @@ static int test__dlfilter_test(struct test_data *td)
		return test_result("Failed to find program symbols", TEST_FAIL);

	pr_debug("Creating new host machine structure\n");
	td->machine = machine__new_host();
	perf_env__init(&host_env);
	td->machine->env = &host_env;
	td->machine = machine__new_host(&host_env);

	td->fd = creat(td->perf_data_file_name, 0644);
	if (td->fd < 0)
Loading