diff options
author | Allan Wirth <wirtha@users.sf.net> | 2014-03-01 09:09:19 +1100 |
---|---|---|
committer | Craig Small <csmall@enc.com.au> | 2014-03-01 09:21:46 +1100 |
commit | 265fa43ee48898001130b90d3656d48af5d241aa (patch) | |
tree | cf03b16a06d0f8f46b36c0d5d3701082c96fe06f /src | |
parent | 3638cc55b4d08851faba46635d737b24d016665b (diff) |
Full thread display for pstree an option
Commit [9de89a] made pstree show the correct thread names. This had
the unintended consequence of making a lot of thread views
uncompact, as the names would be different.
Allan suggested that if you want to see the real thread names, then
explictly ask for them. I agree and pstree now has a new option -t
for showing thread names.
$ pstree 22603
udisksd───4*[{udisksd}]
$ pstree -t 22603
udisksd─┬─{cleanup}
├─{gdbus}
├─{gmain}
└─{probing-thread}
References: [patches:#33] https://sourceforge.net/p/psmisc/patches/33/
Signed-off-by: Craig Small <csmall@enc.com.au>
Diffstat (limited to 'src')
-rw-r--r-- | src/pstree.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/pstree.c b/src/pstree.c index 071e6c4..d13630f 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -78,6 +78,8 @@ extern const char *__progname; #define NUM_NS 6 +#define THREAD_FORMAT "{%.*s}" /* Format for thread names */ + typedef struct _proc { char comm[COMM_LEN + 2 + 1]; /* add another 2 for thread brackets */ char **argv; /* only used : argv[0] is 1st arg; undef if argc < 1 */ @@ -133,7 +135,8 @@ static int *width = NULL; static int *more = NULL; static int print_args = 0, compact = 1, user_change = 0, pids = 0, pgids = 0, - show_parents = 0, by_pid = 0, trunc = 1, wait_end = 0, ns_change = 0; + show_parents = 0, by_pid = 0, trunc = 1, wait_end = 0, ns_change = 0, + thread_names = 0; static int show_scontext = 0; static int output_width = 132; static int cur_x = 1; @@ -803,6 +806,10 @@ static char* get_threadname(const pid_t pid, const int tid, const char *comm) if (! (threadname = malloc(COMM_LEN + 2 + 1))) { exit(2); } + if (!thread_names) { + sprintf(threadname, THREAD_FORMAT, COMM_LEN, comm); + return threadname; + } if (snprintf(path, PATH_MAX, "%s/%d/task/%d/stat", PROC_BASE, pid, tid) < 0) perror("get_threadname: asprintf"); if ( (file = fopen(path, "r")) != NULL) { @@ -811,15 +818,16 @@ static char* get_threadname(const pid_t pid, const int tid, const char *comm) && (endcomm = strrchr(thread_comm, ')'))) { ++thread_comm; *endcomm = '\0'; - sprintf(threadname, "{%.*s}", COMM_LEN, thread_comm); + sprintf(threadname, THREAD_FORMAT, COMM_LEN, thread_comm); (void) fclose(file); return threadname; } } + fclose(file); } + /* Fall back to old method */ - sprintf(threadname, "{%.*s}", COMM_LEN, comm); - fclose(file); + sprintf(threadname, THREAD_FORMAT, COMM_LEN, comm); return threadname; } @@ -1008,6 +1016,7 @@ static void usage(void) " -p, --show-pids show PIDs; implies -c\n" " -s, --show-parents show parents of the selected process\n" " -S, --ns-changes show namespace transitions\n" + " -t, --thread-names show full thread names\n" " -u, --uid-changes show uid transitions\n" " -U, --unicode use UTF-8 (Unicode) line drawing characters\n" " -V, --version display version information\n")); @@ -1059,6 +1068,7 @@ int main(int argc, char **argv) {"show-pgids", 0, NULL, 'g'}, {"show-parents", 0, NULL, 's'}, {"ns-changes", 0, NULL, 'S' }, + {"thread-names", 0, NULL, 't'}, {"uid-changes", 0, NULL, 'u'}, {"unicode", 0, NULL, 'U'}, {"version", 0, NULL, 'V'}, @@ -1109,11 +1119,11 @@ int main(int argc, char **argv) #ifdef WITH_SELINUX while ((c = - getopt_long(argc, argv, "aAcGhH:nN:pglsSuUVZ", options, + getopt_long(argc, argv, "aAcGhH:nN:pglsStuUVZ", options, NULL)) != -1) #else /*WITH_SELINUX */ while ((c = - getopt_long(argc, argv, "aAcGhH:nN:pglsSuUV", options, NULL)) != -1) + getopt_long(argc, argv, "aAcGhH:nN:pglsStuUV", options, NULL)) != -1) #endif /*WITH_SELINUX */ switch (c) { case 'a': @@ -1180,6 +1190,9 @@ int main(int argc, char **argv) case 'S': ns_change = 1; break; + case 't': + thread_names = 1; + break; case 'u': user_change = 1; break; |