[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180109153522.14116-48-jolsa@kernel.org>
Date: Tue, 9 Jan 2018 16:35:20 +0100
From: Jiri Olsa <jolsa@...nel.org>
To: Arnaldo Carvalho de Melo <acme@...nel.org>
Cc: lkml <linux-kernel@...r.kernel.org>,
Ingo Molnar <mingo@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
David Ahern <dsahern@...il.com>,
Andi Kleen <ak@...ux.intel.com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Peter Zijlstra <a.p.zijlstra@...llo.nl>
Subject: [PATCH 47/49] perf record: Add maps to --thread-stats output
Display free size of thread's memory maps as part
of --thread-stats output.
$ perf --debug threads=2 record ...
...
pid write poll skip maps (size 20K)
1s 8914 136B 1 0 19K 19K 19K 19K
2s 8914 512K 43 79 19K 19K 17K 19K
3s 8914 3M 214 385 17K 16K 16K 17K
4s 8914 3M 121 291 17K 17K 18K 18K
...
Link: http://lkml.kernel.org/n/tip-4id1fjlu5ypfqnu9kvpo7l3z@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@...nel.org>
---
tools/perf/builtin-record.c | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 3941bfa3d8aa..9ba64660982f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1270,10 +1270,25 @@ static int record__threads_stop(struct record *rec)
return err;
}
-static void record_thread__display(struct record_thread *t, unsigned long s)
+/* Stolen from kernel. */
+#define CIRC_CNT(head, tail, size) (((head) - (tail)) & ((size) - 1))
+#define CIRC_SPACE(head, tail, size) CIRC_CNT((tail), ((head)+1), (size))
+
+static u64 mmap_free_size(struct perf_mmap *map, struct perf_evlist *evlist)
+{
+ u64 head = perf_mmap__read_head(map);
+ u64 tail = perf_mmap__read_tail(map);
+
+ return CIRC_SPACE(head, tail, evlist->mmap_len);
+}
+
+static void
+record_thread__display(struct record_thread *t, struct perf_evlist *evlist,
+ unsigned long s)
{
char buf_size[20];
char buf_time[20];
+ int i;
unit_number__scnprintf(buf_size, sizeof(buf_size), t->stats.bytes_written);
@@ -1282,15 +1297,26 @@ static void record_thread__display(struct record_thread *t, unsigned long s)
else
buf_time[0] = 0;
- fprintf(stderr, "%6s %6d %10s %10" PRIu64" %10" PRIu64"\n",
+ fprintf(stderr, "%6s %6d %10s %10" PRIu64" %10" PRIu64 " ",
buf_time, t->pid, buf_size, t->stats.poll, t->stats.poll_skip);
+
+ for (i = 0; i < t->mmap_nr; i++) {
+ u64 size = mmap_free_size(t->mmap[i], evlist);
+
+ unit_number__scnprintf(buf_size, sizeof(buf_size), size);
+ fprintf(stderr, "%5s ", buf_size);
+ }
+
+ fprintf(stderr, "\n");
}
static void record__threads_stats(struct record *rec)
{
struct record_thread *threads = rec->threads;
+ struct perf_evlist *evlist = rec->evlist;
static time_t last, last_header, start;
time_t current = time(NULL);
+ char buf_size[20];
int i;
if (last == current)
@@ -1301,15 +1327,18 @@ static void record__threads_stats(struct record *rec)
last = current;
+ unit_number__scnprintf(buf_size, sizeof(buf_size), evlist->mmap_len);
+
if (!last_header || (last_header + 10 < current)) {
- fprintf(stderr, "%6s %6s %10s %10s %10s\n", " ", "pid", "write", "poll", "skip");
+ fprintf(stderr, "%6s %6s %10s %10s %10s %5s (size %s)\n",
+ " ", "pid", "write", "poll", "skip", "maps", buf_size);
last_header = current;
}
for (i = 0; i < rec->threads_cnt; i++) {
struct record_thread *t = threads + i;
- record_thread__display(t, !i ? current - start : 0);
+ record_thread__display(t, evlist, !i ? current - start : 0);
memset(&t->stats, 0, sizeof(t->stats));
}
}
--
2.13.6
Powered by blists - more mailing lists