[PATCH v3 02/11] perf tools: Add perf_env__is_same_boot()
From: Namhyung Kim
Date: Mon Nov 23 2026 - 18:20:44 EST
Add perf_env__is_same_boot() to compare the recorded boot_id in struct
perf_env against the running host's /proc/sys/kernel/random/boot_id.
For live sessions where no offline header was populated, it falls back
to reading the host boot_id and returns true.
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/env.c | 25 +++++++++++++++++++++++++
tools/perf/util/env.h | 1 +
2 files changed, 26 insertions(+)
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index f624ba98e23c6a77..ce1f9ab2c40a9599 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -445,6 +445,31 @@ const char *perf_env__boot_id(struct perf_env *env)
return boot_id;
}
+static char *host_boot_id;
+
+static void init_host_boot_id(void)
+{
+ host_boot_id = read_host_boot_id();
+}
+
+bool perf_env__is_same_boot(struct perf_env *env)
+{
+ const char *env_boot_id;
+
+ DO_ONCE(init_host_boot_id);
+ if (!host_boot_id)
+ return false;
+
+ if (!env)
+ return true;
+
+ env_boot_id = perf_env__boot_id(env);
+ if (!env_boot_id)
+ return false;
+
+ return !strcmp(env_boot_id, host_boot_id);
+}
+
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[])
{
int i;
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index 4180380f4533790a..2d0a67ae306fb362 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -190,6 +190,7 @@ int perf_env__kernel_is_64_bit(struct perf_env *env);
bool perf_arch_is_big_endian(const char *arch);
const char *perf_env__os_release(struct perf_env *env);
const char *perf_env__boot_id(struct perf_env *env);
+bool perf_env__is_same_boot(struct perf_env *env);
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
--
2.56.1.809.ga0b61035b5-goog