Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191277
b: refs/heads/master
c: 0806ebd
h: refs/heads/master
i:
  191275: 37b7ab2
v: v3
  • Loading branch information
Ingo Molnar committed May 3, 2010
1 parent 807c28b commit e70e49a
Show file tree
Hide file tree
Showing 28 changed files with 408 additions and 148 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: feef47d0cb530e8419dfa0b48141b538b89b1b1a
refs/heads/master: 0806ebd974590ab24ab357d5d87db744e56bfe13
17 changes: 2 additions & 15 deletions trunk/tools/perf/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ LIB_H += util/include/linux/rbtree.h
LIB_H += util/include/linux/string.h
LIB_H += util/include/linux/types.h
LIB_H += util/include/asm/asm-offsets.h
LIB_H += util/include/asm/bitops.h
LIB_H += util/include/asm/bug.h
LIB_H += util/include/asm/byteorder.h
LIB_H += util/include/asm/hweight.h
LIB_H += util/include/asm/swab.h
LIB_H += util/include/asm/system.h
LIB_H += util/include/asm/uaccess.h
Expand Down Expand Up @@ -435,7 +435,6 @@ LIB_OBJS += $(OUTPUT)util/path.o
LIB_OBJS += $(OUTPUT)util/rbtree.o
LIB_OBJS += $(OUTPUT)util/bitmap.o
LIB_OBJS += $(OUTPUT)util/hweight.o
LIB_OBJS += $(OUTPUT)util/find_next_bit.o
LIB_OBJS += $(OUTPUT)util/run-command.o
LIB_OBJS += $(OUTPUT)util/quote.o
LIB_OBJS += $(OUTPUT)util/strbuf.o
Expand Down Expand Up @@ -491,6 +490,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kmem.o
BUILTIN_OBJS += $(OUTPUT)builtin-lock.o
BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
BUILTIN_OBJS += $(OUTPUT)builtin-test.o
BUILTIN_OBJS += $(OUTPUT)builtin-inject.o

PERFLIBS = $(LIB_FILE)

Expand Down Expand Up @@ -948,19 +948,6 @@ $(OUTPUT)util/config.o: util/config.c $(OUTPUT)PERF-CFLAGS
$(OUTPUT)util/rbtree.o: ../../lib/rbtree.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

# some perf warning policies can't fit to lib/bitmap.c, eg: it warns about variable shadowing
# from <string.h> that comes from kernel headers wrapping.
KBITMAP_FLAGS=`echo $(ALL_CFLAGS) | sed s/-Wshadow// | sed s/-Wswitch-default// | sed s/-Wextra//`

$(OUTPUT)util/bitmap.o: ../../lib/bitmap.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(KBITMAP_FLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

$(OUTPUT)util/hweight.o: ../../lib/hweight.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

$(OUTPUT)util/find_next_bit.o: ../../lib/find_next_bit.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) -DETC_PERFCONFIG='"$(ETC_PERFCONFIG_SQ)"' $<

$(OUTPUT)util/scripting-engines/trace-event-perl.o: util/scripting-engines/trace-event-perl.c $(OUTPUT)PERF-CFLAGS
$(QUIET_CC)$(CC) -o $@ -c $(ALL_CFLAGS) $(PERL_EMBED_CCOPTS) -Wno-redundant-decls -Wno-strict-prototypes -Wno-unused-parameter -Wno-shadow $<

Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ static int __cmd_annotate(void)
int ret;
struct perf_session *session;

session = perf_session__new(input_name, O_RDONLY, force);
session = perf_session__new(input_name, O_RDONLY, force, false);
if (session == NULL)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-buildid-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int __cmd_buildid_list(void)
int err = -1;
struct perf_session *session;

session = perf_session__new(input_name, O_RDONLY, force);
session = perf_session__new(input_name, O_RDONLY, force, false);
if (session == NULL)
return -1;

Expand Down
4 changes: 2 additions & 2 deletions trunk/tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ static int __cmd_diff(void)
int ret, i;
struct perf_session *session[2];

session[0] = perf_session__new(input_old, O_RDONLY, force);
session[1] = perf_session__new(input_new, O_RDONLY, force);
session[0] = perf_session__new(input_old, O_RDONLY, force, false);
session[1] = perf_session__new(input_new, O_RDONLY, force, false);
if (session[0] == NULL || session[1] == NULL)
return -ENOMEM;

Expand Down
228 changes: 228 additions & 0 deletions trunk/tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
/*
* builtin-inject.c
*
* Builtin inject command: Examine the live mode (stdin) event stream
* and repipe it to stdout while optionally injecting additional
* events into it.
*/
#include "builtin.h"

#include "perf.h"
#include "util/session.h"
#include "util/debug.h"

#include "util/parse-options.h"

static char const *input_name = "-";
static bool inject_build_ids;

static int event__repipe(event_t *event __used,
struct perf_session *session __used)
{
uint32_t size;
void *buf = event;

size = event->header.size;

while (size) {
int ret = write(STDOUT_FILENO, buf, size);
if (ret < 0)
return -errno;

size -= ret;
buf += ret;
}

return 0;
}

static int event__repipe_mmap(event_t *self, struct perf_session *session)
{
int err;

err = event__process_mmap(self, session);
event__repipe(self, session);

return err;
}

static int event__repipe_task(event_t *self, struct perf_session *session)
{
int err;

err = event__process_task(self, session);
event__repipe(self, session);

return err;
}

static int event__repipe_tracing_data(event_t *self,
struct perf_session *session)
{
int err;

event__repipe(self, session);
err = event__process_tracing_data(self, session);

return err;
}

static int dso__read_build_id(struct dso *self)
{
if (self->has_build_id)
return 0;

if (filename__read_build_id(self->long_name, self->build_id,
sizeof(self->build_id)) > 0) {
self->has_build_id = true;
return 0;
}

return -1;
}

static int dso__inject_build_id(struct dso *self, struct perf_session *session)
{
u16 misc = PERF_RECORD_MISC_USER;
struct machine *machine;
int err;

if (dso__read_build_id(self) < 0) {
pr_debug("no build_id found for %s\n", self->long_name);
return -1;
}

machine = perf_session__find_host_machine(session);
if (machine == NULL) {
pr_err("Can't find machine for session\n");
return -1;
}

if (self->kernel)
misc = PERF_RECORD_MISC_KERNEL;

err = event__synthesize_build_id(self, misc, event__repipe,
machine, session);
if (err) {
pr_err("Can't synthesize build_id event for %s\n", self->long_name);
return -1;
}

return 0;
}

static int event__inject_buildid(event_t *event, struct perf_session *session)
{
struct addr_location al;
struct thread *thread;
u8 cpumode;

cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

thread = perf_session__findnew(session, event->ip.pid);
if (thread == NULL) {
pr_err("problem processing %d event, skipping it.\n",
event->header.type);
goto repipe;
}

thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
event->ip.pid, event->ip.ip, &al);

if (al.map != NULL) {
if (!al.map->dso->hit) {
al.map->dso->hit = 1;
if (map__load(al.map, NULL) >= 0) {
dso__inject_build_id(al.map->dso, session);
/*
* If this fails, too bad, let the other side
* account this as unresolved.
*/
} else
pr_warning("no symbols found in %s, maybe "
"install a debug package?\n",
al.map->dso->long_name);
}
}

repipe:
event__repipe(event, session);
return 0;
}

struct perf_event_ops inject_ops = {
.sample = event__repipe,
.mmap = event__repipe,
.comm = event__repipe,
.fork = event__repipe,
.exit = event__repipe,
.lost = event__repipe,
.read = event__repipe,
.throttle = event__repipe,
.unthrottle = event__repipe,
.attr = event__repipe,
.event_type = event__repipe,
.tracing_data = event__repipe,
.build_id = event__repipe,
};

extern volatile int session_done;

static void sig_handler(int sig __attribute__((__unused__)))
{
session_done = 1;
}

static int __cmd_inject(void)
{
struct perf_session *session;
int ret = -EINVAL;

signal(SIGINT, sig_handler);

if (inject_build_ids) {
inject_ops.sample = event__inject_buildid;
inject_ops.mmap = event__repipe_mmap;
inject_ops.fork = event__repipe_task;
inject_ops.tracing_data = event__repipe_tracing_data;
}

session = perf_session__new(input_name, O_RDONLY, false, true);
if (session == NULL)
return -ENOMEM;

ret = perf_session__process_events(session, &inject_ops);

perf_session__delete(session);

return ret;
}

static const char * const report_usage[] = {
"perf inject [<options>]",
NULL
};

static const struct option options[] = {
OPT_BOOLEAN('b', "inject build-ids", &inject_build_ids,
"Inject build-ids into the output stream"),
OPT_INCR('v', "verbose", &verbose,
"be more verbose (show build ids, etc)"),
OPT_END()
};

int cmd_inject(int argc, const char **argv, const char *prefix __used)
{
argc = parse_options(argc, argv, options, report_usage, 0);

/*
* Any (unrecognized) arguments left?
*/
if (argc)
usage_with_options(report_usage, options);

if (symbol__init() < 0)
return -1;

return __cmd_inject();
}
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ static void sort_result(void)
static int __cmd_kmem(void)
{
int err = -EINVAL;
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
if (session == NULL)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-lock.c
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ static struct perf_event_ops eops = {

static int read_events(void)
{
session = perf_session__new(input_name, O_RDONLY, 0);
session = perf_session__new(input_name, O_RDONLY, 0, false);
if (!session)
die("Initializing perf session failed\n");

Expand Down
24 changes: 10 additions & 14 deletions trunk/tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,13 +446,6 @@ static void atexit_header(void)

process_buildids();
perf_header__write(&session->header, output, true);
} else {
int err;

err = event__synthesize_build_ids(process_synthesized_event,
session);
if (err < 0)
pr_err("Couldn't synthesize build ids.\n");
}
}

Expand Down Expand Up @@ -555,7 +548,7 @@ static int __cmd_record(int argc, const char **argv)
}

session = perf_session__new(output_name, O_WRONLY,
write_mode == WRITE_FORCE);
write_mode == WRITE_FORCE, false);
if (session == NULL) {
pr_err("Not enough memory for reading perf file header\n");
return -1;
Expand Down Expand Up @@ -673,12 +666,15 @@ static int __cmd_record(int argc, const char **argv)
nr_counters,
process_synthesized_event,
session);
if (err <= 0) {
pr_err("Couldn't record tracing data.\n");
return err;
}

advance_output(err);
/*
* FIXME err <= 0 here actually means that there were no tracepoints
* so its not really an error, just that we don't need to synthesize
* anything.
* We really have to return this more properly and also propagate
* errors that now are calling die()
*/
if (err > 0)
advance_output(err);
}

machine = perf_session__find_host_machine(session);
Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ static int __cmd_report(void)

signal(SIGINT, sig_handler);

session = perf_session__new(input_name, O_RDONLY, force);
session = perf_session__new(input_name, O_RDONLY, force, false);
if (session == NULL)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1660,7 +1660,7 @@ static struct perf_event_ops event_ops = {
static int read_events(void)
{
int err = -EINVAL;
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
if (session == NULL)
return -ENOMEM;

Expand Down
2 changes: 1 addition & 1 deletion trunk/tools/perf/builtin-timechart.c
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ static struct perf_event_ops event_ops = {

static int __cmd_timechart(void)
{
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0);
struct perf_session *session = perf_session__new(input_name, O_RDONLY, 0, false);
int ret = -EINVAL;

if (session == NULL)
Expand Down
Loading

0 comments on commit e70e49a

Please sign in to comment.