[PATCH 2/2] perf kvm: Don't create an empty perf.data in live mode

From: James Clark

Date: Wed Nov 25 2026 - 10:12:42 EST


'perf kvm stat live' creates its session with a perf_data in write mode
but with no path, so perf_data__open() defaults to "perf.data" and
creates an empty file in the current directory. This is visible when
running the "perf kvm tests" test.

Do the same thing as 'perf top' and create the session without a
perf_data, passing a host env instead. Live mode never writes anything
to the file anyway.

Signed-off-by: James Clark <james.clark@xxxxxxxxxx>
---
tools/perf/builtin-kvm.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 785b761fb951..c48d56b18487 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1855,9 +1855,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
"perf kvm stat live [<options>]",
NULL
};
- struct perf_data data = {
- .mode = PERF_DATA_MODE_WRITE,
- };
+ struct perf_env host_env;


/* event handling */
@@ -1911,6 +1909,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
return err;
}

+ perf_env__init(&host_env);
kvm->evlist = kvm_live_event_list();
if (kvm->evlist == NULL) {
err = -1;
@@ -1923,7 +1922,9 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
/*
* perf session
*/
- kvm->session = perf_session__new(&data, &kvm->tool);
+ kvm->session = __perf_session__new(/*data=*/NULL, &kvm->tool,
+ /*trace_event_repipe=*/false,
+ &host_env);
if (IS_ERR(kvm->session)) {
err = PTR_ERR(kvm->session);
kvm->session = NULL;
@@ -1944,6 +1945,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
perf_session__delete(kvm->session);
kvm->session = NULL;
evlist__put(kvm->evlist);
+ perf_env__exit(&host_env);

return err;
}

--
2.43.0