debug.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ui_helpline__vshow(fmt, args);
  22. else
  23. ret = vfprintf(stderr, fmt, args);
  24. va_end(args);
  25. }
  26. return ret;
  27. }
  28. int dump_printf(const char *fmt, ...)
  29. {
  30. va_list args;
  31. int ret = 0;
  32. if (dump_trace) {
  33. va_start(args, fmt);
  34. ret = vprintf(fmt, args);
  35. va_end(args);
  36. }
  37. return ret;
  38. }
  39. void trace_event(union perf_event *event)
  40. {
  41. unsigned char *raw_event = (void *)event;
  42. const char *color = PERF_COLOR_BLUE;
  43. int i, j;
  44. if (!dump_trace)
  45. return;
  46. printf(".");
  47. color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
  48. event->header.size);
  49. for (i = 0; i < event->header.size; i++) {
  50. if ((i & 15) == 0) {
  51. printf(".");
  52. color_fprintf(stdout, color, " %04x: ", i);
  53. }
  54. color_fprintf(stdout, color, " %02x", raw_event[i]);
  55. if (((i & 15) == 15) || i == event->header.size-1) {
  56. color_fprintf(stdout, color, " ");
  57. for (j = 0; j < 15-(i & 15); j++)
  58. color_fprintf(stdout, color, " ");
  59. for (j = i & ~15; j <= i; j++) {
  60. color_fprintf(stdout, color, "%c",
  61. isprint(raw_event[j]) ?
  62. raw_event[j] : '.');
  63. }
  64. color_fprintf(stdout, color, "\n");
  65. }
  66. }
  67. printf(".\n");
  68. }