Skip to content

Commit

Permalink
Merge branch 'perf/live' into perf/core
Browse files Browse the repository at this point in the history
Conflicts:
	tools/perf/builtin-record.c

Merge reason: add the live tracing feature, resolve conflict.

Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Apr 15, 2010
2 parents f921281 + a0cccc2 commit 84b13fd
Show file tree
Hide file tree
Showing 35 changed files with 1,184 additions and 106 deletions.
68 changes: 61 additions & 7 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static unsigned int mmap_pages = 128;
static unsigned int user_freq = UINT_MAX;
static int freq = 1000;
static int output;
static int pipe_output = 0;
static const char *output_name = "perf.data";
static int group = 0;
static unsigned int realtime_prio = 0;
Expand Down Expand Up @@ -109,6 +110,11 @@ static void mmap_write_tail(struct mmap_data *md, unsigned long tail)
pc->data_tail = tail;
}

static void advance_output(size_t size)
{
bytes_written += size;
}

static void write_output(void *buf, size_t size)
{
while (size) {
Expand Down Expand Up @@ -435,10 +441,19 @@ static int process_buildids(void)

static void atexit_header(void)
{
session->header.data_size += bytes_written;
if (!pipe_output) {
session->header.data_size += bytes_written;

process_buildids();
perf_header__write(&session->header, output, true);
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");
}
}

static int __cmd_record(int argc, const char **argv)
Expand All @@ -464,7 +479,9 @@ static int __cmd_record(int argc, const char **argv)
exit(-1);
}

if (!stat(output_name, &st) && st.st_size) {
if (!strcmp(output_name, "-"))
pipe_output = 1;
else if (!stat(output_name, &st) && st.st_size) {
if (write_mode == WRITE_FORCE) {
char oldname[PATH_MAX];
snprintf(oldname, sizeof(oldname), "%s.old",
Expand All @@ -482,7 +499,10 @@ static int __cmd_record(int argc, const char **argv)
else
flags |= O_TRUNC;

output = open(output_name, flags, S_IRUSR|S_IWUSR);
if (pipe_output)
output = STDOUT_FILENO;
else
output = open(output_name, flags, S_IRUSR | S_IWUSR);
if (output < 0) {
perror("failed to create output file");
exit(-1);
Expand All @@ -496,7 +516,7 @@ static int __cmd_record(int argc, const char **argv)
}

if (!file_new) {
err = perf_header__read(&session->header, output);
err = perf_header__read(session, output);
if (err < 0)
return err;
}
Expand All @@ -522,6 +542,8 @@ static int __cmd_record(int argc, const char **argv)
}

if (!child_pid) {
if (pipe_output)
dup2(2, 1);
close(child_ready_pipe[0]);
close(go_pipe[1]);
fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
Expand Down Expand Up @@ -573,14 +595,46 @@ static int __cmd_record(int argc, const char **argv)
open_counters(cpumap[i]);
}

if (file_new) {
if (pipe_output) {
err = perf_header__write_pipe(output);
if (err < 0)
return err;
} else if (file_new) {
err = perf_header__write(&session->header, output, false);
if (err < 0)
return err;
}

post_processing_offset = lseek(output, 0, SEEK_CUR);

if (pipe_output) {
err = event__synthesize_attrs(&session->header,
process_synthesized_event,
session);
if (err < 0) {
pr_err("Couldn't synthesize attrs.\n");
return err;
}

err = event__synthesize_event_types(process_synthesized_event,
session);
if (err < 0) {
pr_err("Couldn't synthesize event_types.\n");
return err;
}

err = event__synthesize_tracing_data(output, attrs,
nr_counters,
process_synthesized_event,
session);
if (err <= 0) {
pr_err("Couldn't record tracing data.\n");
return err;
}

advance_output(err);
}

err = event__synthesize_kernel_mmap(process_synthesized_event,
session, "_text");
if (err < 0)
Expand Down
16 changes: 15 additions & 1 deletion tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,28 @@ static struct perf_event_ops event_ops = {
.fork = event__process_task,
.lost = event__process_lost,
.read = process_read_event,
.attr = event__process_attr,
.event_type = event__process_event_type,
.tracing_data = event__process_tracing_data,
.build_id = event__process_build_id,
};

extern volatile int session_done;

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

static int __cmd_report(void)
{
int ret = -EINVAL;
struct perf_session *session;
struct rb_node *next;
const char *help = "For a higher level overview, try: perf report --sort comm,dso";

signal(SIGINT, sig_handler);

session = perf_session__new(input_name, O_RDONLY, force);
if (session == NULL)
return -ENOMEM;
Expand Down Expand Up @@ -465,7 +478,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __used)
{
argc = parse_options(argc, argv, options, report_usage, 0);

setup_browser();
if (strcmp(input_name, "-") != 0)
setup_browser();

if (symbol__init() < 0)
return -1;
Expand Down
75 changes: 74 additions & 1 deletion tools/perf/builtin-trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,23 @@ static int process_sample_event(event_t *event, struct perf_session *session)
static struct perf_event_ops event_ops = {
.sample = process_sample_event,
.comm = event__process_comm,
.attr = event__process_attr,
.event_type = event__process_event_type,
.tracing_data = event__process_tracing_data,
.build_id = event__process_build_id,
};

extern volatile int session_done;

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

static int __cmd_trace(struct perf_session *session)
{
signal(SIGINT, sig_handler);

return perf_session__process_events(session, &event_ops);
}

Expand Down Expand Up @@ -548,6 +561,65 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
suffix = REPORT_SUFFIX;
}

if (!suffix && argc >= 2 && strncmp(argv[1], "-", strlen("-")) != 0) {
char *record_script_path, *report_script_path;
int live_pipe[2];
pid_t pid;

record_script_path = get_script_path(argv[1], RECORD_SUFFIX);
if (!record_script_path) {
fprintf(stderr, "record script not found\n");
return -1;
}

report_script_path = get_script_path(argv[1], REPORT_SUFFIX);
if (!report_script_path) {
fprintf(stderr, "report script not found\n");
return -1;
}

if (pipe(live_pipe) < 0) {
perror("failed to create pipe");
exit(-1);
}

pid = fork();
if (pid < 0) {
perror("failed to fork");
exit(-1);
}

if (!pid) {
dup2(live_pipe[1], 1);
close(live_pipe[0]);

__argv = malloc(5 * sizeof(const char *));
__argv[0] = "/bin/sh";
__argv[1] = record_script_path;
__argv[2] = "-o";
__argv[3] = "-";
__argv[4] = NULL;

execvp("/bin/sh", (char **)__argv);
exit(-1);
}

dup2(live_pipe[0], 0);
close(live_pipe[1]);

__argv = malloc((argc + 3) * sizeof(const char *));
__argv[0] = "/bin/sh";
__argv[1] = report_script_path;
for (i = 2; i < argc; i++)
__argv[i] = argv[i];
__argv[i++] = "-i";
__argv[i++] = "-";
__argv[i++] = NULL;

execvp("/bin/sh", (char **)__argv);
exit(-1);
}

if (suffix) {
script_path = get_script_path(argv[2], suffix);
if (!script_path) {
Expand Down Expand Up @@ -580,7 +652,8 @@ int cmd_trace(int argc, const char **argv, const char *prefix __used)
if (session == NULL)
return -ENOMEM;

if (!perf_session__has_traces(session, "record -R"))
if (strcmp(input_name, "-") &&
!perf_session__has_traces(session, "record -R"))
return -EINVAL;

if (generate_script_lang) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );

our @EXPORT = qw(
avg nsecs nsecs_secs nsecs_nsecs nsecs_usecs print_nsecs
clear_term
);

our $VERSION = '0.01';
Expand Down Expand Up @@ -55,6 +56,11 @@ sub nsecs_str {
return $str;
}

sub clear_term
{
print "\x1b[H\x1b[2J";
}

1;
__END__
=head1 NAME
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/failed-syscalls-record
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit
perf record -c 1 -f -a -M -R -e raw_syscalls:sys_exit $@
8 changes: 7 additions & 1 deletion tools/perf/scripts/perl/bin/failed-syscalls-report
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
#!/bin/bash
# description: system-wide failed syscalls
# args: [comm]
perf trace -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $1
if [ $# -gt 0 ] ; then
if ! expr match "$1" "-" ; then
comm=$1
shift
fi
fi
perf trace $@ -s ~/libexec/perf-core/scripts/perl/failed-syscalls.pl $comm
3 changes: 2 additions & 1 deletion tools/perf/scripts/perl/bin/rw-by-file-record
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_enter_write
perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_enter_write $@

8 changes: 7 additions & 1 deletion tools/perf/scripts/perl/bin/rw-by-file-report
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash
# description: r/w activity for a program, by file
# args: <comm>
perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $1
if [ $# -lt 1 ] ; then
echo "usage: rw-by-file <comm>"
exit
fi
comm=$1
shift
perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-file.pl $comm



2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/rw-by-pid-record
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write
perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/rw-by-pid-report
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# description: system-wide r/w activity
perf trace -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl
perf trace $@ -s ~/libexec/perf-core/scripts/perl/rw-by-pid.pl



2 changes: 2 additions & 0 deletions tools/perf/scripts/perl/bin/rwtop-record
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e syscalls:sys_enter_read -e syscalls:sys_exit_read -e syscalls:sys_enter_write -e syscalls:sys_exit_write $@
23 changes: 23 additions & 0 deletions tools/perf/scripts/perl/bin/rwtop-report
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash
# description: system-wide r/w top
# args: [interval]
n_args=0
for i in "$@"
do
if expr match "$i" "-" > /dev/null ; then
break
fi
n_args=$(( $n_args + 1 ))
done
if [ "$n_args" -gt 1 ] ; then
echo "usage: rwtop-report [interval]"
exit
fi
if [ "$n_args" -gt 0 ] ; then
interval=$1
shift
fi
perf trace $@ -s ~/libexec/perf-core/scripts/perl/rwtop.pl $interval



2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/wakeup-latency-record
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e sched:sched_switch -e sched:sched_wakeup
perf record -c 1 -f -a -M -R -e sched:sched_switch -e sched:sched_wakeup $@



Expand Down
2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/wakeup-latency-report
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# description: system-wide min/max/avg wakeup latency
perf trace -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl
perf trace $@ -s ~/libexec/perf-core/scripts/perl/wakeup-latency.pl



2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/workqueue-stats-record
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
perf record -c 1 -f -a -M -R -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion
perf record -c 1 -f -a -M -R -e workqueue:workqueue_creation -e workqueue:workqueue_destruction -e workqueue:workqueue_execution -e workqueue:workqueue_insertion $@
2 changes: 1 addition & 1 deletion tools/perf/scripts/perl/bin/workqueue-stats-report
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
# description: workqueue stats (ins/exe/create/destroy)
perf trace -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl
perf trace $@ -s ~/libexec/perf-core/scripts/perl/workqueue-stats.pl



Expand Down
Loading

0 comments on commit 84b13fd

Please sign in to comment.