Skip to content

Commit fd78260

Browse files
committed
perf threads: Move thread_map to separate file
To untangle it from struct thread handling, that is tied to symbols, etc. Right now in the python bindings I'm working on I need just a subset of the util/ files, untangling it allows me to do that. 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>
1 parent 17ea1b7 commit fd78260

10 files changed

Lines changed: 86 additions & 71 deletions

File tree

‎tools/perf/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ LIB_H += util/values.h
426426
LIB_H += util/sort.h
427427
LIB_H += util/hist.h
428428
LIB_H += util/thread.h
429+
LIB_H += util/thread_map.h
429430
LIB_H += util/trace-event.h
430431
LIB_H += util/probe-finder.h
431432
LIB_H += util/probe-event.h
@@ -471,6 +472,7 @@ LIB_OBJS += $(OUTPUT)util/map.o
471472
LIB_OBJS += $(OUTPUT)util/pstack.o
472473
LIB_OBJS += $(OUTPUT)util/session.o
473474
LIB_OBJS += $(OUTPUT)util/thread.o
475+
LIB_OBJS += $(OUTPUT)util/thread_map.o
474476
LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
475477
LIB_OBJS += $(OUTPUT)util/trace-event-read.o
476478
LIB_OBJS += $(OUTPUT)util/trace-event-info.o

‎tools/perf/builtin-record.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "util/session.h"
2525
#include "util/symbol.h"
2626
#include "util/cpumap.h"
27+
#include "util/thread_map.h"
2728

2829
#include <unistd.h>
2930
#include <sched.h>

‎tools/perf/builtin-stat.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "util/header.h"
5050
#include "util/cpumap.h"
5151
#include "util/thread.h"
52+
#include "util/thread_map.h"
5253

5354
#include <sys/prctl.h>
5455
#include <math.h>

‎tools/perf/builtin-test.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "util/parse-events.h"
1313
#include "util/session.h"
1414
#include "util/symbol.h"
15-
#include "util/thread.h"
15+
#include "util/thread_map.h"
1616

1717
static long page_size;
1818

‎tools/perf/builtin-top.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "util/session.h"
2727
#include "util/symbol.h"
2828
#include "util/thread.h"
29+
#include "util/thread_map.h"
2930
#include "util/util.h"
3031
#include <linux/rbtree.h>
3132
#include "util/parse-options.h"

‎tools/perf/util/evsel.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "../perf.h"
44
#include "util.h"
55
#include "cpumap.h"
6-
#include "thread.h"
6+
#include "thread_map.h"
77

88
#include <unistd.h>
99
#include <sys/mman.h>

‎tools/perf/util/thread.c‎

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,6 @@
77
#include "util.h"
88
#include "debug.h"
99

10-
/* Skip "." and ".." directories */
11-
static int filter(const struct dirent *dir)
12-
{
13-
if (dir->d_name[0] == '.')
14-
return 0;
15-
else
16-
return 1;
17-
}
18-
19-
struct thread_map *thread_map__new_by_pid(pid_t pid)
20-
{
21-
struct thread_map *threads;
22-
char name[256];
23-
int items;
24-
struct dirent **namelist = NULL;
25-
int i;
26-
27-
sprintf(name, "/proc/%d/task", pid);
28-
items = scandir(name, &namelist, filter, NULL);
29-
if (items <= 0)
30-
return NULL;
31-
32-
threads = malloc(sizeof(*threads) + sizeof(pid_t) * items);
33-
if (threads != NULL) {
34-
for (i = 0; i < items; i++)
35-
threads->map[i] = atoi(namelist[i]->d_name);
36-
threads->nr = items;
37-
}
38-
39-
for (i=0; i<items; i++)
40-
free(namelist[i]);
41-
free(namelist);
42-
43-
return threads;
44-
}
45-
46-
struct thread_map *thread_map__new_by_tid(pid_t tid)
47-
{
48-
struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
49-
50-
if (threads != NULL) {
51-
threads->map[0] = tid;
52-
threads->nr = 1;
53-
}
54-
55-
return threads;
56-
}
57-
58-
struct thread_map *thread_map__new(pid_t pid, pid_t tid)
59-
{
60-
if (pid != -1)
61-
return thread_map__new_by_pid(pid);
62-
return thread_map__new_by_tid(tid);
63-
}
64-
6510
static struct thread *thread__new(pid_t pid)
6611
{
6712
struct thread *self = zalloc(sizeof(*self));

‎tools/perf/util/thread.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,10 @@ struct thread {
1818
int comm_len;
1919
};
2020

21-
struct thread_map {
22-
int nr;
23-
int map[];
24-
};
25-
2621
struct perf_session;
2722

2823
void thread__delete(struct thread *self);
2924

30-
struct thread_map *thread_map__new_by_pid(pid_t pid);
31-
struct thread_map *thread_map__new_by_tid(pid_t tid);
32-
struct thread_map *thread_map__new(pid_t pid, pid_t tid);
33-
34-
static inline void thread_map__delete(struct thread_map *threads)
35-
{
36-
free(threads);
37-
}
38-
3925
int thread__set_comm(struct thread *self, const char *comm);
4026
int thread__comm_len(struct thread *self);
4127
struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);

‎tools/perf/util/thread_map.c‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <dirent.h>
2+
#include <stdlib.h>
3+
#include <stdio.h>
4+
#include "thread_map.h"
5+
6+
/* Skip "." and ".." directories */
7+
static int filter(const struct dirent *dir)
8+
{
9+
if (dir->d_name[0] == '.')
10+
return 0;
11+
else
12+
return 1;
13+
}
14+
15+
struct thread_map *thread_map__new_by_pid(pid_t pid)
16+
{
17+
struct thread_map *threads;
18+
char name[256];
19+
int items;
20+
struct dirent **namelist = NULL;
21+
int i;
22+
23+
sprintf(name, "/proc/%d/task", pid);
24+
items = scandir(name, &namelist, filter, NULL);
25+
if (items <= 0)
26+
return NULL;
27+
28+
threads = malloc(sizeof(*threads) + sizeof(pid_t) * items);
29+
if (threads != NULL) {
30+
for (i = 0; i < items; i++)
31+
threads->map[i] = atoi(namelist[i]->d_name);
32+
threads->nr = items;
33+
}
34+
35+
for (i=0; i<items; i++)
36+
free(namelist[i]);
37+
free(namelist);
38+
39+
return threads;
40+
}
41+
42+
struct thread_map *thread_map__new_by_tid(pid_t tid)
43+
{
44+
struct thread_map *threads = malloc(sizeof(*threads) + sizeof(pid_t));
45+
46+
if (threads != NULL) {
47+
threads->map[0] = tid;
48+
threads->nr = 1;
49+
}
50+
51+
return threads;
52+
}
53+
54+
struct thread_map *thread_map__new(pid_t pid, pid_t tid)
55+
{
56+
if (pid != -1)
57+
return thread_map__new_by_pid(pid);
58+
return thread_map__new_by_tid(tid);
59+
}
60+
61+
void thread_map__delete(struct thread_map *threads)
62+
{
63+
free(threads);
64+
}

‎tools/perf/util/thread_map.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef __PERF_THREAD_MAP_H
2+
#define __PERF_THREAD_MAP_H
3+
4+
#include <sys/types.h>
5+
6+
struct thread_map {
7+
int nr;
8+
int map[];
9+
};
10+
11+
struct thread_map *thread_map__new_by_pid(pid_t pid);
12+
struct thread_map *thread_map__new_by_tid(pid_t tid);
13+
struct thread_map *thread_map__new(pid_t pid, pid_t tid);
14+
void thread_map__delete(struct thread_map *threads);
15+
#endif /* __PERF_THREAD_MAP_H */

0 commit comments

Comments
 (0)