debug.c 2.2 KB

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