-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 234362 b: refs/heads/master c: fd78260 h: refs/heads/master v: v3
- Loading branch information
Arnaldo Carvalho de Melo
committed
Jan 24, 2011
1 parent
b8dd368
commit 4fb7e75
Showing
11 changed files
with
87 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 17ea1b70a87e28457821318341bead2b45563092 | ||
refs/heads/master: fd78260b5376173faeb17127bd63b3c99a8e8bfb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <dirent.h> | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include "thread_map.h" | ||
|
||
/* Skip "." and ".." directories */ | ||
static int filter(const struct dirent *dir) | ||
{ | ||
if (dir->d_name[0] == '.') | ||
return 0; | ||
else | ||
return 1; | ||
} | ||
|
||
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 i; | ||
|
||
sprintf(name, "/proc/%d/task", pid); | ||
items = scandir(name, &namelist, filter, NULL); | ||
if (items <= 0) | ||
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++) | ||
free(namelist[i]); | ||
free(namelist); | ||
|
||
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); | ||
} | ||
|
||
void thread_map__delete(struct thread_map *threads) | ||
{ | ||
free(threads); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef __PERF_THREAD_MAP_H | ||
#define __PERF_THREAD_MAP_H | ||
|
||
#include <sys/types.h> | ||
|
||
struct thread_map { | ||
int nr; | ||
int map[]; | ||
}; | ||
|
||
struct thread_map *thread_map__new_by_pid(pid_t pid); | ||
struct thread_map *thread_map__new_by_tid(pid_t tid); | ||
struct thread_map *thread_map__new(pid_t pid, pid_t tid); | ||
void thread_map__delete(struct thread_map *threads); | ||
#endif /* __PERF_THREAD_MAP_H */ |