debug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* For general debugging purposes */
  2. #include "../perf.h"
  3. #include <string.h>
  4. #include <stdarg.h>
  5. #include <stdio.h>
  6. #include "cache.h"
  7. #include "color.h"
  8. #include "event.h"
  9. #include "debug.h"
  10. #include "util.h"
  11. int verbose;
  12. bool dump_trace = false, quiet = false;
  13. int eprintf(int level, const char *fmt, ...)
  14. {
  15. va_list args;
  16. int ret = 0;
  17. if (verbose >= level) {
  18. va_start(args, fmt);
  19. if (use_browser > 0)
  20. ret = ui_helpline__show_help(fmt, args);
  21. else
  22. ret = vfprintf(stderr, fmt, args);
  23. va_end(args);
  24. }
  25. return ret;
  26. }
  27. int dump_printf(const char *fmt, ...)
  28. {
  29. va_list args;
  30. int ret = 0;
  31. if (dump_trace) {
  32. va_start(args, fmt);
  33. ret = vprintf(fmt, args);
  34. va_end(args);
  35. }
  36. return ret;
  37. }
  38. #ifdef NO_NEWT_SUPPORT
  39. void ui__warning(const char *format, ...)
  40. {
  41. va_list args;
  42. va_start(args, format);
  43. vfprintf(stderr, format, args);
  44. va_end(args);
  45. }
  46. #endif
  47. void ui__warning_paranoid(void)
  48. {
  49. ui__warning("Permission error - are you root?\n"
  50. "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
  51. " -1 - Not paranoid at all\n"
  52. " 0 - Disallow raw tracepoint access for unpriv\n"
  53. " 1 - Disallow cpu events for unpriv\n"
  54. " 2 - Disallow kernel profiling for unpriv\n");
  55. }
  56. void trace_event(union perf_event *event)
  57. {
  58. unsigned char *raw_event = (void *)event;
  59. const char *color = PERF_COLOR_BLUE;
  60. int i, j;
  61. if (!dump_trace)
  62. return;
  63. printf(".");
  64. color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
  65. event->header.size);
  66. for (i = 0; i < event->header.size; i++) {
  67. if ((i & 15) == 0) {
  68. printf(".");
  69. color_fprintf(stdout, color, " %04x: ", i);
  70. }
  71. color_fprintf(stdout, color, " %02x", raw_event[i]);
  72. if (((i & 15) == 15) || i == event->header.size-1) {
  73. color_fprintf(stdout, color, " ");
  74. for (j = 0; j < 15-(i & 15); j++)
  75. color_fprintf(stdout, color, " ");
  76. for (j = i & ~15; j <= i; j++) {
  77. color_fprintf(stdout, color, "%c",
  78. isprint(raw_event[j]) ?
  79. raw_event[j] : '.');
  80. }
  81. color_fprintf(stdout, color, "\n");
  82. }
  83. }
  84. printf(".\n");
  85. }