trace: Add ring buffer stats to measure rate of events
[pandora-kernel.git] / kernel / trace / trace.c
index e5df02c..b419070 100644 (file)
@@ -3568,6 +3568,30 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
        return cnt;
 }
 
+static ssize_t
+tracing_total_entries_read(struct file *filp, char __user *ubuf,
+                               size_t cnt, loff_t *ppos)
+{
+       struct trace_array *tr = filp->private_data;
+       char buf[64];
+       int r, cpu;
+       unsigned long size = 0, expanded_size = 0;
+
+       mutex_lock(&trace_types_lock);
+       for_each_tracing_cpu(cpu) {
+               size += tr->entries >> 10;
+               if (!ring_buffer_expanded)
+                       expanded_size += trace_buf_size >> 10;
+       }
+       if (ring_buffer_expanded)
+               r = sprintf(buf, "%lu\n", size);
+       else
+               r = sprintf(buf, "%lu (expanded: %lu)\n", size, expanded_size);
+       mutex_unlock(&trace_types_lock);
+
+       return simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
+}
+
 static ssize_t
 tracing_free_buffer_write(struct file *filp, const char __user *ubuf,
                          size_t cnt, loff_t *ppos)
@@ -3739,6 +3763,12 @@ static const struct file_operations tracing_entries_fops = {
        .llseek         = generic_file_llseek,
 };
 
+static const struct file_operations tracing_total_entries_fops = {
+       .open           = tracing_open_generic,
+       .read           = tracing_total_entries_read,
+       .llseek         = generic_file_llseek,
+};
+
 static const struct file_operations tracing_free_buffer_fops = {
        .write          = tracing_free_buffer_write,
        .release        = tracing_free_buffer_release,
@@ -4026,6 +4056,8 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
        struct trace_array *tr = &global_trace;
        struct trace_seq *s;
        unsigned long cnt;
+       unsigned long long t;
+       unsigned long usec_rem;
 
        s = kmalloc(sizeof(*s), GFP_KERNEL);
        if (!s)
@@ -4042,6 +4074,17 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
        cnt = ring_buffer_commit_overrun_cpu(tr->buffer, cpu);
        trace_seq_printf(s, "commit overrun: %ld\n", cnt);
 
+       cnt = ring_buffer_bytes_cpu(tr->buffer, cpu);
+       trace_seq_printf(s, "bytes: %ld\n", cnt);
+
+       t = ns2usecs(ring_buffer_oldest_event_ts(tr->buffer, cpu));
+       usec_rem = do_div(t, USEC_PER_SEC);
+       trace_seq_printf(s, "oldest event ts: %5llu.%06lu\n", t, usec_rem);
+
+       t = ns2usecs(ring_buffer_time_stamp(tr->buffer, cpu));
+       usec_rem = do_div(t, USEC_PER_SEC);
+       trace_seq_printf(s, "now ts: %5llu.%06lu\n", t, usec_rem);
+
        count = simple_read_from_buffer(ubuf, count, ppos, s->buffer, s->len);
 
        kfree(s);
@@ -4450,6 +4493,9 @@ static __init int tracer_init_debugfs(void)
        trace_create_file("buffer_size_kb", 0644, d_tracer,
                        &global_trace, &tracing_entries_fops);
 
+       trace_create_file("buffer_total_size_kb", 0444, d_tracer,
+                       &global_trace, &tracing_total_entries_fops);
+
        trace_create_file("free_buffer", 0644, d_tracer,
                        &global_trace, &tracing_free_buffer_fops);