Re: [PATCH 2/5] perf sched stats: Add record and rawdump support

From: Sapkal, Swapnil
Date: Wed Sep 18 2024 - 04:57:06 EST


Hi James,

Thanks for the review.

On 9/17/2024 4:05 PM, James Clark wrote:


On 16/09/2024 17:47, Ravi Bangoria wrote:
From: Swapnil Sapkal <swapnil.sapkal@xxxxxxx>

Define new, perf tool only, sample types and their layouts. Add logic
to parse /proc/schedstat, convert it to perf sample format and save
samples to perf.data file with `perf sched stats record` command. Also
add logic to read perf.data file, interpret schedstat samples and
print rawdump of samples with `perf script -D`.

Note that, /proc/schedstat file output is standardized with version
number. The patch supports v15 but older or newer version can be added
easily.

Signed-off-by: Swapnil Sapkal <swapnil.sapkal@xxxxxxx>
Co-developed-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>
Signed-off-by: Ravi Bangoria <ravi.bangoria@xxxxxxx>
---

[...]

+int perf_event__synthesize_schedstat(const struct perf_tool *tool,
+                     perf_event__handler_t process,
+                     struct perf_cpu_map *user_requested_cpus)
+{
+    union perf_event *event = NULL;
+    size_t line_len = 0;
+    char *line = NULL;
+    char bf[BUFSIZ];
+    __u64 timestamp;
+    __u16 version;
+    struct io io;
+    int ret = -1;
+    int cpu = -1;
+    char ch;
+
+    io.fd = open("/proc/schedstat", O_RDONLY, 0);

Other parts of the tool use procfs__mountpoint() for /proc. Although it can only be in one place so it doesn't actually make a difference for this one. Probably worth it for consistency though.

Sure, I will update this in the next version.

+    if (io.fd < 0) {
+        pr_err("Failed to open /proc/schedstat\n");

A hint about CONFIG_SCHEDSTAT would be useful here.

Sure, I will update.

--
Thanks and Regards,
Swapnil