Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 304834
b: refs/heads/master
c: 5145418
h: refs/heads/master
v: v3
  • Loading branch information
Arnaldo Carvalho de Melo committed Apr 16, 2012
1 parent b075ef4 commit d3662a5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 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: 29ed6e76b4ca81103f31c8316f9e4cfcf134572f
refs/heads/master: 5145418b06fa907883ff1f62301d534a0d26ba18
65 changes: 64 additions & 1 deletion trunk/tools/perf/util/annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,50 @@ int symbol__inc_addr_samples(struct symbol *sym, struct map *map,

static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privsize)
{
struct disasm_line *dl = malloc(sizeof(*dl) + privsize);
struct disasm_line *dl = zalloc(sizeof(*dl) + privsize);

if (dl != NULL) {
dl->offset = offset;
dl->line = strdup(line);
if (dl->line == NULL)
goto out_delete;

if (offset != -1) {
char *name = dl->line, tmp;

while (isspace(name[0]))
++name;

if (name[0] == '\0')
goto out_delete;

dl->operands = name + 1;

while (dl->operands[0] != '\0' &&
!isspace(dl->operands[0]))
++dl->operands;

tmp = dl->operands[0];
dl->operands[0] = '\0';
dl->name = strdup(name);

if (dl->name == NULL)
goto out_free_line;

dl->operands[0] = tmp;

if (dl->operands[0] != '\0') {
dl->operands++;
while (isspace(dl->operands[0]))
++dl->operands;
}
}
}

return dl;

out_free_line:
free(dl->line);
out_delete:
free(dl);
return NULL;
Expand All @@ -98,6 +132,7 @@ static struct disasm_line *disasm_line__new(s64 offset, char *line, size_t privs
void disasm_line__free(struct disasm_line *dl)
{
free(dl->line);
free(dl->name);
free(dl);
}

Expand Down Expand Up @@ -591,6 +626,34 @@ void disasm__purge(struct list_head *head)
}
}

static size_t disasm_line__fprintf(struct disasm_line *dl, FILE *fp)
{
size_t printed;

if (dl->offset == -1)
return fprintf(fp, "%s\n", dl->line);

printed = fprintf(fp, "%#" PRIx64 " %s", dl->offset, dl->name);

if (dl->operands[0] != '\0') {
printed += fprintf(fp, "%.*s %s\n", 6 - (int)printed, " ",
dl->operands);
}

return printed + fprintf(fp, "\n");
}

size_t disasm__fprintf(struct list_head *head, FILE *fp)
{
struct disasm_line *pos;
size_t printed = 0;

list_for_each_entry(pos, head, node)
printed += disasm_line__fprintf(pos, fp);

return printed;
}

int symbol__tty_annotate(struct symbol *sym, struct map *map, int evidx,
bool print_lines, bool full_paths, int min_pcnt,
int max_lines)
Expand Down
3 changes: 3 additions & 0 deletions trunk/tools/perf/util/annotate.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ struct disasm_line {
struct list_head node;
s64 offset;
char *line;
char *name;
char *operands;
};

void disasm_line__free(struct disasm_line *dl);
struct disasm_line *disasm__get_next_ip_line(struct list_head *head, struct disasm_line *pos);
size_t disasm__fprintf(struct list_head *head, FILE *fp);

struct sym_hist {
u64 sum;
Expand Down

0 comments on commit d3662a5

Please sign in to comment.