Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 72 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 17ea1b70a87e28457821318341bead2b45563092
refs/heads/master: fd78260b5376173faeb17127bd63b3c99a8e8bfb
2 changes: 2 additions & 0 deletions trunk/tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ LIB_H += util/values.h
LIB_H += util/sort.h
LIB_H += util/hist.h
LIB_H += util/thread.h
LIB_H += util/thread_map.h
LIB_H += util/trace-event.h
LIB_H += util/probe-finder.h
LIB_H += util/probe-event.h
Expand Down Expand Up @@ -471,6 +472,7 @@ LIB_OBJS += $(OUTPUT)util/map.o
LIB_OBJS += $(OUTPUT)util/pstack.o
LIB_OBJS += $(OUTPUT)util/session.o
LIB_OBJS += $(OUTPUT)util/thread.o
LIB_OBJS += $(OUTPUT)util/thread_map.o
LIB_OBJS += $(OUTPUT)util/trace-event-parse.o
LIB_OBJS += $(OUTPUT)util/trace-event-read.o
LIB_OBJS += $(OUTPUT)util/trace-event-info.o
Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "util/session.h"
#include "util/symbol.h"
#include "util/cpumap.h"
#include "util/thread_map.h"

#include <unistd.h>
#include <sched.h>
Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/builtin-stat.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include "util/header.h"
#include "util/cpumap.h"
#include "util/thread.h"
#include "util/thread_map.h"

#include <sys/prctl.h>
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "util/parse-events.h"
#include "util/session.h"
#include "util/symbol.h"
#include "util/thread.h"
#include "util/thread_map.h"

static long page_size;

Expand Down
1 change: 1 addition & 0 deletions trunk/tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "util/session.h"
#include "util/symbol.h"
#include "util/thread.h"
#include "util/thread_map.h"
#include "util/util.h"
#include <linux/rbtree.h>
#include "util/parse-options.h"
Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/util/evsel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "../perf.h"
#include "util.h"
#include "cpumap.h"
#include "thread.h"
#include "thread_map.h"

#include <unistd.h>
#include <sys/mman.h>
Expand Down
55 changes: 0 additions & 55 deletions trunk/tools/perf/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,61 +7,6 @@
#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;
}

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);
}

static struct thread *thread__new(pid_t pid)
{
struct thread *self = zalloc(sizeof(*self));
Expand Down
14 changes: 0 additions & 14 deletions trunk/tools/perf/util/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,10 @@ struct thread {
int comm_len;
};

struct thread_map {
int nr;
int map[];
};

struct perf_session;

void thread__delete(struct thread *self);

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);

static inline void thread_map__delete(struct thread_map *threads)
{
free(threads);
}

int thread__set_comm(struct thread *self, const char *comm);
int thread__comm_len(struct thread *self);
struct thread *perf_session__findnew(struct perf_session *self, pid_t pid);
Expand Down
64 changes: 64 additions & 0 deletions trunk/tools/perf/util/thread_map.c
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);
}
15 changes: 15 additions & 0 deletions trunk/tools/perf/util/thread_map.h
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 */

0 comments on commit 4fb7e75

Please sign in to comment.