Re: [PATCH 2/5] trace: Add ring buffer stats to measure rate ofevents

From: Steven Rostedt
Date: Fri Jul 29 2011 - 14:10:25 EST


On Tue, 2011-07-26 at 15:59 -0700, Vaibhav Nagarnaik wrote:
> The stats file under per_cpu folder provides the number of entries,
> overruns and other statistics about the CPU ring buffer. However, the
> numbers do not provide any indication of how full the ring buffer is in
> bytes compared to the overall size in bytes. Also, it is helpful to know
> the rate at which the cpu buffer is filling up.
>
> This patch adds an entry "bytes: " in printed stats for per_cpu ring
> buffer which provides the actual bytes consumed in the ring buffer. This
> field includes the number of bytes used by recorded events and the
> padding bytes added when moving the tail pointer to next page.
>
> It also adds the following time stamps:
> "head ts:" - the oldest timestamp in the ring buffer


I hate the name of "head_ts", as it really is meaningless. The head of
our ring buffer is indeed the oldest events, but other ring buffers have
head as the newest. This is an internal name that should not be used
outside of the ring buffer code itself. Maybe call it "oldest_ts", or
even more verbose (and what it actually is), "oldest_event_ts".


> "now ts:" - the timestamp at the time of reading
>
> The field "now ts" provides a consistent time snapshot to the userspace
> when being read. This is read from the same trace clock used by tracing
> event timestamps.
>
> Together, these values provide the rate at which the buffer is filling
> up, from the formula:
> bytes / (now_ts - head_ts)
>
> Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@xxxxxxxxxx>
> ---

> /**
> + * ring_buffer_head_ts - get the oldest event timestamp from the buffer
> + * @buffer: The ring buffer
> + * @cpu: The per CPU buffer to read from.
> + */
> +unsigned long ring_buffer_head_ts(struct ring_buffer *buffer, int cpu)

Hence, replace head_ts, with something else here.

Thanks,

-- Steve

> +{
> + unsigned long flags;
> + struct ring_buffer_per_cpu *cpu_buffer;
> + struct buffer_page *bpage;
> + unsigned long ret;
> +
> + if (!cpumask_test_cpu(cpu, buffer->cpumask))
> + return 0;
> +
> + cpu_buffer = buffer->buffers[cpu];
> + spin_lock_irqsave(&cpu_buffer->reader_lock, flags);
> + /*
> + * if the tail is on reader_page, oldest time stamp is on the reader
> + * page
> + */
> + if (cpu_buffer->tail_page == cpu_buffer->reader_page)
> + bpage = cpu_buffer->reader_page;
> + else
> + bpage = rb_set_head_page(cpu_buffer);
> + ret = bpage->page->time_stamp;
> + spin_unlock_irqrestore(&cpu_buffer->reader_lock, flags);
> +
> + return ret;
> +}


--
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/