* [PATCH] perf: excluding "." and ".." directories when calculating tids. @ 2010-06-15 8:58 Gui Jianfeng 2010-06-15 9:33 ` Gui Jianfeng 0 siblings, 1 reply; 7+ messages in thread From: Gui Jianfeng @ 2010-06-15 8:58 UTC (permalink / raw) To: mingo; +Cc: linux kernel mailing list excluding "." and ".." directories when calculating tids. Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> --- tools/perf/util/thread.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1f7ecd4..4f71d1c 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -17,6 +17,8 @@ int find_all_tid(int pid, pid_t ** all_tid) sprintf(name, "/proc/%d/task", pid); items = scandir(name, &namelist, NULL, NULL); + /* Excluding "." and ".." directories! */ + items -= 2; if (items <= 0) return -ENOENT; *all_tid = malloc(sizeof(pid_t) * items); -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] perf: excluding "." and ".." directories when calculating tids. 2010-06-15 8:58 [PATCH] perf: excluding "." and ".." directories when calculating tids Gui Jianfeng @ 2010-06-15 9:33 ` Gui Jianfeng 2010-06-16 5:21 ` Gui Jianfeng 0 siblings, 1 reply; 7+ messages in thread From: Gui Jianfeng @ 2010-06-15 9:33 UTC (permalink / raw) To: mingo; +Cc: linux kernel mailing list Gui Jianfeng wrote: > excluding "." and ".." directories when calculating tids. Please ignore this one, will post an updated version. Thanks, Gui > > Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> > --- > tools/perf/util/thread.c | 2 ++ > 1 files changed, 2 insertions(+), 0 deletions(-) > > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c > index 1f7ecd4..4f71d1c 100644 > --- a/tools/perf/util/thread.c > +++ b/tools/perf/util/thread.c > @@ -17,6 +17,8 @@ int find_all_tid(int pid, pid_t ** all_tid) > > sprintf(name, "/proc/%d/task", pid); > items = scandir(name, &namelist, NULL, NULL); > + /* Excluding "." and ".." directories! */ > + items -= 2; > if (items <= 0) > return -ENOENT; > *all_tid = malloc(sizeof(pid_t) * items); ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH] perf: excluding "." and ".." directories when calculating tids. 2010-06-15 9:33 ` Gui Jianfeng @ 2010-06-16 5:21 ` Gui Jianfeng 2010-06-16 16:35 ` Adam Schrotenboer 2010-07-03 13:57 ` [tip:perf/urgent] perf tools: Fix find tids routine by excluding "." and ".." tip-bot for Gui Jianfeng 0 siblings, 2 replies; 7+ messages in thread From: Gui Jianfeng @ 2010-06-16 5:21 UTC (permalink / raw) To: mingo; +Cc: linux kernel mailing list Introduce a filter function to skip "." and ".." directories when calculating tid number. Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> --- tools/perf/util/thread.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1f7ecd4..9a448b4 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -7,6 +7,15 @@ #include "util.h" #include "debug.h" +/* Skip "." and ".." directories */ +static int filter(const struct dirent *dir) +{ + if (dir->d_name[0] == '.') + return 0; + else + return 1; +} + int find_all_tid(int pid, pid_t ** all_tid) { char name[256]; @@ -16,7 +25,7 @@ int find_all_tid(int pid, pid_t ** all_tid) int i; sprintf(name, "/proc/%d/task", pid); - items = scandir(name, &namelist, NULL, NULL); + items = scandir(name, &namelist, filter, NULL); if (items <= 0) return -ENOENT; *all_tid = malloc(sizeof(pid_t) * items); -- 1.6.5.2 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] perf: excluding "." and ".." directories when calculating tids. 2010-06-16 5:21 ` Gui Jianfeng @ 2010-06-16 16:35 ` Adam Schrotenboer 2010-06-17 3:11 ` Gui Jianfeng 2010-07-03 13:57 ` [tip:perf/urgent] perf tools: Fix find tids routine by excluding "." and ".." tip-bot for Gui Jianfeng 1 sibling, 1 reply; 7+ messages in thread From: Adam Schrotenboer @ 2010-06-16 16:35 UTC (permalink / raw) To: Gui Jianfeng; +Cc: mingo, linux kernel mailing list [-- Attachment #1: Type: text/plain, Size: 1056 bytes --] On 06/15/2010 10:21 PM, Gui Jianfeng wrote: > Introduce a filter function to skip "." and ".." directories when calculating > tid number. > > Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> > --- > tools/perf/util/thread.c | 11 ++++++++++- > 1 files changed, 10 insertions(+), 1 deletions(-) > > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c > index 1f7ecd4..9a448b4 100644 > --- a/tools/perf/util/thread.c > +++ b/tools/perf/util/thread.c > @@ -7,6 +7,15 @@ > #include "util.h" > #include "debug.h" > > +/* Skip "." and ".." directories */ > +static int filter(const struct dirent *dir) > +{ > + if (dir->d_name[0] == '.') > + return 0; > + else > + return 1; > +} > + > Is this safe? Can you _never_ have a d_name with a leading dot, like ' .hidden' ?? Maybe should if(dir->d_name[0] == '.' && (dir->d_name[1] == '\0' || (dir->d_name[1] == '.' && dir->d_name[2] == '\0'))) Admittedly I don't think it happens in the current procfs, but I'd want to be careful regardless. [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 261 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] perf: excluding "." and ".." directories when calculating tids. 2010-06-16 16:35 ` Adam Schrotenboer @ 2010-06-17 3:11 ` Gui Jianfeng 2010-06-18 14:40 ` Arnaldo Carvalho de Melo 0 siblings, 1 reply; 7+ messages in thread From: Gui Jianfeng @ 2010-06-17 3:11 UTC (permalink / raw) To: Adam Schrotenboer; +Cc: mingo, linux kernel mailing list Adam Schrotenboer wrote: > On 06/15/2010 10:21 PM, Gui Jianfeng wrote: >> Introduce a filter function to skip "." and ".." directories when calculating >> tid number. >> >> Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> >> --- >> tools/perf/util/thread.c | 11 ++++++++++- >> 1 files changed, 10 insertions(+), 1 deletions(-) >> >> diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c >> index 1f7ecd4..9a448b4 100644 >> --- a/tools/perf/util/thread.c >> +++ b/tools/perf/util/thread.c >> @@ -7,6 +7,15 @@ >> #include "util.h" >> #include "debug.h" >> >> +/* Skip "." and ".." directories */ >> +static int filter(const struct dirent *dir) >> +{ >> + if (dir->d_name[0] == '.') >> + return 0; >> + else >> + return 1; >> +} >> + >> > > Is this safe? Can you _never_ have a d_name with a leading dot, like ' > .hidden' ?? > Maybe should > if(dir->d_name[0] == '.' && (dir->d_name[1] == '\0' || (dir->d_name[1] > == '.' && dir->d_name[2] == '\0'))) > > Admittedly I don't think it happens in the current procfs, but I'd want > to be careful regardless. Actually, we only care the numeral directories. So, even if there's a ".hidden", it's fine to filter out this directory. Just keep things simple here. Thanks, Gui > > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] perf: excluding "." and ".." directories when calculating tids. 2010-06-17 3:11 ` Gui Jianfeng @ 2010-06-18 14:40 ` Arnaldo Carvalho de Melo 0 siblings, 0 replies; 7+ messages in thread From: Arnaldo Carvalho de Melo @ 2010-06-18 14:40 UTC (permalink / raw) To: Gui Jianfeng; +Cc: Adam Schrotenboer, mingo, linux kernel mailing list Em Thu, Jun 17, 2010 at 11:11:35AM +0800, Gui Jianfeng escreveu: > Adam Schrotenboer wrote: > > On 06/15/2010 10:21 PM, Gui Jianfeng wrote: > >> Introduce a filter function to skip "." and ".." directories when calculating > >> tid number. > >> > >> +/* Skip "." and ".." directories */ > >> +static int filter(const struct dirent *dir) > >> +{ > >> + if (dir->d_name[0] == '.') > >> + return 0; > >> + else > >> + return 1; > > > > Is this safe? Can you _never_ have a d_name with a leading dot, like ' > > .hidden' ?? > > Admittedly I don't think it happens in the current procfs, but I'd want > > to be careful regardless. > > Actually, we only care the numeral directories. So, even if there's a ".hidden", > it's fine to filter out this directory. Just keep things simple here. Agreed, applying to perf/core, thanks, - Arnaldo ^ permalink raw reply [flat|nested] 7+ messages in thread
* [tip:perf/urgent] perf tools: Fix find tids routine by excluding "." and ".." 2010-06-16 5:21 ` Gui Jianfeng 2010-06-16 16:35 ` Adam Schrotenboer @ 2010-07-03 13:57 ` tip-bot for Gui Jianfeng 1 sibling, 0 replies; 7+ messages in thread From: tip-bot for Gui Jianfeng @ 2010-07-03 13:57 UTC (permalink / raw) To: linux-tip-commits Cc: acme, linux-kernel, hpa, mingo, guijianfeng, tglx, mingo Commit-ID: c214909b36efec632432acdcbfacdd46a6e11370 Gitweb: http://git.kernel.org/tip/c214909b36efec632432acdcbfacdd46a6e11370 Author: Gui Jianfeng <guijianfeng@cn.fujitsu.com> AuthorDate: Wed, 16 Jun 2010 13:21:44 +0800 Committer: Arnaldo Carvalho de Melo <acme@redhat.com> CommitDate: Thu, 1 Jul 2010 14:02:38 -0300 perf tools: Fix find tids routine by excluding "." and ".." Introduce a filter function to skip "." and ".." directories when calculating tid number, otherwise tid 0 will be included in the all_tid result array. Cc: Ingo Molnar <mingo@elte.hu> LKML-Reference: <4C185F68.1020505@cn.fujitsu.com> Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> --- tools/perf/util/thread.c | 11 ++++++++++- 1 files changed, 10 insertions(+), 1 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 1f7ecd4..9a448b4 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -7,6 +7,15 @@ #include "util.h" #include "debug.h" +/* Skip "." and ".." directories */ +static int filter(const struct dirent *dir) +{ + if (dir->d_name[0] == '.') + return 0; + else + return 1; +} + int find_all_tid(int pid, pid_t ** all_tid) { char name[256]; @@ -16,7 +25,7 @@ int find_all_tid(int pid, pid_t ** all_tid) int i; sprintf(name, "/proc/%d/task", pid); - items = scandir(name, &namelist, NULL, NULL); + items = scandir(name, &namelist, filter, NULL); if (items <= 0) return -ENOENT; *all_tid = malloc(sizeof(pid_t) * items); ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-07-03 13:58 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-06-15 8:58 [PATCH] perf: excluding "." and ".." directories when calculating tids Gui Jianfeng 2010-06-15 9:33 ` Gui Jianfeng 2010-06-16 5:21 ` Gui Jianfeng 2010-06-16 16:35 ` Adam Schrotenboer 2010-06-17 3:11 ` Gui Jianfeng 2010-06-18 14:40 ` Arnaldo Carvalho de Melo 2010-07-03 13:57 ` [tip:perf/urgent] perf tools: Fix find tids routine by excluding "." and ".." tip-bot for Gui Jianfeng
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox