blob: 66eb3828ceb5ec4b2df31147274cc767be09856a [file] [log] [blame]
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02001/* For general debugging purposes */
2
3#include "../perf.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +02004
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02005#include <string.h>
6#include <stdarg.h>
7#include <stdio.h>
8
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -03009#include "cache.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +020010#include "color.h"
11#include "event.h"
12#include "debug.h"
Arnaldo Carvalho de Melo4a58e612009-12-27 21:37:00 -020013#include "util.h"
Namhyung Kim16ad2ff2012-05-07 14:09:02 +090014#include "target.h"
Frederic Weisbecker8f288272009-08-16 22:05:48 +020015
Arnaldo Carvalho de Melob44308f2010-10-26 15:20:09 -020016int verbose;
17bool dump_trace = false, quiet = false;
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020018
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020019int eprintf(int level, const char *fmt, ...)
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020020{
21 va_list args;
22 int ret = 0;
23
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020024 if (verbose >= level) {
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020025 va_start(args, fmt);
Namhyung Kim0985a942012-08-16 17:14:54 +090026 if (use_browser == 1)
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -030027 ret = ui_helpline__show_help(fmt, args);
Namhyung Kim0985a942012-08-16 17:14:54 +090028 else if (use_browser == 2)
29 ret = perf_gtk__show_helpline(fmt, args);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030030 else
31 ret = vfprintf(stderr, fmt, args);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020032 va_end(args);
33 }
34
35 return ret;
36}
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020037
38int dump_printf(const char *fmt, ...)
39{
40 va_list args;
41 int ret = 0;
42
43 if (dump_trace) {
44 va_start(args, fmt);
45 ret = vprintf(fmt, args);
46 va_end(args);
47 }
48
49 return ret;
50}
Frederic Weisbecker8f288272009-08-16 22:05:48 +020051
Namhyung Kimba47a142012-05-29 13:22:58 +090052#if defined(NO_NEWT_SUPPORT) && defined(NO_GTK2_SUPPORT)
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020053int ui__warning(const char *format, ...)
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020054{
55 va_list args;
56
57 va_start(args, format);
58 vfprintf(stderr, format, args);
59 va_end(args);
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020060 return 0;
Arnaldo Carvalho de Melo068ffaa2010-11-27 02:41:01 -020061}
62#endif
63
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020064int ui__error_paranoid(void)
Arnaldo Carvalho de Meloc286c412011-03-28 09:50:11 -030065{
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020066 return ui__error("Permission error - are you root?\n"
Arnaldo Carvalho de Meloc286c412011-03-28 09:50:11 -030067 "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
68 " -1 - Not paranoid at all\n"
69 " 0 - Disallow raw tracepoint access for unpriv\n"
70 " 1 - Disallow cpu events for unpriv\n"
71 " 2 - Disallow kernel profiling for unpriv\n");
72}
73
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020074void trace_event(union perf_event *event)
Frederic Weisbecker8f288272009-08-16 22:05:48 +020075{
76 unsigned char *raw_event = (void *)event;
77 const char *color = PERF_COLOR_BLUE;
78 int i, j;
79
80 if (!dump_trace)
81 return;
82
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020083 printf(".");
84 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
85 event->header.size);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020086
87 for (i = 0; i < event->header.size; i++) {
88 if ((i & 15) == 0) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020089 printf(".");
90 color_fprintf(stdout, color, " %04x: ", i);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020091 }
92
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020093 color_fprintf(stdout, color, " %02x", raw_event[i]);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020094
95 if (((i & 15) == 15) || i == event->header.size-1) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020096 color_fprintf(stdout, color, " ");
Frederic Weisbecker8f288272009-08-16 22:05:48 +020097 for (j = 0; j < 15-(i & 15); j++)
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020098 color_fprintf(stdout, color, " ");
Andy Isaacson84c104a2010-06-11 19:44:04 -070099 for (j = i & ~15; j <= i; j++) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200100 color_fprintf(stdout, color, "%c",
101 isprint(raw_event[j]) ?
102 raw_event[j] : '.');
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200103 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200104 color_fprintf(stdout, color, "\n");
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200105 }
106 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200107 printf(".\n");
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200108}