From: eSyr <evgsyr at gmail.com>
To: powertop@lists.01.org
Subject: [Powertop] [PATCH] Adding PID to process description.
Date: Tue, 02 Aug 2016 06:39:31 +0300 [thread overview]
Message-ID: <20160802033927.GA22138@obsidian> (raw)
[-- Attachment #1: Type: text/plain, Size: 1854 bytes --]
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;
}
}
--
1.7.10.4
next reply other threads:[~2016-08-02 3:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-02 3:39 eSyr [this message]
-- strict thread matches above, loose matches on Subject: below --
2016-08-03 15:41 [Powertop] [PATCH] Adding PID to process description Joe Konno
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160802033927.GA22138@obsidian \
--to=powertop@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox