Skip to content

Commit cee3ab9

Browse files
olsajiriacmel
authored andcommitted
perf tools: Add debug prints for ordered events queue
Adding some prints for ordered events queue, to help debug issues. Adding debug_ordered_events debug variable to be able to enable ordered events debug messages using: $ perf --debug ordered-events=2 report ... Also using oe pointer in perf_session__queue_event instead of chained session variable dereferencing. Signed-off-by: Jiri Olsa <jolsa@kernel.org> Acked-by: David Ahern <dsahern@gmail.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-7p3mnnopjvsp9nmk9msqcfkm@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 94786b6 commit cee3ab9

4 files changed

Lines changed: 72 additions & 2 deletions

File tree

‎tools/perf/util/debug.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
#include "util.h"
1414
#include "target.h"
1515

16+
#define NSECS_PER_SEC 1000000000ULL
17+
#define NSECS_PER_USEC 1000ULL
18+
1619
int verbose;
1720
bool dump_trace = false, quiet = false;
21+
int debug_ordered_events;
1822

1923
static int _eprintf(int level, int var, const char *fmt, va_list args)
2024
{
@@ -42,6 +46,35 @@ int eprintf(int level, int var, const char *fmt, ...)
4246
return ret;
4347
}
4448

49+
static int __eprintf_time(u64 t, const char *fmt, va_list args)
50+
{
51+
int ret = 0;
52+
u64 secs, usecs, nsecs = t;
53+
54+
secs = nsecs / NSECS_PER_SEC;
55+
nsecs -= secs * NSECS_PER_SEC;
56+
usecs = nsecs / NSECS_PER_USEC;
57+
58+
ret = fprintf(stderr, "[%13" PRIu64 ".%06" PRIu64 "] ",
59+
secs, usecs);
60+
ret += vfprintf(stderr, fmt, args);
61+
return ret;
62+
}
63+
64+
int eprintf_time(int level, int var, u64 t, const char *fmt, ...)
65+
{
66+
int ret = 0;
67+
va_list args;
68+
69+
if (var >= level) {
70+
va_start(args, fmt);
71+
ret = __eprintf_time(t, fmt, args);
72+
va_end(args);
73+
}
74+
75+
return ret;
76+
}
77+
4578
/*
4679
* Overloading libtraceevent standard info print
4780
* function, display with -v in perf.
@@ -110,7 +143,8 @@ static struct debug_variable {
110143
const char *name;
111144
int *ptr;
112145
} debug_variables[] = {
113-
{ .name = "verbose", .ptr = &verbose },
146+
{ .name = "verbose", .ptr = &verbose },
147+
{ .name = "ordered-events", .ptr = &debug_ordered_events},
114148
{ .name = NULL, }
115149
};
116150

‎tools/perf/util/debug.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
extern int verbose;
1212
extern bool quiet, dump_trace;
13+
extern int debug_ordered_events;
1314

1415
#ifndef pr_fmt
1516
#define pr_fmt(fmt) fmt
@@ -29,6 +30,12 @@ extern bool quiet, dump_trace;
2930
#define pr_debug3(fmt, ...) pr_debugN(3, pr_fmt(fmt), ##__VA_ARGS__)
3031
#define pr_debug4(fmt, ...) pr_debugN(4, pr_fmt(fmt), ##__VA_ARGS__)
3132

33+
#define pr_time_N(n, var, t, fmt, ...) \
34+
eprintf_time(n, var, t, fmt, ##__VA_ARGS__)
35+
36+
#define pr_oe_time(t, fmt, ...) pr_time_N(1, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
37+
#define pr_oe_time2(t, fmt, ...) pr_time_N(2, debug_ordered_events, t, pr_fmt(fmt), ##__VA_ARGS__)
38+
3239
int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
3340
void trace_event(union perf_event *event);
3441

@@ -38,6 +45,7 @@ int ui__warning(const char *format, ...) __attribute__((format(printf, 1, 2)));
3845
void pr_stat(const char *fmt, ...);
3946

4047
int eprintf(int level, int var, const char *fmt, ...) __attribute__((format(printf, 3, 4)));
48+
int eprintf_time(int level, int var, u64 t, const char *fmt, ...) __attribute__((format(printf, 4, 5)));
4149

4250
int perf_debug_option(const char *str);
4351

‎tools/perf/util/ordered-events.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#include <linux/list.h>
2+
#include <linux/compiler.h>
23
#include "ordered-events.h"
34
#include "evlist.h"
45
#include "session.h"
56
#include "asm/bug.h"
67
#include "debug.h"
78

9+
#define pr_N(n, fmt, ...) \
10+
eprintf(n, debug_ordered_events, fmt, ##__VA_ARGS__)
11+
12+
#define pr(fmt, ...) pr_N(1, pr_fmt(fmt), ##__VA_ARGS__)
13+
814
static void queue_event(struct ordered_events *oe, struct ordered_event *new)
915
{
1016
struct ordered_event *last = oe->last;
@@ -14,6 +20,8 @@ static void queue_event(struct ordered_events *oe, struct ordered_event *new)
1420
++oe->nr_events;
1521
oe->last = new;
1622

23+
pr_oe_time2(timestamp, "queue_event nr_events %u\n", oe->nr_events);
24+
1725
if (!last) {
1826
list_add(&new->list, &oe->events);
1927
oe->max_timestamp = timestamp;
@@ -69,12 +77,17 @@ static struct ordered_event *alloc_event(struct ordered_events *oe)
6977
if (!oe->buffer)
7078
return NULL;
7179

80+
pr("alloc size %" PRIu64 "B (+%zu), max %" PRIu64 "B\n",
81+
oe->cur_alloc_size, size, oe->max_alloc_size);
82+
7283
oe->cur_alloc_size += size;
7384
list_add(&oe->buffer->list, &oe->to_free);
7485

7586
/* First entry is abused to maintain the to_free list. */
7687
oe->buffer_idx = 2;
7788
new = oe->buffer + 1;
89+
} else {
90+
pr("allocation limit reached %" PRIu64 "B\n", oe->max_alloc_size);
7891
}
7992

8093
return new;
@@ -155,6 +168,11 @@ int ordered_events__flush(struct perf_session *s, struct perf_tool *tool,
155168
enum oe_flush how)
156169
{
157170
struct ordered_events *oe = &s->ordered_events;
171+
static const char * const str[] = {
172+
"FINAL",
173+
"ROUND",
174+
"HALF ",
175+
};
158176
int err;
159177

160178
switch (how) {
@@ -184,13 +202,21 @@ int ordered_events__flush(struct perf_session *s, struct perf_tool *tool,
184202
break;
185203
};
186204

205+
pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush PRE %s, nr_events %u\n",
206+
str[how], oe->nr_events);
207+
pr_oe_time(oe->max_timestamp, "max_timestamp\n");
208+
187209
err = __ordered_events__flush(s, tool);
188210

189211
if (!err) {
190212
if (how == OE_FLUSH__ROUND)
191213
oe->next_flush = oe->max_timestamp;
192214
}
193215

216+
pr_oe_time(oe->next_flush, "next_flush - ordered_events__flush POST %s, nr_events %u\n",
217+
str[how], oe->nr_events);
218+
pr_oe_time(oe->last_flush, "last_flush\n");
219+
194220
return err;
195221
}
196222

‎tools/perf/util/session.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,10 @@ int perf_session_queue_event(struct perf_session *s, union perf_event *event,
499499
if (!timestamp || timestamp == ~0ULL)
500500
return -ETIME;
501501

502-
if (timestamp < s->ordered_events.last_flush) {
502+
if (timestamp < oe->last_flush) {
503503
printf("Warning: Timestamp below last timeslice flush\n");
504+
pr_oe_time(timestamp, "out of order event");
505+
pr_oe_time(oe->last_flush, "last flush");
504506
return -EINVAL;
505507
}
506508

0 commit comments

Comments
 (0)