Skip to content

Commit 65bdb8f

Browse files
committed
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 <[email protected]>
1 parent 767209a commit 65bdb8f

File tree

4 files changed

+13
-20
lines changed

4 files changed

+13
-20
lines changed

tools/perf/builtin-stat.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ static bool interval_count;
132132
static const char *output_name;
133133
static int output_fd;
134134
static char *metrics;
135+
static struct rusage_stats ru_stats;
135136

136137
struct perf_stat {
137138
bool record;
@@ -696,6 +697,17 @@ static enum counter_recovery stat_handle_error(struct evsel *counter)
696697
return COUNTER_FATAL;
697698
}
698699

700+
static void update_rusage_stats(const struct rusage *rusage)
701+
{
702+
const u64 us_to_ns = 1000;
703+
const u64 s_to_ns = 1000000000;
704+
705+
update_stats(&ru_stats.ru_utime_usec_stat,
706+
(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
707+
update_stats(&ru_stats.ru_stime_usec_stat,
708+
(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
709+
}
710+
699711
static int __run_perf_stat(int argc, const char **argv, int run_idx)
700712
{
701713
int interval = stat_config.interval;
@@ -947,7 +959,7 @@ static int __run_perf_stat(int argc, const char **argv, int run_idx)
947959
evlist__reset_aggr_stats(evsel_list);
948960
} else {
949961
update_stats(&walltime_nsecs_stats, t1 - t0);
950-
update_rusage_stats(&ru_stats, &stat_config.ru_data);
962+
update_rusage_stats(&stat_config.ru_data);
951963
}
952964

953965
/*

tools/perf/util/config.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ struct perf_stat_config stat_config = {
4545
.run_count = 1,
4646
.metric_only_len = METRIC_ONLY_LEN,
4747
.walltime_nsecs_stats = &walltime_nsecs_stats,
48-
.ru_stats = &ru_stats,
4948
.big_num = true,
5049
.ctl_fd = -1,
5150
.ctl_fd_ack = -1,

tools/perf/util/stat-shadow.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "tool_pmu.h"
1919

2020
struct stats walltime_nsecs_stats;
21-
struct rusage_stats ru_stats;
2221

2322
enum {
2423
CTX_BIT_USER = 1 << 0,
@@ -74,7 +73,6 @@ static int evsel_context(const struct evsel *evsel)
7473
void perf_stat__reset_shadow_stats(void)
7574
{
7675
memset(&walltime_nsecs_stats, 0, sizeof(walltime_nsecs_stats));
77-
memset(&ru_stats, 0, sizeof(ru_stats));
7876
}
7977

8078
static enum stat_type evsel__stat_type(struct evsel *evsel)

tools/perf/util/stat.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ struct perf_stat_config {
102102
const char *csv_sep;
103103
struct stats *walltime_nsecs_stats;
104104
struct rusage ru_data;
105-
struct rusage_stats *ru_stats;
106105
struct cpu_aggr_map *aggr_map;
107106
aggr_get_id_t aggr_get_id;
108107
struct cpu_aggr_map *cpus_aggr_map;
@@ -132,25 +131,10 @@ static inline void init_stats(struct stats *stats)
132131
stats->max = 0;
133132
}
134133

135-
static inline void init_rusage_stats(struct rusage_stats *ru_stats) {
136-
init_stats(&ru_stats->ru_utime_usec_stat);
137-
init_stats(&ru_stats->ru_stime_usec_stat);
138-
}
139-
140-
static inline void update_rusage_stats(struct rusage_stats *ru_stats, struct rusage* rusage) {
141-
const u64 us_to_ns = 1000;
142-
const u64 s_to_ns = 1000000000;
143-
update_stats(&ru_stats->ru_utime_usec_stat,
144-
(rusage->ru_utime.tv_usec * us_to_ns + rusage->ru_utime.tv_sec * s_to_ns));
145-
update_stats(&ru_stats->ru_stime_usec_stat,
146-
(rusage->ru_stime.tv_usec * us_to_ns + rusage->ru_stime.tv_sec * s_to_ns));
147-
}
148-
149134
struct evsel;
150135
struct evlist;
151136

152137
extern struct stats walltime_nsecs_stats;
153-
extern struct rusage_stats ru_stats;
154138

155139
enum metric_threshold_classify {
156140
METRIC_THRESHOLD_UNKNOWN,

0 commit comments

Comments
 (0)