perf stat: Reduce scope of ru_stats

The ru_stats are used to capture user and system time stats when a
process exits. These are then applied to user and system time tool
events if their reads fail due to the process terminating. Reduce the
scope now the metric code no longer reads these values.

Signed-off-by: Ian Rogers <irogers@google.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
This commit is contained in:
Ian Rogers 2025-11-13 10:05:11 -08:00 committed by Namhyung Kim
parent 3d65f6445f
commit 557c34435b
4 changed files with 18 additions and 25 deletions

View File

@ -104,6 +104,11 @@
#define DEFAULT_SEPARATOR " "
#define FREEZE_ON_SMI_PATH "bus/event_source/devices/cpu/freeze_on_smi"
struct rusage_stats {
struct stats ru_utime_usec_stat;
struct stats ru_stime_usec_stat;
};
static void print_counters(struct timespec *ts, int argc, const char **argv);
static struct evlist *evsel_list;
@ -133,6 +138,7 @@ static bool interval_count;
static const char *output_name;
static int output_fd;
static char *metrics;
static struct rusage_stats ru_stats;
struct perf_stat {
bool record;
@ -730,6 +736,17 @@ static int create_perf_stat_counter(struct evsel *evsel,
evsel->core.threads);
}
static void update_rusage_stats(const struct rusage *rusage)
{
const u64 us_to_ns = 1000;
const u64 s_to_ns = 1000000000;
update_stats(&ru_stats.ru_utime_usec_stat,
(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
update_stats(&ru_stats.ru_stime_usec_stat,
(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
}
static int __run_perf_stat(int argc, const char **argv, int run_idx)
{
int interval = stat_config.interval;
@ -979,7 +996,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
evlist__reset_aggr_stats(evsel_list);
} else {
update_stats(&walltime_nsecs_stats, t1 - t0);
update_rusage_stats(&ru_stats, &stat_config.ru_data);
update_rusage_stats(&stat_config.ru_data);
}
/*

View File

@ -45,7 +45,6 @@ struct perf_stat_config stat_config = {
.run_count = 1,
.metric_only_len = METRIC_ONLY_LEN,
.walltime_nsecs_stats = &walltime_nsecs_stats,
.ru_stats = &ru_stats,
.big_num = true,
.ctl_fd = -1,
.ctl_fd_ack = -1,

View File

@ -19,12 +19,10 @@
#include "tool_pmu.h"
struct stats walltime_nsecs_stats;
struct rusage_stats ru_stats;
void perf_stat__reset_shadow_stats(void)
{
memset(&walltime_nsecs_stats, 0, sizeof(walltime_nsecs_stats));
memset(&ru_stats, 0, sizeof(ru_stats));
}
static bool tool_pmu__is_time_event(const struct perf_stat_config *config,

View File

@ -56,11 +56,6 @@ enum aggr_mode {
AGGR_MAX
};
struct rusage_stats {
struct stats ru_utime_usec_stat;
struct stats ru_stime_usec_stat;
};
typedef struct aggr_cpu_id (*aggr_get_id_t)(struct perf_stat_config *config, struct perf_cpu cpu);
struct perf_stat_config {
@ -102,7 +97,6 @@ struct perf_stat_config {
const char *csv_sep;
struct stats *walltime_nsecs_stats;
struct rusage ru_data;
struct rusage_stats *ru_stats;
struct cpu_aggr_map *aggr_map;
aggr_get_id_t aggr_get_id;
struct cpu_aggr_map *cpus_aggr_map;
@ -132,25 +126,10 @@ static inline void init_stats(struct stats *stats)
stats->max = 0;
}
static inline void init_rusage_stats(struct rusage_stats *ru_stats) {
init_stats(&ru_stats->ru_utime_usec_stat);
init_stats(&ru_stats->ru_stime_usec_stat);
}
static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rusage* rusage) {
const u64 us_to_ns = 1000;
const u64 s_to_ns = 1000000000;
update_stats(&ru_stats->ru_utime_usec_stat,
(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
update_stats(&ru_stats->ru_stime_usec_stat,
(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
}
struct evsel;
struct evlist;
extern struct stats walltime_nsecs_stats;
extern struct rusage_stats ru_stats;
enum metric_threshold_classify {
METRIC_THRESHOLD_UNKNOWN,