RE: [PATCH V2 4/5] perf record: synthesize event multithreading support

From: Liang, Kan
Date: Wed Oct 18 2017 - 12:59:21 EST


> On Wed, Oct 18, 2017 at 07:29:32AM -0700, kan.liang@xxxxxxxxx wrote:
>
> SNIP
>
> > + 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;
> > + } else {
> > + perf_set_multithreaded();
> > + for (i = 0; i < nr_thread; i++) {
> > + snprintf(name, sizeof(name), "%s.%d",
> > + SYNTHESIZED_PATH, i);
>
> hum, I think we want some uniq temp names in here..

Any suggestions for the name?
perf.tmp.X?

>
> > + 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]);
>
> also those files should be removed

Sure.
I will modify the perf_data_file__close(file, bool remove) to do it.

Thanks,
Kan