Skip to content

Commit

Permalink
Merge tag 'perf-core-for-mingo' of git://git.kernel.org/pub/scm/linux…
Browse files Browse the repository at this point in the history
…/kernel/git/jolsa/perf into perf/core

Pull perf/core improvements and fixes from Jiri Olsa:

  * Propagate exit status of a command line workload for
    record command (Namhyung Kim)

  * Use tid for finding thread (Namhyung Kim)

  * Clarify the output of perf sched map plus small sched
    command fixies (Dongsheng Yang)

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Ingo Molnar committed May 12, 2014
2 parents 3a497f4 + 13ce34d commit 26f2738
Show file tree
Hide file tree
Showing 13 changed files with 90 additions and 152 deletions.
2 changes: 1 addition & 1 deletion tools/perf/builtin-inject.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ static int perf_event__inject_buildid(struct perf_tool *tool,

cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;

thread = machine__findnew_thread(machine, sample->pid, sample->pid);
thread = machine__findnew_thread(machine, sample->pid, sample->tid);
if (thread == NULL) {
pr_err("problem processing %d event, skipping it.\n",
event->header.type);
Expand Down
2 changes: 1 addition & 1 deletion tools/perf/builtin-kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
struct machine *machine)
{
struct thread *thread = machine__findnew_thread(machine, sample->pid,
sample->pid);
sample->tid);

if (thread == NULL) {
pr_debug("problem processing %d event, skipping it.\n",
Expand Down
158 changes: 60 additions & 98 deletions tools/perf/builtin-record.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,6 @@
#include <sched.h>
#include <sys/mman.h>

#ifndef HAVE_ON_EXIT_SUPPORT
#ifndef ATEXIT_MAX
#define ATEXIT_MAX 32
#endif
static int __on_exit_count = 0;
typedef void (*on_exit_func_t) (int, void *);
static on_exit_func_t __on_exit_funcs[ATEXIT_MAX];
static void *__on_exit_args[ATEXIT_MAX];
static int __exitcode = 0;
static void __handle_on_exit_funcs(void);
static int on_exit(on_exit_func_t function, void *arg);
#define exit(x) (exit)(__exitcode = (x))

static int on_exit(on_exit_func_t function, void *arg)
{
if (__on_exit_count == ATEXIT_MAX)
return -ENOMEM;
else if (__on_exit_count == 0)
atexit(__handle_on_exit_funcs);
__on_exit_funcs[__on_exit_count] = function;
__on_exit_args[__on_exit_count++] = arg;
return 0;
}

static void __handle_on_exit_funcs(void)
{
int i;
for (i = 0; i < __on_exit_count; i++)
__on_exit_funcs[i] (__exitcode, __on_exit_args[i]);
}
#endif

struct record {
struct perf_tool tool;
Expand Down Expand Up @@ -147,29 +116,19 @@ static void sig_handler(int sig)
{
if (sig == SIGCHLD)
child_finished = 1;
else
signr = sig;

done = 1;
signr = sig;
}

static void record__sig_exit(int exit_status __maybe_unused, void *arg)
static void record__sig_exit(void)
{
struct record *rec = arg;
int status;

if (rec->evlist->workload.pid > 0) {
if (!child_finished)
kill(rec->evlist->workload.pid, SIGTERM);

wait(&status);
if (WIFSIGNALED(status))
psignal(WTERMSIG(status), rec->progname);
}

if (signr == -1 || signr == SIGUSR1)
if (signr == -1)
return;

signal(signr, SIG_DFL);
raise(signr);
}

static int record__open(struct record *rec)
Expand Down Expand Up @@ -243,27 +202,6 @@ static int process_buildids(struct record *rec)
size, &build_id__mark_dso_hit_ops);
}

static void record__exit(int status, void *arg)
{
struct record *rec = arg;
struct perf_data_file *file = &rec->file;

if (status != 0)
return;

if (!file->is_pipe) {
rec->session->header.data_size += rec->bytes_written;

if (!rec->no_buildid)
process_buildids(rec);
perf_session__write_header(rec->session, rec->evlist,
file->fd, true);
perf_session__delete(rec->session);
perf_evlist__delete(rec->evlist);
symbol__exit();
}
}

static void perf_event__synthesize_guest_os(struct machine *machine, void *data)
{
int err;
Expand Down Expand Up @@ -344,18 +282,19 @@ static volatile int workload_exec_errno;
* if the fork fails, since we asked by setting its
* want_signal to true.
*/
static void workload_exec_failed_signal(int signo, siginfo_t *info,
static void workload_exec_failed_signal(int signo __maybe_unused,
siginfo_t *info,
void *ucontext __maybe_unused)
{
workload_exec_errno = info->si_value.sival_int;
done = 1;
signr = signo;
child_finished = 1;
}

static int __cmd_record(struct record *rec, int argc, const char **argv)
{
int err;
int status = 0;
unsigned long waking = 0;
const bool forks = argc > 0;
struct machine *machine;
Expand All @@ -367,7 +306,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)

rec->progname = argv[0];

on_exit(record__sig_exit, rec);
atexit(record__sig_exit);
signal(SIGCHLD, sig_handler);
signal(SIGINT, sig_handler);
signal(SIGTERM, sig_handler);
Expand All @@ -388,40 +327,36 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
workload_exec_failed_signal);
if (err < 0) {
pr_err("Couldn't run the workload!\n");
status = err;
goto out_delete_session;
}
}

if (record__open(rec) != 0) {
err = -1;
goto out_delete_session;
goto out_child;
}

if (!rec->evlist->nr_groups)
perf_header__clear_feat(&session->header, HEADER_GROUP_DESC);

/*
* perf_session__delete(session) will be called at record__exit()
*/
on_exit(record__exit, rec);

if (file->is_pipe) {
err = perf_header__write_pipe(file->fd);
if (err < 0)
goto out_delete_session;
goto out_child;
} else {
err = perf_session__write_header(session, rec->evlist,
file->fd, false);
if (err < 0)
goto out_delete_session;
goto out_child;
}

if (!rec->no_buildid
&& !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) {
pr_err("Couldn't generate buildids. "
"Use --no-buildid to profile anyway.\n");
err = -1;
goto out_delete_session;
goto out_child;
}

machine = &session->machines.host;
Expand All @@ -431,7 +366,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
process_synthesized_event);
if (err < 0) {
pr_err("Couldn't synthesize attrs.\n");
goto out_delete_session;
goto out_child;
}

if (have_tracepoints(&rec->evlist->entries)) {
Expand All @@ -447,7 +382,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
process_synthesized_event);
if (err <= 0) {
pr_err("Couldn't record tracing data.\n");
goto out_delete_session;
goto out_child;
}
rec->bytes_written += err;
}
Expand Down Expand Up @@ -475,7 +410,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
err = __machine__synthesize_threads(machine, tool, &opts->target, rec->evlist->threads,
process_synthesized_event, opts->sample_address);
if (err != 0)
goto out_delete_session;
goto out_child;

if (rec->realtime_prio) {
struct sched_param param;
Expand All @@ -484,7 +419,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (sched_setscheduler(0, SCHED_FIFO, &param)) {
pr_err("Could not set realtime priority.\n");
err = -1;
goto out_delete_session;
goto out_child;
}
}

Expand Down Expand Up @@ -512,13 +447,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)

if (record__mmap_read_all(rec) < 0) {
err = -1;
goto out_delete_session;
goto out_child;
}

if (hits == rec->samples) {
if (done)
break;
err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1);
if (err < 0 && errno == EINTR)
err = 0;
waking++;
}

Expand All @@ -538,28 +475,52 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
const char *emsg = strerror_r(workload_exec_errno, msg, sizeof(msg));
pr_err("Workload failed: %s\n", emsg);
err = -1;
goto out_delete_session;
goto out_child;
}

if (quiet || signr == SIGUSR1)
return 0;
if (!quiet) {
fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);

fprintf(stderr, "[ perf record: Woken up %ld times to write data ]\n", waking);
/*
* Approximate RIP event size: 24 bytes.
*/
fprintf(stderr,
"[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n",
(double)rec->bytes_written / 1024.0 / 1024.0,
file->path,
rec->bytes_written / 24);
}

/*
* Approximate RIP event size: 24 bytes.
*/
fprintf(stderr,
"[ perf record: Captured and wrote %.3f MB %s (~%" PRIu64 " samples) ]\n",
(double)rec->bytes_written / 1024.0 / 1024.0,
file->path,
rec->bytes_written / 24);
out_child:
if (forks) {
int exit_status;

return 0;
if (!child_finished)
kill(rec->evlist->workload.pid, SIGTERM);

wait(&exit_status);

if (err < 0)
status = err;
else if (WIFEXITED(exit_status))
status = WEXITSTATUS(exit_status);
else if (WIFSIGNALED(exit_status))
signr = WTERMSIG(exit_status);
} else
status = err;

if (!err && !file->is_pipe) {
rec->session->header.data_size += rec->bytes_written;

if (!rec->no_buildid)
process_buildids(rec);
perf_session__write_header(rec->session, rec->evlist,
file->fd, true);
}

out_delete_session:
perf_session__delete(session);
return err;
return status;
}

#define BRANCH_OPT(n, m) \
Expand Down Expand Up @@ -988,6 +949,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __maybe_unused)

err = __cmd_record(&record, argc, argv);
out_symbol_exit:
perf_evlist__delete(rec->evlist);
symbol__exit();
return err;
}
38 changes: 22 additions & 16 deletions tools/perf/builtin-sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct sched_atom {
struct task_desc *wakee;
};

#define TASK_STATE_TO_CHAR_STR "RSDTtZX"
#define TASK_STATE_TO_CHAR_STR "RSDTtZXxKWP"

enum thread_state {
THREAD_SLEEPING = 0,
Expand Down Expand Up @@ -1300,17 +1300,25 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,

new_shortname = 0;
if (!sched_in->shortname[0]) {
sched_in->shortname[0] = sched->next_shortname1;
sched_in->shortname[1] = sched->next_shortname2;

if (sched->next_shortname1 < 'Z') {
sched->next_shortname1++;
if (!strcmp(thread__comm_str(sched_in), "swapper")) {
/*
* Don't allocate a letter-number for swapper:0
* as a shortname. Instead, we use '.' for it.
*/
sched_in->shortname[0] = '.';
sched_in->shortname[1] = ' ';
} else {
sched->next_shortname1='A';
if (sched->next_shortname2 < '9') {
sched->next_shortname2++;
sched_in->shortname[0] = sched->next_shortname1;
sched_in->shortname[1] = sched->next_shortname2;

if (sched->next_shortname1 < 'Z') {
sched->next_shortname1++;
} else {
sched->next_shortname2='0';
sched->next_shortname1 = 'A';
if (sched->next_shortname2 < '9')
sched->next_shortname2++;
else
sched->next_shortname2 = '0';
}
}
new_shortname = 1;
Expand All @@ -1322,12 +1330,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
else
printf("*");

if (sched->curr_thread[cpu]) {
if (sched->curr_thread[cpu]->tid)
printf("%2s ", sched->curr_thread[cpu]->shortname);
else
printf(". ");
} else
if (sched->curr_thread[cpu])
printf("%2s ", sched->curr_thread[cpu]->shortname);
else
printf(" ");
}

Expand Down Expand Up @@ -1635,6 +1640,7 @@ static int __cmd_record(int argc, const char **argv)
"-e", "sched:sched_stat_runtime",
"-e", "sched:sched_process_fork",
"-e", "sched:sched_wakeup",
"-e", "sched:sched_wakeup_new",
"-e", "sched:sched_migrate_task",
};

Expand Down
Loading

0 comments on commit 26f2738

Please sign in to comment.