All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: kan.liang@intel.com
Cc: acme@kernel.org, mingo@redhat.com, linux-kernel@vger.kernel.org,
	peterz@infradead.org, jolsa@kernel.org, wangnan0@huawei.com,
	hekuang@huawei.com, namhyung@kernel.org,
	alexander.shishkin@linux.intel.com, adrian.hunter@intel.com,
	ak@linux.intel.com
Subject: Re: [PATCH V2 4/5] perf record: synthesize event multithreading support
Date: Wed, 18 Oct 2017 17:37:59 +0200	[thread overview]
Message-ID: <20171018153759.GB512@krava> (raw)
In-Reply-To: <1508336973-383492-5-git-send-email-kan.liang@intel.com>

On Wed, Oct 18, 2017 at 07:29:32AM -0700, kan.liang@intel.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

  reply	other threads:[~2017-10-18 15:38 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-18 14:29 [PATCH V2 0/5] event synthesization multithreading for perf record kan.liang
2017-10-18 14:29 ` [PATCH V2 1/5] perf tools: pass thread info to process function kan.liang
2017-10-18 14:29 ` [PATCH V2 2/5] perf tools: pass thread info in event synthesization kan.liang
2017-10-18 14:29 ` [PATCH V2 3/5] perf tools: expose copyfile_offset() kan.liang
2017-10-18 14:29 ` [PATCH V2 4/5] perf record: synthesize event multithreading support kan.liang
2017-10-18 15:37   ` Jiri Olsa [this message]
2017-10-18 15:39   ` Jiri Olsa
2017-10-18 15:43   ` Jiri Olsa
2017-10-18 16:57     ` Liang, Kan
2017-10-18 14:29 ` [PATCH V2 5/5] perf record: add option to set the number of thread for event synthesize kan.liang
2017-10-18 17:04 ` [PATCH V2 0/5] event synthesization multithreading for perf record Ingo Molnar
2017-10-20 20:19   ` Liang, Kan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171018153759.GB512@krava \
    --to=jolsa@redhat.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.