Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 338862
b: refs/heads/master
c: 9d2f8e2
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Oct 6, 2012
1 parent 4cfca59 commit 1c2bc09
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 41 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: 0c1fe6b2f30fa275d939071293b6e28771283f6d
refs/heads/master: 9d2f8e22fc965bcdd5561d000d234fe2d23657ba
2 changes: 2 additions & 0 deletions trunk/tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ LIB_H += util/evlist.h
LIB_H += util/exec_cmd.h
LIB_H += util/types.h
LIB_H += util/levenshtein.h
LIB_H += util/machine.h
LIB_H += util/map.h
LIB_H += util/parse-options.h
LIB_H += util/parse-events.h
Expand Down Expand Up @@ -383,6 +384,7 @@ LIB_OBJS += $(OUTPUT)util/header.o
LIB_OBJS += $(OUTPUT)util/callchain.o
LIB_OBJS += $(OUTPUT)util/values.o
LIB_OBJS += $(OUTPUT)util/debug.o
LIB_OBJS += $(OUTPUT)util/machine.o
LIB_OBJS += $(OUTPUT)util/map.o
LIB_OBJS += $(OUTPUT)util/pstack.o
LIB_OBJS += $(OUTPUT)util/session.o
Expand Down
57 changes: 57 additions & 0 deletions trunk/tools/perf/util/machine.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "machine.h"
#include "map.h"
#include "thread.h"
#include <stdbool.h>

static struct thread *__machine__findnew_thread(struct machine *machine, pid_t pid,
bool create)
{
struct rb_node **p = &machine->threads.rb_node;
struct rb_node *parent = NULL;
struct thread *th;

/*
* Font-end cache - PID lookups come in blocks,
* so most of the time we dont have to look up
* the full rbtree:
*/
if (machine->last_match && machine->last_match->pid == pid)
return machine->last_match;

while (*p != NULL) {
parent = *p;
th = rb_entry(parent, struct thread, rb_node);

if (th->pid == pid) {
machine->last_match = th;
return th;
}

if (pid < th->pid)
p = &(*p)->rb_left;
else
p = &(*p)->rb_right;
}

if (!create)
return NULL;

th = thread__new(pid);
if (th != NULL) {
rb_link_node(&th->rb_node, parent, p);
rb_insert_color(&th->rb_node, &machine->threads);
machine->last_match = th;
}

return th;
}

struct thread *machine__findnew_thread(struct machine *machine, pid_t pid)
{
return __machine__findnew_thread(machine, pid, true);
}

struct thread *machine__find_thread(struct machine *machine, pid_t pid)
{
return __machine__findnew_thread(machine, pid, false);
}
11 changes: 11 additions & 0 deletions trunk/tools/perf/util/machine.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef __PERF_MACHINE_H
#define __PERF_MACHINE_H

#include <sys/types.h>

struct thread;
struct machine;

struct thread *machine__find_thread(struct machine *machine, pid_t pid);

#endif /* __PERF_MACHINE_H */
41 changes: 1 addition & 40 deletions trunk/tools/perf/util/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "util.h"
#include "debug.h"

static struct thread *thread__new(pid_t pid)
struct thread *thread__new(pid_t pid)
{
struct thread *self = zalloc(sizeof(*self));

Expand Down Expand Up @@ -61,45 +61,6 @@ static size_t thread__fprintf(struct thread *self, FILE *fp)
map_groups__fprintf(&self->mg, verbose, fp);
}

struct thread *machine__findnew_thread(struct machine *self, pid_t pid)
{
struct rb_node **p = &self->threads.rb_node;
struct rb_node *parent = NULL;
struct thread *th;

/*
* Font-end cache - PID lookups come in blocks,
* so most of the time we dont have to look up
* the full rbtree:
*/
if (self->last_match && self->last_match->pid == pid)
return self->last_match;

while (*p != NULL) {
parent = *p;
th = rb_entry(parent, struct thread, rb_node);

if (th->pid == pid) {
self->last_match = th;
return th;
}

if (pid < th->pid)
p = &(*p)->rb_left;
else
p = &(*p)->rb_right;
}

th = thread__new(pid);
if (th != NULL) {
rb_link_node(&th->rb_node, parent, p);
rb_insert_color(&th->rb_node, &self->threads);
self->last_match = th;
}

return th;
}

void thread__insert_map(struct thread *self, struct map *map)
{
map_groups__fixup_overlappings(&self->mg, map, verbose, stderr);
Expand Down
2 changes: 2 additions & 0 deletions trunk/tools/perf/util/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <linux/rbtree.h>
#include <unistd.h>
#include <sys/types.h>
#include "symbol.h"

struct thread {
Expand All @@ -22,6 +23,7 @@ struct thread {

struct machine;

struct thread *thread__new(pid_t pid);
void thread__delete(struct thread *self);

int thread__set_comm(struct thread *self, const char *comm);
Expand Down

0 comments on commit 1c2bc09

Please sign in to comment.