[PATCH v12 11/16] perf record: Introduce data transferred and compressed stats

Alexey Bayduraev
2021-11-23T14:10:14Z

Introduce bytes_transferred and bytes_compressed stats so they
would capture statistics for the related data buffer transfers.

Acked-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Namhyung Kim <namhyung@gmail.com>
Reviewed-by: Riccardo Mancini <rickyman7@gmail.com>
Tested-by: Riccardo Mancini <rickyman7@gmail.com>
Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
---
tools/perf/builtin-record.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1581da48fa9b..67181102c18f 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -109,6 +109,8 @@ struct record_thread {
unsigned long long samples;
unsigned long waking;
u64 bytes_written;
+ u64 bytes_transferred;
+ u64 bytes_compressed;
};

static __thread struct record_thread *thread;
@@ -1411,8 +1413,13 @@ static size_t zstd_compress(struct perf_session *session, struct mmap *map,
compressed = zstd_compress_stream_to_records(zstd_data, dst, dst_size, src, src_size,
max_record_size, process_comp_header);

- session->bytes_transferred += src_size;
- session->bytes_compressed += compressed;
+ if (map && map->file) {
+ thread->bytes_transferred += src_size;
+ thread->bytes_compressed += compressed;
+ } else {
+ session->bytes_transferred += src_size;
+ session->bytes_compressed += compressed;
+ }

return compressed;
}
@@ -2097,8 +2104,20 @@ static int record__stop_threads(struct record *rec)
for (t = 1; t < rec->nr_threads; t++)
record__terminate_thread(&thread_data[t]);

- for (t = 0; t < rec->nr_threads; t++)
+ for (t = 0; t < rec->nr_threads; t++) {
rec->samples += thread_data[t].samples;
+ if (!record__threads_enabled(rec))
+ continue;
+ rec->session->bytes_transferred += thread_data[t].bytes_transferred;
+ rec->session->bytes_compressed += thread_data[t].bytes_compressed;
+ pr_debug("threads[%d]: samples=%lld, wakes=%ld, ", thread_data[t].tid,
+ thread_data[t].samples, thread_data[t].waking);
+ if (thread_data[t].bytes_transferred && thread_data[t].bytes_compressed)
+ pr_debug("trasferred=%ld, compressed=%ld\n",
+ thread_data[t].bytes_transferred, thread_data[t].bytes_compressed);
+ else
+ pr_debug("written=%ld\n", thread_data[t].bytes_written);
+ }

return 0;
}
--
2.19.0