Skip to content

Commit ecffc8a

Browse files
diandersrostedt
authored andcommitted
tracing: Add trace_total_entries() / trace_total_entries_cpu()
These two new exported functions will be used in a future patch by kdb_ftdump() to quickly skip all but the last few trace entries. Link: http://lkml.kernel.org/r/20190319171206.97107-2-dianders@chromium.org Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Douglas Anderson <dianders@chromium.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
1 parent dbfe673 commit ecffc8a

2 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎kernel/trace/trace.c‎

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,34 +3492,69 @@ static void s_stop(struct seq_file *m, void *p)
34923492
trace_event_read_unlock();
34933493
}
34943494

3495+
static void
3496+
get_total_entries_cpu(struct trace_buffer *buf, unsigned long *total,
3497+
unsigned long *entries, int cpu)
3498+
{
3499+
unsigned long count;
3500+
3501+
count = ring_buffer_entries_cpu(buf->buffer, cpu);
3502+
/*
3503+
* If this buffer has skipped entries, then we hold all
3504+
* entries for the trace and we need to ignore the
3505+
* ones before the time stamp.
3506+
*/
3507+
if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
3508+
count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
3509+
/* total is the same as the entries */
3510+
*total = count;
3511+
} else
3512+
*total = count +
3513+
ring_buffer_overrun_cpu(buf->buffer, cpu);
3514+
*entries = count;
3515+
}
3516+
34953517
static void
34963518
get_total_entries(struct trace_buffer *buf,
34973519
unsigned long *total, unsigned long *entries)
34983520
{
3499-
unsigned long count;
3521+
unsigned long t, e;
35003522
int cpu;
35013523

35023524
*total = 0;
35033525
*entries = 0;
35043526

35053527
for_each_tracing_cpu(cpu) {
3506-
count = ring_buffer_entries_cpu(buf->buffer, cpu);
3507-
/*
3508-
* If this buffer has skipped entries, then we hold all
3509-
* entries for the trace and we need to ignore the
3510-
* ones before the time stamp.
3511-
*/
3512-
if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
3513-
count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
3514-
/* total is the same as the entries */
3515-
*total += count;
3516-
} else
3517-
*total += count +
3518-
ring_buffer_overrun_cpu(buf->buffer, cpu);
3519-
*entries += count;
3528+
get_total_entries_cpu(buf, &t, &e, cpu);
3529+
*total += t;
3530+
*entries += e;
35203531
}
35213532
}
35223533

3534+
unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu)
3535+
{
3536+
unsigned long total, entries;
3537+
3538+
if (!tr)
3539+
tr = &global_trace;
3540+
3541+
get_total_entries_cpu(&tr->trace_buffer, &total, &entries, cpu);
3542+
3543+
return entries;
3544+
}
3545+
3546+
unsigned long trace_total_entries(struct trace_array *tr)
3547+
{
3548+
unsigned long total, entries;
3549+
3550+
if (!tr)
3551+
tr = &global_trace;
3552+
3553+
get_total_entries(&tr->trace_buffer, &total, &entries);
3554+
3555+
return entries;
3556+
}
3557+
35233558
static void print_lat_help_header(struct seq_file *m)
35243559
{
35253560
seq_puts(m, "# _------=> CPU# \n"

‎kernel/trace/trace.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,9 @@ void trace_init_global_iter(struct trace_iterator *iter);
721721

722722
void tracing_iter_reset(struct trace_iterator *iter, int cpu);
723723

724+
unsigned long trace_total_entries_cpu(struct trace_array *tr, int cpu);
725+
unsigned long trace_total_entries(struct trace_array *tr);
726+
724727
void trace_function(struct trace_array *tr,
725728
unsigned long ip,
726729
unsigned long parent_ip,

0 commit comments

Comments
 (0)