Contrary to lstopo, hwloc-ps has no problem with long command-lines. What's the point of shortening to comm here?
Brice Le 29/08/2017 18:27, 'Gitdub ' a écrit : > This is an automated email from the git hooks/post-receive script. It was > generated because a ref change was pushed to the repository containing > the project "open-mpi/hwloc". > > The branch, master has been updated > via 37eb93c7dfeca1a0ce84474bac9d2f234bcbacd4 (commit) > from be52ce0ca44b36cc50b55b0ab2cf784f1a2a1c75 (commit) > > Those revisions listed above that are new to this repository have > not appeared on any other notification email; so we list those > revisions in full, below. > > - Log ----------------------------------------------------------------- > https://github.com/open-mpi/hwloc/commit/37eb93c7dfeca1a0ce84474bac9d2f234bcbacd4 > > commit 37eb93c7dfeca1a0ce84474bac9d2f234bcbacd4 > Author: Samuel Thibault <samuel.thiba...@ens-lyon.org> > Date: Tue Aug 29 18:25:36 2017 +0200 > > hwloc-ps: harmonize with lstopo --ps > > Harmonize the hwloc-ps source code for getting process name with lstopo > --ps > source code. This thus gets 11e1957 ('show only comm of processes'). > > (cherry picked from commit d801688ef7e5fbf22c7259f679d350d6f41ebea1) > > diff --git a/utils/hwloc/hwloc-ps.c b/utils/hwloc/hwloc-ps.c > index 095e8c7..c5256a9 100644 > --- a/utils/hwloc/hwloc-ps.c > +++ b/utils/hwloc/hwloc-ps.c > @@ -1,6 +1,6 @@ > /* > * Copyright © 2009-2017 Inria. All rights reserved. > - * Copyright © 2009-2012 Université Bordeaux > + * Copyright © 2009-2012, 2017 Université Bordeaux > * Copyright © 2009-2011 Cisco Systems, Inc. All rights reserved. > * See COPYING in top-level directory. > */ > @@ -116,20 +116,69 @@ static void one_process(hwloc_topology_t topology, > hwloc_const_bitmap_t topocpus > path = malloc(pathlen); > snprintf(path, pathlen, "/proc/%ld/cmdline", pid); > file = open(path, O_RDONLY); > - free(path); > + if (file < 0) { > + /* Ignore errors */ > + free(path); > + goto out; > + } > + n = read(file, name, sizeof(name) - 1); > + close(file); > > - if (file >= 0) { > - n = read(file, name, sizeof(name) - 1); > - close(file); > + if (n <= 0) { > + /* Ignore kernel threads and errors */ > + free(path); > + goto out; > + } > + > + snprintf(path, pathlen, "/proc/%ld/comm", pid); > + file = open(path, O_RDONLY); > > - if (n <= 0) > - /* Ignore kernel threads and errors */ > - goto out; > + if (file >= 0) { > + n = read(file, name, sizeof(name) - 1); > + close(file); > + if (n > 0) { > + name[n] = 0; > + if (n > 1 && name[n-1] == '\n') > + name[n-1] = 0; > + } else { > + snprintf(name, sizeof(name), "(unknown)"); > + } > + } else { > + /* Old kernel, have to look at old file */ > + char stats[32]; > + char *parenl = NULL, *parenr; > > - name[n] = 0; > + snprintf(path, pathlen, "/proc/%ld/stat", pid); > + file = open(path, O_RDONLY); > > - if (only_name && !strstr(name, only_name)) > + if (file < 0) { > + /* Ignore errors */ > + free(path); > goto out; > + } > + > + /* "pid (comm) ..." */ > + n = read(file, stats, sizeof(stats) - 1); > + close(file); > + if (n > 0) { > + stats[n] = 0; > + parenl = strchr(stats, '('); > + parenr = strchr(stats, ')'); > + if (!parenr) > + parenr = &stats[sizeof(stats)-1]; > + *parenr = 0; > + } > + if (!parenl) { > + snprintf(name, sizeof(name), "(unknown)"); > + } else { > + snprintf(name, sizeof(name), parenl+1); > + } > + } > + > + free(path); > + > + if (only_name && !strstr(name, only_name)) { > + goto out; > } > } > #endif /* HWLOC_LINUX_SYS */ > diff --git a/utils/lstopo/lstopo.c b/utils/lstopo/lstopo.c > index cb4f7dc..70c78eb 100644 > --- a/utils/lstopo/lstopo.c > +++ b/utils/lstopo/lstopo.c > @@ -217,12 +217,12 @@ static void add_process_objects(hwloc_topology_t > topology) > { > /* Get threads */ > DIR *task_dir; > - struct dirent *task_dirent; > > snprintf(path, pathlen, "/proc/%s/task", dirent->d_name); > task_dir = opendir(path); > > if (task_dir) { > + struct dirent *task_dirent; > while ((task_dirent = readdir(task_dir))) { > long local_tid; > char *task_end; > > > ----------------------------------------------------------------------- > > Summary of changes: > utils/hwloc/hwloc-ps.c | 69 > ++++++++++++++++++++++++++++++++++++++++++-------- > utils/lstopo/lstopo.c | 2 +- > 2 files changed, 60 insertions(+), 11 deletions(-) > > > hooks/post-receive _______________________________________________ hwloc-devel mailing list hwloc-devel@lists.open-mpi.org https://lists.open-mpi.org/mailman/listinfo/hwloc-devel