All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
	paulus@samba.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf, tool, record: Fix the header generation for pipe
Date: Mon, 22 Aug 2011 16:52:10 +0200	[thread overview]
Message-ID: <20110822145210.GA8694@jolsa.brq.redhat.com> (raw)
In-Reply-To: <1314023913.2307.63.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC>

On Mon, Aug 22, 2011 at 04:38:33PM +0200, Eric Dumazet wrote:
> Le lundi 22 août 2011 à 16:23 +0200, Jiri Olsa a écrit :
> > The generation of the perf data file fails when using pipe
> > as the output file descriptor.
> > 
> > When record command generates the data header, several files are put
> > inside and the file size is stored ahead of the file contents itself.
> > 
> > The problem is that debugfs files cannot be stat-ed for size so we
> > need to read the whole file, count the size and update the file size
> > via seek&write (pwrite call).
> > This cannot be done for pipes, since it's not allowed to seek on it.
> > 
> > The attached patch changes current behaviour for pipes to get the
> > file size first and write correct data within the first pass.
> > For other than pipe files, the current behaviour stands.
> > 
> > This issue was caught when running the script command:
> > 
> > 	# perf script  syscall-counts ls
> > 
> > since it connects record and report via pipe.
> > 
> > Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> > ---
> >  tools/perf/util/trace-event-info.c |   81 +++++++++++++++++++++++++++++++-----
> >  1 files changed, 70 insertions(+), 11 deletions(-)
> > 
> > diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
> > index 3403f81..62ab9a2 100644
> > --- a/tools/perf/util/trace-event-info.c
> > +++ b/tools/perf/util/trace-event-info.c
> > @@ -59,6 +59,7 @@ unsigned int page_size;
> >  
> >  static const char *output_file = "trace.info";
> >  static int output_fd;
> > +static int output_is_pipe;
> >  
> >  struct event_list {
> >  	struct event_list *next;
> > @@ -183,20 +184,59 @@ int bigendian(void)
> >  	return *ptr == 0x01020304;
> >  }
> >  
> > +static off_t get_file_size(int fd)
> > +{
> > +	off_t size = 0;
> > +	char buf[BUFSIZ];
> > +	int r;
> > +
> > +	do {
> > +		r = read(fd, buf, BUFSIZ);
> > +		if (r > 0)
> > +			size += r;
> > +	} while (r > 0);
> > +
> > +	if (lseek(fd, 0, SEEK_SET))
> > +		die("seek failed");
> > +
> > +	return size;
> > +}
> 
> This part makes no sense :
> 
> If fd is a pipe, you'll call die("seek failed")
> 
> If it's not a pipe, you can try lseek(fd, 0, SEEK_END)+lseek(fd, 0,
> SEEK_SET) or fstat(fd, &st) instead of the read() loop.

- fd is always file.. the descriptor, which might be pipe, is in output_fd variable
  but, maybe the die call is not necessary.. this should not fail

- the record_file function is called only on debugfs or procfs files:
	events/header_page
	events/header_event
	events/**/format
	printk_formats
	/proc/kallsyms

so I think I need to read the whole file as in current code.

thanks,
jirka

  reply	other threads:[~2011-08-22 14:52 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-22 14:23 [PATCH] perf, tool, record: Fix the header generation for pipe Jiri Olsa
2011-08-22 14:38 ` Eric Dumazet
2011-08-22 14:52   ` Jiri Olsa [this message]
2011-08-22 15:51     ` Eric Dumazet
2011-08-22 16:07       ` Jiri Olsa
2011-08-29 13:20         ` Arnaldo Carvalho de Melo
2011-08-29 13:41           ` Jiri Olsa
2011-08-29 14:25             ` Arnaldo Carvalho de Melo
2011-09-14 13:58               ` [PATCH] perf tools: Fix tracing info recording Jiri Olsa
2011-09-14 15:44                 ` Neil Horman
2011-09-21 15:30                 ` Frederic Weisbecker
2011-09-25 13:34                   ` Jiri Olsa
2011-09-26  9:11                     ` [PATCHv2 1/2] " Jiri Olsa
2011-09-26  9:11                       ` [PATCHv2 1/2] perf tools: Collect tracing event data files directly Jiri Olsa
2011-09-26 13:36                         ` Steven Rostedt
2011-09-26 14:56                           ` Jiri Olsa
2011-09-28 13:55                             ` Frederic Weisbecker
2011-09-28 14:03                               ` Steven Rostedt
2011-09-28 14:17                                 ` Frederic Weisbecker
2011-09-28 14:23                                   ` Steven Rostedt
2011-09-28 16:56                                   ` Ingo Molnar
2011-09-28 17:10                                     ` Steven Rostedt
2011-10-10  5:22                                       ` Ingo Molnar
2011-10-10 12:27                                         ` Steven Rostedt
2011-10-10 14:21                                           ` Frederic Weisbecker
2011-09-26 13:43                         ` David Ahern
2011-09-26 14:58                           ` Jiri Olsa
2011-09-26  9:11                       ` [PATCHv2 2/2] perf tools: Fix tracing info recording Jiri Olsa
2011-09-29 15:05                       ` [PATCHv3 0/2] " Jiri Olsa
2011-09-29 15:05                         ` [PATCHv3 1/2] perf tools: Fix raw sample reading Jiri Olsa
2011-09-29 15:34                           ` David Ahern
2011-09-29 15:05                         ` [PATCHv3 2/2] perf tools: Fix tracing info recording Jiri Olsa
2011-10-13 14:00                           ` Jiri Olsa
2011-10-20 13:59                             ` [PATCHv4] " Jiri Olsa
2011-10-20 21:28                               ` Arnaldo Carvalho de Melo

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=20110822145210.GA8694@jolsa.brq.redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    /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.