[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20171018153759.GB512@krava>
Date: Wed, 18 Oct 2017 17:37:59 +0200
From: Jiri Olsa <jolsa@...hat.com>
To: kan.liang@...el.com
Cc: acme@...nel.org, mingo@...hat.com, linux-kernel@...r.kernel.org,
peterz@...radead.org, jolsa@...nel.org, wangnan0@...wei.com,
hekuang@...wei.com, namhyung@...nel.org,
alexander.shishkin@...ux.intel.com, adrian.hunter@...el.com,
ak@...ux.intel.com
Subject: Re: [PATCH V2 4/5] perf record: synthesize event multithreading
support
On Wed, Oct 18, 2017 at 07:29:32AM -0700, kan.liang@...el.com wrote:
SNIP
> +static int record__multithread_synthesize(struct record *rec,
> + struct machine *machine,
> + struct perf_tool *tool,
> + struct record_opts *opts)
> +{
> + int i, err, nr_thread = sysconf(_SC_NPROCESSORS_ONLN);
> + char name[PATH_MAX];
> + struct stat st;
> +
> + if (nr_thread <= 1)
> + return __machine__synthesize_threads(machine, tool,
> + &opts->target,
> + rec->evlist->threads,
> + process_synthesized_event,
> + opts->sample_address,
> + opts->proc_map_timeout,
> + 1);
> +
> + rec->synthesized_file = calloc(nr_thread, sizeof(struct perf_data_file));
> + if (rec->synthesized_file == NULL) {
> + pr_debug("Could not do multithread synthesize."
> + "Roll back to single thread\n");
> + nr_thread = 1;
I guess we could fail here anyway.. it'd simplify the code below ;-)
jirka
> + } else {
> + perf_set_multithreaded();
> + for (i = 0; i < nr_thread; i++) {
> + snprintf(name, sizeof(name), "%s.%d",
> + SYNTHESIZED_PATH, i);
> + rec->synthesized_file[i].path = name;
> + err = perf_data_file__open(&rec->synthesized_file[i]);
> + if (err) {
> + pr_err("Failed to open file %s\n",
> + rec->synthesized_file[i].path);
> + goto free;
> + }
> + }
> + }
> +
> + err = __machine__synthesize_threads(machine, tool, &opts->target,
> + rec->evlist->threads,
> + process_synthesized_event,
> + opts->sample_address,
> + opts->proc_map_timeout, nr_thread);
> + if (err < 0)
> + goto free;
> +
> + if (nr_thread > 1) {
> + int fd_from, fd_to;
> +
> + fd_to = rec->session->file->fd;
> + for (i = 0; i < nr_thread; i++) {
> + fd_from = rec->synthesized_file[i].fd;
> +
> + fstat(fd_from, &st);
> + if (st.st_size == 0)
> + continue;
> + err = copyfile_offset(fd_from, 0, fd_to,
> + lseek(fd_to, 0, SEEK_END),
> + st.st_size);
> + update_bytes_written(rec, st.st_size);
> + }
> + }
> +
> +free:
> + if (nr_thread > 1) {
> + for (i = 0; i < nr_thread; i++) {
> + if (rec->synthesized_file[i].fd > 0)
> + perf_data_file__close(&rec->synthesized_file[i]);
> + }
> + free(rec->synthesized_file);
> + perf_set_singlethreaded();
> + }
> +
> + return err;
> +}
SNIP
Powered by blists - more mailing lists