Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 158262
b: refs/heads/master
c: 2cec19d
h: refs/heads/master
v: v3
  • Loading branch information
Frederic Weisbecker authored and Ingo Molnar committed Aug 16, 2009
1 parent f1315ac commit 169447c
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 52 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: 0d31b82dd5c54a0b1e1d789427abdcc180bc4602
refs/heads/master: 2cec19d9d0716f8d68f1c5a87667d0387d4d252d
40 changes: 18 additions & 22 deletions trunk/tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ static char *sort_order = default_sort_order;
static int input;
static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;

static int dump_trace = 0;
#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)


static int full_paths;

static int print_line;
Expand Down Expand Up @@ -507,14 +503,14 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

thread = threads__findnew(event->ip.pid, &threads, &last_match);

dprintf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
dump_printf("%p [%p]: PERF_EVENT (IP, %d): %d: %p\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->header.misc,
event->ip.pid,
(void *)(long)ip);

dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);

if (thread == NULL) {
fprintf(stderr, "problem processing %d event, skipping it.\n",
Expand All @@ -528,7 +524,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

dso = kernel_dso;

dprintf(" ...... dso: %s\n", dso->name);
dump_printf(" ...... dso: %s\n", dso->name);

} else if (event->header.misc & PERF_EVENT_MISC_USER) {

Expand All @@ -549,12 +545,12 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
if ((long long)ip < 0)
dso = kernel_dso;
}
dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
dump_printf(" ...... dso: %s\n", dso ? dso->name : "<not found>");

} else {
show = SHOW_HV;
level = 'H';
dprintf(" ...... dso: [hypervisor]\n");
dump_printf(" ...... dso: [hypervisor]\n");
}

if (show & show_mask) {
Expand Down Expand Up @@ -582,7 +578,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)

thread = threads__findnew(event->mmap.pid, &threads, &last_match);

dprintf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
dump_printf("%p [%p]: PERF_EVENT_MMAP %d: [%p(%p) @ %p]: %s\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->mmap.pid,
Expand All @@ -592,7 +588,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
event->mmap.filename);

if (thread == NULL || map == NULL) {
dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n");
dump_printf("problem processing PERF_EVENT_MMAP, skipping event.\n");
return 0;
}

Expand All @@ -608,14 +604,14 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)
struct thread *thread;

thread = threads__findnew(event->comm.pid, &threads, &last_match);
dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
dump_printf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->comm.comm, event->comm.pid);

if (thread == NULL ||
thread__set_comm(thread, event->comm.comm)) {
dprintf("problem processing PERF_EVENT_COMM, skipping event.\n");
dump_printf("problem processing PERF_EVENT_COMM, skipping event.\n");
return -1;
}
total_comm++;
Expand All @@ -631,13 +627,13 @@ process_fork_event(event_t *event, unsigned long offset, unsigned long head)

thread = threads__findnew(event->fork.pid, &threads, &last_match);
parent = threads__findnew(event->fork.ppid, &threads, &last_match);
dprintf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
dump_printf("%p [%p]: PERF_EVENT_FORK: %d:%d\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->fork.pid, event->fork.ppid);

if (!thread || !parent || thread__fork(thread, parent)) {
dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
dump_printf("problem processing PERF_EVENT_FORK, skipping event.\n");
return -1;
}
total_fork++;
Expand Down Expand Up @@ -1022,14 +1018,14 @@ static int __cmd_annotate(void)

size = event->header.size;

dprintf("%p [%p]: event: %d\n",
dump_printf("%p [%p]: event: %d\n",
(void *)(offset + head),
(void *)(long)event->header.size,
event->header.type);

if (!size || process_event(event, offset, head) < 0) {

dprintf("%p [%p]: skipping unknown header type: %d\n",
dump_printf("%p [%p]: skipping unknown header type: %d\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->header.type);
Expand All @@ -1055,11 +1051,11 @@ static int __cmd_annotate(void)
rc = EXIT_SUCCESS;
close(input);

dprintf(" IP events: %10ld\n", total);
dprintf(" mmap events: %10ld\n", total_mmap);
dprintf(" comm events: %10ld\n", total_comm);
dprintf(" fork events: %10ld\n", total_fork);
dprintf(" unknown events: %10ld\n", total_unknown);
dump_printf(" IP events: %10ld\n", total);
dump_printf(" mmap events: %10ld\n", total_mmap);
dump_printf(" comm events: %10ld\n", total_comm);
dump_printf(" fork events: %10ld\n", total_fork);
dump_printf(" unknown events: %10ld\n", total_unknown);

if (dump_trace)
return 0;
Expand Down
56 changes: 27 additions & 29 deletions trunk/tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ static char *field_sep;
static int input;
static int show_mask = SHOW_KERNEL | SHOW_USER | SHOW_HV;

static int dump_trace = 0;
#define dprintf(x...) do { if (dump_trace) printf(x); } while (0)
#define cdprintf(x...) do { if (dump_trace) color_fprintf(stdout, color, x); } while (0)

static int full_paths;
Expand Down Expand Up @@ -713,8 +711,8 @@ resolve_symbol(struct thread *thread, struct map **mapp,
if ((long long)ip < 0)
dso = kernel_dso;
}
dprintf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
dprintf(" ...... map: %Lx -> %Lx\n", *ipp, ip);
dump_printf(" ...... dso: %s\n", dso ? dso->name : "<not found>");
dump_printf(" ...... map: %Lx -> %Lx\n", *ipp, ip);
*ipp = ip;

if (dsop)
Expand Down Expand Up @@ -1108,7 +1106,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)
more_data += sizeof(u64);
}

dprintf("%p [%p]: PERF_EVENT_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
dump_printf("%p [%p]: PERF_EVENT_SAMPLE (IP, %d): %d/%d: %p period: %Ld\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->header.misc,
Expand All @@ -1121,7 +1119,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

chain = (void *)more_data;

dprintf("... chain: nr:%Lu\n", chain->nr);
dump_printf("... chain: nr:%Lu\n", chain->nr);

if (validate_chain(chain, event) < 0) {
eprintf("call-chain problem with event, skipping it.\n");
Expand All @@ -1130,11 +1128,11 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

if (dump_trace) {
for (i = 0; i < chain->nr; i++)
dprintf("..... %2d: %016Lx\n", i, chain->ips[i]);
dump_printf("..... %2d: %016Lx\n", i, chain->ips[i]);
}
}

dprintf(" ... thread: %s:%d\n", thread->comm, thread->pid);
dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);

if (thread == NULL) {
eprintf("problem processing %d event, skipping it.\n",
Expand All @@ -1153,7 +1151,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

dso = kernel_dso;

dprintf(" ...... dso: %s\n", dso->name);
dump_printf(" ...... dso: %s\n", dso->name);

} else if (cpumode == PERF_EVENT_MISC_USER) {

Expand All @@ -1166,7 +1164,7 @@ process_sample_event(event_t *event, unsigned long offset, unsigned long head)

dso = hypervisor_dso;

dprintf(" ...... dso: [hypervisor]\n");
dump_printf(" ...... dso: [hypervisor]\n");
}

if (show & show_mask) {
Expand Down Expand Up @@ -1197,7 +1195,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)

thread = threads__findnew(event->mmap.pid, &threads, &last_match);

dprintf("%p [%p]: PERF_EVENT_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
dump_printf("%p [%p]: PERF_EVENT_MMAP %d/%d: [%p(%p) @ %p]: %s\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->mmap.pid,
Expand All @@ -1208,7 +1206,7 @@ process_mmap_event(event_t *event, unsigned long offset, unsigned long head)
event->mmap.filename);

if (thread == NULL || map == NULL) {
dprintf("problem processing PERF_EVENT_MMAP, skipping event.\n");
dump_printf("problem processing PERF_EVENT_MMAP, skipping event.\n");
return 0;
}

Expand All @@ -1225,14 +1223,14 @@ process_comm_event(event_t *event, unsigned long offset, unsigned long head)

thread = threads__findnew(event->comm.pid, &threads, &last_match);

dprintf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
dump_printf("%p [%p]: PERF_EVENT_COMM: %s:%d\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->comm.comm, event->comm.pid);

if (thread == NULL ||
thread__set_comm(thread, event->comm.comm)) {
dprintf("problem processing PERF_EVENT_COMM, skipping event.\n");
dump_printf("problem processing PERF_EVENT_COMM, skipping event.\n");
return -1;
}
total_comm++;
Expand All @@ -1249,7 +1247,7 @@ process_task_event(event_t *event, unsigned long offset, unsigned long head)
thread = threads__findnew(event->fork.pid, &threads, &last_match);
parent = threads__findnew(event->fork.ppid, &threads, &last_match);

dprintf("%p [%p]: PERF_EVENT_%s: (%d:%d):(%d:%d)\n",
dump_printf("%p [%p]: PERF_EVENT_%s: (%d:%d):(%d:%d)\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->header.type == PERF_EVENT_FORK ? "FORK" : "EXIT",
Expand All @@ -1267,7 +1265,7 @@ process_task_event(event_t *event, unsigned long offset, unsigned long head)
return 0;

if (!thread || !parent || thread__fork(thread, parent)) {
dprintf("problem processing PERF_EVENT_FORK, skipping event.\n");
dump_printf("problem processing PERF_EVENT_FORK, skipping event.\n");
return -1;
}
total_fork++;
Expand All @@ -1278,7 +1276,7 @@ process_task_event(event_t *event, unsigned long offset, unsigned long head)
static int
process_lost_event(event_t *event, unsigned long offset, unsigned long head)
{
dprintf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n",
dump_printf("%p [%p]: PERF_EVENT_LOST: id:%Ld: lost:%Ld\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->lost.id,
Expand All @@ -1298,12 +1296,12 @@ static void trace_event(event_t *event)
if (!dump_trace)
return;

dprintf(".");
dump_printf(".");
cdprintf("\n. ... raw event: size %d bytes\n", event->header.size);

for (i = 0; i < event->header.size; i++) {
if ((i & 15) == 0) {
dprintf(".");
dump_printf(".");
cdprintf(" %04x: ", i);
}

Expand All @@ -1322,7 +1320,7 @@ static void trace_event(event_t *event)
cdprintf("\n");
}
}
dprintf(".\n");
dump_printf(".\n");
}

static struct perf_header *header;
Expand Down Expand Up @@ -1359,7 +1357,7 @@ process_read_event(event_t *event, unsigned long offset, unsigned long head)
event->read.value);
}

dprintf("%p [%p]: PERF_EVENT_READ: %d %d %s %Lu\n",
dump_printf("%p [%p]: PERF_EVENT_READ: %d %d %s %Lu\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->read.pid,
Expand Down Expand Up @@ -1540,14 +1538,14 @@ static int __cmd_report(void)

size = event->header.size;

dprintf("\n%p [%p]: event: %d\n",
dump_printf("\n%p [%p]: event: %d\n",
(void *)(offset + head),
(void *)(long)event->header.size,
event->header.type);

if (!size || process_event(event, offset, head) < 0) {

dprintf("%p [%p]: skipping unknown header type: %d\n",
dump_printf("%p [%p]: skipping unknown header type: %d\n",
(void *)(offset + head),
(void *)(long)(event->header.size),
event->header.type);
Expand Down Expand Up @@ -1577,12 +1575,12 @@ static int __cmd_report(void)
rc = EXIT_SUCCESS;
close(input);

dprintf(" IP events: %10ld\n", total);
dprintf(" mmap events: %10ld\n", total_mmap);
dprintf(" comm events: %10ld\n", total_comm);
dprintf(" fork events: %10ld\n", total_fork);
dprintf(" lost events: %10ld\n", total_lost);
dprintf(" unknown events: %10ld\n", total_unknown);
dump_printf(" IP events: %10ld\n", total);
dump_printf(" mmap events: %10ld\n", total_mmap);
dump_printf(" comm events: %10ld\n", total_comm);
dump_printf(" fork events: %10ld\n", total_fork);
dump_printf(" lost events: %10ld\n", total_lost);
dump_printf(" unknown events: %10ld\n", total_unknown);

if (dump_trace)
return 0;
Expand Down
15 changes: 15 additions & 0 deletions trunk/tools/perf/util/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <stdio.h>

int verbose = 0;
int dump_trace = 0;

int eprintf(const char *fmt, ...)
{
Expand All @@ -20,3 +21,17 @@ int eprintf(const char *fmt, ...)

return ret;
}

int dump_printf(const char *fmt, ...)
{
va_list args;
int ret = 0;

if (dump_trace) {
va_start(args, fmt);
ret = vprintf(fmt, args);
va_end(args);
}

return ret;
}
2 changes: 2 additions & 0 deletions trunk/tools/perf/util/debug.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* For debugging general purposes */

extern int verbose;
extern int dump_trace;

int eprintf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));

0 comments on commit 169447c

Please sign in to comment.