chiark / gitweb /
bootchart: add parameter "-C" to expand process names to the full cmdline
[elogind.git] / src / bootchart / log.c
index cf6c3a73f6bbe0214262d1c706de953550bd5d69..1e3f4a9e8c9c1b359c212f6dda3a57e964bb6018 100644 (file)
@@ -95,6 +95,26 @@ static char *bufgetline(char *buf)
         return c;
 }
 
         return c;
 }
 
+static int pid_cmdline_strncpy(char *buffer, int pid, size_t buf_len) {
+       char filename[PATH_MAX];
+       int _cleanup_close_ fd=-1;
+       ssize_t n;
+
+       sprintf(filename, "%d/cmdline", pid);
+       fd = openat(procfd, filename, O_RDONLY);
+       if (fd < 0)
+               return -errno;
+
+       n = read(fd, buffer, buf_len-1);
+        if (n > 0) {
+                int i;
+                for (i = 0; i < n; i++)
+                        if (buffer[i] == '\0')
+                                buffer[i] = ' ';
+                buffer[n] = '\0';
+        }
+       return 0;
+}
 
 void log_sample(int sample)
 {
 
 void log_sample(int sample)
 {
@@ -273,7 +293,12 @@ schedstat_next:
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
-                        strncpy(ps->name, key, 16);
+                        strncpy(ps->name, key, 256);
+
+                        /* cmdline */
+                        if (show_cmdline)
+                                pid_cmdline_strncpy(ps->name, pid, 256);
+
                         /* discard line 2 */
                         m = bufgetline(buf);
                         if (!m)
                         /* discard line 2 */
                         m = bufgetline(buf);
                         if (!m)
@@ -433,7 +458,11 @@ catch_rename:
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
                         if (!sscanf(buf, "%s %*s %*s", key))
                                 continue;
 
-                        strncpy(ps->name, key, 16);
+                        strncpy(ps->name, key, 256);
+
+                        /* cmdline */
+                        if (show_cmdline)
+                                pid_cmdline_strncpy(ps->name, pid, 256);
                 }
         }
 }
                 }
         }
 }