blob: 299b55586502feb8fc57da0e5b452e30d9dfbe9b [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
Jiri Olsaf772abc2013-12-03 14:09:25 +010019static int _eprintf(int level, const char *fmt, va_list args)
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020020{
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020021 int ret = 0;
22
Arnaldo Carvalho de Melo6beba7a2009-10-21 17:34:06 -020023 if (verbose >= level) {
Arnaldo Carvalho de Melo044c4f8f2012-11-29 16:51:01 -030024 if (use_browser >= 1)
Namhyung Kimb56e5332012-11-15 01:47:41 +090025 ui_helpline__vshow(fmt, args);
Arnaldo Carvalho de Melof9224c52010-03-11 20:12:44 -030026 else
27 ret = vfprintf(stderr, fmt, args);
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +020028 }
29
30 return ret;
31}
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020032
Jiri Olsaf772abc2013-12-03 14:09:25 +010033int eprintf(int level, const char *fmt, ...)
34{
35 va_list args;
36 int ret;
37
38 va_start(args, fmt);
39 ret = _eprintf(level, fmt, args);
40 va_end(args);
41
42 return ret;
43}
44
45/*
46 * Overloading libtraceevent standard info print
47 * function, display with -v in perf.
48 */
49void pr_stat(const char *fmt, ...)
50{
51 va_list args;
52
53 va_start(args, fmt);
54 _eprintf(1, fmt, args);
55 va_end(args);
56 eprintf(1, "\n");
57}
58
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020059int dump_printf(const char *fmt, ...)
60{
61 va_list args;
62 int ret = 0;
63
64 if (dump_trace) {
65 va_start(args, fmt);
66 ret = vprintf(fmt, args);
67 va_end(args);
68 }
69
70 return ret;
71}
Frederic Weisbecker8f288272009-08-16 22:05:48 +020072
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020073void trace_event(union perf_event *event)
Frederic Weisbecker8f288272009-08-16 22:05:48 +020074{
75 unsigned char *raw_event = (void *)event;
76 const char *color = PERF_COLOR_BLUE;
77 int i, j;
78
79 if (!dump_trace)
80 return;
81
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020082 printf(".");
83 color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
84 event->header.size);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020085
86 for (i = 0; i < event->header.size; i++) {
87 if ((i & 15) == 0) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020088 printf(".");
89 color_fprintf(stdout, color, " %04x: ", i);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020090 }
91
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020092 color_fprintf(stdout, color, " %02x", raw_event[i]);
Frederic Weisbecker8f288272009-08-16 22:05:48 +020093
94 if (((i & 15) == 15) || i == event->header.size-1) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020095 color_fprintf(stdout, color, " ");
Frederic Weisbecker8f288272009-08-16 22:05:48 +020096 for (j = 0; j < 15-(i & 15); j++)
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020097 color_fprintf(stdout, color, " ");
Andy Isaacson84c104a2010-06-11 19:44:04 -070098 for (j = i & ~15; j <= i; j++) {
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -020099 color_fprintf(stdout, color, "%c",
100 isprint(raw_event[j]) ?
101 raw_event[j] : '.');
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200102 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200103 color_fprintf(stdout, color, "\n");
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200104 }
105 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200106 printf(".\n");
Frederic Weisbecker8f288272009-08-16 22:05:48 +0200107}