Re: [PATCH] perf record: mmap output file - v2

From: Ingo Molnar
Date: Tue Oct 15 2013 - 03:25:51 EST



* Namhyung Kim <namhyung@xxxxxxxxxx> wrote:

> > 3)
> >
> > The rec->bytes_at_mmap_start field feels a bit weird. If I read the code
> > correctly, in every 'perf record' invocation, rec->bytes_written starts at
> > 0 - i.e. we don't have repeat invocations of cmd_record().
>
> rec->bytes_written is updated when it writes to the output file for
> synthesizing COMM/MMAP events (this mmap output is not used at that
> time).

Btw., while looking into it, I think advance_output() needlessly
obfuscates as well:

static void advance_output(struct perf_record *rec, size_t size)
{
rec->bytes_written += size;
}

that code should just be written open coded.

So I think all this needs a few good rounds of cleanups, before we can
complicate it with a new feature. (the cleanups can be on top of the
feature, if they go in at the same time.)

> > That means that this:
> >
> > rec->bytes_at_mmap_start = st.st_size - rec->bytes_written;
> >
> > is really:
> >
> > rec->bytes_at_mmap_start = st.st_size;
> >
> > furthermore, since we don't allow appends anymore, st.st_size ought to be
> > zero as well.
> >
> > Which means that ->bytes_at_mmap_start is always zero - and could be
> > eliminated altogether.
>
> No, st_size is bigger than rec->bytes_written due to the
> perf_file_header which is written without updating rec->bytes_written.

Since all this is code that executes once during __cmd_record(), is this
all about the header writeout?

That is what confused me about the stat() call and that's messy really: we
are the ones who write the file header, we have a very good idea about how
many bytes we wrote to the file! It should be entirely unnecessary to lose
that information and then execute a system call to recover that
information...

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/