debug.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. int 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. return 0;
  46. }
  47. #endif
  48. int ui__error_paranoid(void)
  49. {
  50. return ui__error("Permission error - are you root?\n"
  51. "Consider tweaking /proc/sys/kernel/perf_event_paranoid:\n"
  52. " -1 - Not paranoid at all\n"
  53. " 0 - Disallow raw tracepoint access for unpriv\n"
  54. " 1 - Disallow cpu events for unpriv\n"
  55. " 2 - Disallow kernel profiling for unpriv\n");
  56. }
  57. void trace_event(union perf_event *event)
  58. {
  59. unsigned char *raw_event = (void *)event;
  60. const char *color = PERF_COLOR_BLUE;
  61. int i, j;
  62. if (!dump_trace)
  63. return;
  64. printf(".");
  65. color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
  66. event->header.size);
  67. for (i = 0; i < event->header.size; i++) {
  68. if ((i & 15) == 0) {
  69. printf(".");
  70. color_fprintf(stdout, color, " %04x: ", i);
  71. }
  72. color_fprintf(stdout, color, " %02x", raw_event[i]);
  73. if (((i & 15) == 15) || i == event->header.size-1) {
  74. color_fprintf(stdout, color, " ");
  75. for (j = 0; j < 15-(i & 15); j++)
  76. color_fprintf(stdout, color, " ");
  77. for (j = i & ~15; j <= i; j++) {
  78. color_fprintf(stdout, color, "%c",
  79. isprint(raw_event[j]) ?
  80. raw_event[j] : '.');
  81. }
  82. color_fprintf(stdout, color, "\n");
  83. }
  84. }
  85. printf(".\n");
  86. }