blob: 8640a9121e726b794d35174d1cafd5d0bb7cb3d1 [file] [log] [blame]
Frederic Weisbeckercd84c2a2009-08-12 10:03:49 +02001/* For general debugging purposes */
2
3#include "../perf.h"
Frederic Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 va_end(args);
29 }
30
31 return ret;
32}
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020033
Jiri Olsaf772abc2013-12-03 14:09:25 +010034int eprintf(int level, const char *fmt, ...)
35{
36 va_list args;
37 int ret;
38
39 va_start(args, fmt);
40 ret = _eprintf(level, fmt, args);
41 va_end(args);
42
43 return ret;
44}
45
46/*
47 * Overloading libtraceevent standard info print
48 * function, display with -v in perf.
49 */
50void pr_stat(const char *fmt, ...)
51{
52 va_list args;
53
54 va_start(args, fmt);
55 _eprintf(1, fmt, args);
56 va_end(args);
57 eprintf(1, "\n");
58}
59
Frederic Weisbecker2cec19d2009-08-16 19:24:21 +020060int dump_printf(const char *fmt, ...)
61{
62 va_list args;
63 int ret = 0;
64
65 if (dump_trace) {
66 va_start(args, fmt);
67 ret = vprintf(fmt, args);
68 va_end(args);
69 }
70
71 return ret;
72}
Frederic Weisbecker8f28827a2009-08-16 22:05:48 +020073
Arnaldo Carvalho de Melo8115d602011-01-29 14:01:45 -020074void trace_event(union perf_event *event)
Frederic Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-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 Weisbecker8f28827a2009-08-16 22:05:48 +0200103 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200104 color_fprintf(stdout, color, "\n");
Frederic Weisbecker8f28827a2009-08-16 22:05:48 +0200105 }
106 }
Arnaldo Carvalho de Melo5b1c1442010-11-30 17:48:53 -0200107 printf(".\n");
Frederic Weisbecker8f28827a2009-08-16 22:05:48 +0200108}