mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 14:41:27 +00:00
perf tools: Refactor all_tids to hold nr and the map
So that later, we can pass the thread_map instance instead of (thread_num, thread_map) for things like perf_evsel__open and friends, just like was done with cpu_map. Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@elte.hu> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
60d567e2d9
commit
5c98d466e4
5 changed files with 88 additions and 85 deletions
|
@ -16,35 +16,50 @@ static int filter(const struct dirent *dir)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int find_all_tid(int pid, pid_t ** all_tid)
|
||||
struct thread_map *thread_map__new_by_pid(pid_t pid)
|
||||
{
|
||||
struct thread_map *threads;
|
||||
char name[256];
|
||||
int items;
|
||||
struct dirent **namelist = NULL;
|
||||
int ret = 0;
|
||||
int i;
|
||||
|
||||
sprintf(name, "/proc/%d/task", pid);
|
||||
items = scandir(name, &namelist, filter, NULL);
|
||||
if (items <= 0)
|
||||
return -ENOENT;
|
||||
*all_tid = malloc(sizeof(pid_t) * items);
|
||||
if (!*all_tid) {
|
||||
ret = -ENOMEM;
|
||||
goto failure;
|
||||
return NULL;
|
||||
|
||||
threads = malloc(sizeof(*threads) + sizeof(pid_t) * items);
|
||||
if (threads != NULL) {
|
||||
for (i = 0; i < items; i++)
|
||||
threads->map[i] = atoi(namelist[i]->d_name);
|
||||
threads->nr = items;
|
||||
}
|
||||
|
||||
for (i = 0; i < items; i++)
|
||||
(*all_tid)[i] = atoi(namelist[i]->d_name);
|
||||
|
||||
ret = items;
|
||||
|
||||
failure:
|
||||
for (i=0; i<items; i++)
|
||||
free(namelist[i]);
|
||||
free(namelist);
|
||||
|
||||
return ret;
|
||||
return threads;
|
||||
}
|
||||
|
||||
struct thread_map *thread_map__new_by_tid(pid_t tid)
|
||||
{
|
||||
struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
|
||||
|
||||
if (threads != NULL) {
|
||||
threads->map[0] = tid;
|
||||
threads->nr = 1;
|
||||
}
|
||||
|
||||
return threads;
|
||||
}
|
||||
|
||||
struct thread_map *thread_map__new(pid_t pid, pid_t tid)
|
||||
{
|
||||
if (pid != -1)
|
||||
return thread_map__new_by_pid(pid);
|
||||
return thread_map__new_by_tid(tid);
|
||||
}
|
||||
|
||||
static struct thread *thread__new(pid_t pid)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue