On Tue, 2 Aug 2016 06:39:31 +0300
eSyr <evgsyr(a)gmail.com> wrote:
Currently, multiple processes shown in overview and consumers list
are
indistinguishable in case they have the same command line. This commit
prepends PID enclosed in square brackets to the beginning of description
line, similarly to the interrupt ID in interrupt description.
* src/process/process.cpp (process::process): printing PID to desc,
adding process description after it.
---
src/process/process.cpp | 17 +++++++++++++----
1 file changed, 13 insertions(+), 4 deletions(-)
diff --git a/src/process/process.cpp b/src/process/process.cpp
index caeccec..e244c5d 100644
--- a/src/process/process.cpp
+++ b/src/process/process.cpp
@@ -89,6 +89,7 @@ process::process(const char *_comm, int _pid, int _tid) :
power_consumer()
{
char line[4097];
ifstream file;
+ ssize_t pos;
pt_strcpy(comm, _comm);
pid = _pid;
@@ -121,7 +122,15 @@ process::process(const char *_comm, int _pid, int _tid) :
power_consumer()
if (strncmp(_comm, "kondemand/", 10) == 0)
is_idle = 1;
- pt_strcpy(desc, comm);
+ pos = snprintf(desc, sizeof(desc), "[PID %d] ", pid);
+
+ if (pos < 0)
+ pos = 0;
+ if ((size_t)pos > sizeof(desc))
+ return;
+
+ strncpy(desc + pos, comm, sizeof(desc) - pos - 1);
+ desc[sizeof(desc) - 1] = '\0';
sprintf(line, "/proc/%i/cmdline", _pid);
file.open(line, ios::binary);
@@ -131,11 +140,11 @@ process::process(const char *_comm, int _pid, int _tid) :
power_consumer()
file.close();
if (strlen(line) < 1) {
is_kernel = 1;
- snprintf(desc, sizeof(desc), "[%s]", comm);
+ snprintf(desc + pos, sizeof(desc) - pos, "[%s]", comm);
} else {
- int sz = sizeof(desc) - 1;
+ int sz = sizeof(desc) - pos - 1;
cmdline_to_string(line);
- strncpy(desc, line, sz);
+ strncpy(desc + pos, line, sz);
desc[sz] = 0x00;
}
}
Thinking aloud: In the future I'd like to see a dedicated "ID" column in
the
Overview tab. For 'Process'-type listings, it would contain the process
identifier. For 'Interrupt', its identifier. This would enforce something like
1NF discipline from the relational database camp. (That would necessitate
cleanups in other tabs, though, as well as CSV and HTML report output.) In the
Overview tab, the "Description" column is a bit cluttered, imho.
Having said my piece...
You have my Acked-by. Pushed, and thanks for your contribution!
commit f69d4dc45ab526b87a14a04e9dead4f9fc76f8be
Author: eSyr <evgsyr(a)gmail.com>
AuthorDate: Tue Aug 2 06:39:31 2016 +0300
Commit: Joe Konno <joe.konno(a)intel.com>
CommitDate: Wed Aug 3 08:27:38 2016 -0700
Adding PID to process description.
Currently, multiple processes shown in overview and consumers list are
indistinguishable in case they have the same command line. This commit
prepends PID enclosed in square brackets to the beginning of description
line, similarly to the interrupt ID in interrupt description.
* src/process/process.cpp (process::process): printing PID to desc,
adding process description after it.
Acked-by: Joe Konno <joe.konno(a)intel.com>