[PATCH v1 02/11] perf tools: Add perf_env__is_same_boot()
From: Namhyung Kim
Date: Fri Oct 23 2026 - 03:13:22 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.
Assisted-by: LLM
Signed-off-by: Namhyung Kim <namhyung@xxxxxxxxxx>
---
tools/perf/util/env.c | 21 +++++++++++++++++++++
tools/perf/util/env.h | 1 +
2 files changed, 22 insertions(+)
diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 8ca0b677f3172b5f..735db21d66a019a5 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -444,6 +444,27 @@ const char *perf_env__boot_id(struct perf_env *env)
return boot_id;
}
+bool perf_env__is_same_boot(struct perf_env *env)
+{
+ static char *host_boot_id;
+ const char *env_boot_id;
+
+ if (!host_boot_id) {
+ host_boot_id = read_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 772d11eed1bc2a7c..df1d3d1ac3376e1e 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -189,6 +189,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.0.257.gf7497c7d27-goog