debug.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 trace_event(union perf_event *event)
  48. {
  49. unsigned char *raw_event = (void *)event;
  50. const char *color = PERF_COLOR_BLUE;
  51. int i, j;
  52. if (!dump_trace)
  53. return;
  54. printf(".");
  55. color_fprintf(stdout, color, "\n. ... raw event: size %d bytes\n",
  56. event->header.size);
  57. for (i = 0; i < event->header.size; i++) {
  58. if ((i & 15) == 0) {
  59. printf(".");
  60. color_fprintf(stdout, color, " %04x: ", i);
  61. }
  62. color_fprintf(stdout, color, " %02x", raw_event[i]);
  63. if (((i & 15) == 15) || i == event->header.size-1) {
  64. color_fprintf(stdout, color, " ");
  65. for (j = 0; j < 15-(i & 15); j++)
  66. color_fprintf(stdout, color, " ");
  67. for (j = i & ~15; j <= i; j++) {
  68. color_fprintf(stdout, color, "%c",
  69. isprint(raw_event[j]) ?
  70. raw_event[j] : '.');
  71. }
  72. color_fprintf(stdout, color, "\n");
  73. }
  74. }
  75. printf(".\n");
  76. }