Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 169648
b: refs/heads/master
c: b269876
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo authored and Ingo Molnar committed Nov 19, 2009
1 parent 4d74a38 commit 69eae08
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 32 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: 5a8e5a3065bf04b7673262fd6c46123e4b888d2b
refs/heads/master: b269876c8d57fb8c801bea1fc34b461646c5abd0
76 changes: 45 additions & 31 deletions trunk/tools/perf/builtin-top.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ static int display_weighted = -1;
* Symbols
*/

struct sym_entry_source {
struct source_line *source;
struct source_line *lines;
struct source_line **lines_tail;
pthread_mutex_t lock;
};

struct sym_entry {
struct rb_node rb_node;
struct list_head node;
Expand All @@ -117,10 +124,7 @@ struct sym_entry {
u16 name_len;
u8 origin;
struct map *map;
struct source_line *source;
struct source_line *lines;
struct source_line **lines_tail;
pthread_mutex_t source_lock;
struct sym_entry_source *src;
unsigned long count[0];
};

Expand Down Expand Up @@ -172,6 +176,7 @@ static void sig_winch_handler(int sig __used)
static void parse_source(struct sym_entry *syme)
{
struct symbol *sym;
struct sym_entry_source *source;
struct map *map;
FILE *file;
char command[PATH_MAX*2];
Expand All @@ -181,8 +186,17 @@ static void parse_source(struct sym_entry *syme)
if (!syme)
return;

if (syme->lines) {
pthread_mutex_lock(&syme->source_lock);
if (syme->src == NULL) {
syme->src = calloc(1, sizeof(*source));
if (syme->src == NULL)
return;
pthread_mutex_init(&syme->src->lock, NULL);
}

source = syme->src;

if (source->lines) {
pthread_mutex_lock(&source->lock);
goto out_assign;
}

Expand All @@ -202,8 +216,8 @@ static void parse_source(struct sym_entry *syme)
if (!file)
return;

pthread_mutex_lock(&syme->source_lock);
syme->lines_tail = &syme->lines;
pthread_mutex_lock(&source->lock);
source->lines_tail = &source->lines;
while (!feof(file)) {
struct source_line *src;
size_t dummy = 0;
Expand All @@ -223,8 +237,8 @@ static void parse_source(struct sym_entry *syme)
*c = 0;

src->next = NULL;
*syme->lines_tail = src;
syme->lines_tail = &src->next;
*source->lines_tail = src;
source->lines_tail = &src->next;

if (strlen(src->line)>8 && src->line[8] == ':') {
src->eip = strtoull(src->line, NULL, 16);
Expand All @@ -238,15 +252,15 @@ static void parse_source(struct sym_entry *syme)
pclose(file);
out_assign:
sym_filter_entry = syme;
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&source->lock);
}

static void __zero_source_counters(struct sym_entry *syme)
{
int i;
struct source_line *line;

line = syme->lines;
line = syme->src->lines;
while (line) {
for (i = 0; i < nr_counters; i++)
line->count[i] = 0;
Expand All @@ -261,13 +275,13 @@ static void record_precise_ip(struct sym_entry *syme, int counter, u64 ip)
if (syme != sym_filter_entry)
return;

if (pthread_mutex_trylock(&syme->source_lock))
if (pthread_mutex_trylock(&syme->src->lock))
return;

if (!syme->source)
if (syme->src == NULL || syme->src->source == NULL)
goto out_unlock;

for (line = syme->lines; line; line = line->next) {
for (line = syme->src->lines; line; line = line->next) {
if (line->eip == ip) {
line->count[counter]++;
break;
Expand All @@ -276,7 +290,7 @@ static void record_precise_ip(struct sym_entry *syme, int counter, u64 ip)
break;
}
out_unlock:
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&syme->src->lock);
}

static void lookup_sym_source(struct sym_entry *syme)
Expand All @@ -287,14 +301,14 @@ static void lookup_sym_source(struct sym_entry *syme)

sprintf(pattern, "<%s>:", symbol->name);

pthread_mutex_lock(&syme->source_lock);
for (line = syme->lines; line; line = line->next) {
pthread_mutex_lock(&syme->src->lock);
for (line = syme->src->lines; line; line = line->next) {
if (strstr(line->line, pattern)) {
syme->source = line;
syme->src->source = line;
break;
}
}
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&syme->src->lock);
}

static void show_lines(struct source_line *queue, int count, int total)
Expand Down Expand Up @@ -324,24 +338,24 @@ static void show_details(struct sym_entry *syme)
if (!syme)
return;

if (!syme->source)
if (!syme->src->source)
lookup_sym_source(syme);

if (!syme->source)
if (!syme->src->source)
return;

symbol = sym_entry__symbol(syme);
printf("Showing %s for %s\n", event_name(sym_counter), symbol->name);
printf(" Events Pcnt (>=%d%%)\n", sym_pcnt_filter);

pthread_mutex_lock(&syme->source_lock);
line = syme->source;
pthread_mutex_lock(&syme->src->lock);
line = syme->src->source;
while (line) {
total += line->count[sym_counter];
line = line->next;
}

line = syme->source;
line = syme->src->source;
while (line) {
float pcnt = 0.0;

Expand All @@ -366,7 +380,7 @@ static void show_details(struct sym_entry *syme)
line->count[sym_counter] = zero ? 0 : line->count[sym_counter] * 7 / 8;
line = line->next;
}
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&syme->src->lock);
if (more)
printf("%d lines not displayed, maybe increase display entries [e]\n", more);
}
Expand Down Expand Up @@ -647,10 +661,10 @@ static void prompt_symbol(struct sym_entry **target, const char *msg)

/* zero counters of active symbol */
if (syme) {
pthread_mutex_lock(&syme->source_lock);
pthread_mutex_lock(&syme->src->lock);
__zero_source_counters(syme);
*target = NULL;
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&syme->src->lock);
}

fprintf(stdout, "\n%s: ", msg);
Expand Down Expand Up @@ -826,10 +840,10 @@ static void handle_keypress(int c)
else {
struct sym_entry *syme = sym_filter_entry;

pthread_mutex_lock(&syme->source_lock);
pthread_mutex_lock(&syme->src->lock);
sym_filter_entry = NULL;
__zero_source_counters(syme);
pthread_mutex_unlock(&syme->source_lock);
pthread_mutex_unlock(&syme->src->lock);
}
break;
case 'U':
Expand Down Expand Up @@ -915,7 +929,7 @@ static int symbol_filter(struct map *map, struct symbol *sym)

syme = symbol__priv(sym);
syme->map = map;
pthread_mutex_init(&syme->source_lock, NULL);
syme->src = NULL;
if (!sym_filter_entry && sym_filter && !strcmp(name, sym_filter))
sym_filter_entry = syme;

Expand Down

0 comments on commit 69eae08

Please sign in to comment.