plugin_kmem.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * Copyright (C) 2009 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
  3. *
  4. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation;
  8. * version 2.1 of the License (not later!)
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this program; if not, see <http://www.gnu.org/licenses>
  17. *
  18. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include "event-parse.h"
  24. #include "trace-seq.h"
  25. static int call_site_handler(struct trace_seq *s, struct tep_record *record,
  26. struct tep_event_format *event, void *context)
  27. {
  28. struct tep_format_field *field;
  29. unsigned long long val, addr;
  30. void *data = record->data;
  31. const char *func;
  32. field = tep_find_field(event, "call_site");
  33. if (!field)
  34. return 1;
  35. if (tep_read_number_field(field, data, &val))
  36. return 1;
  37. func = tep_find_function(event->pevent, val);
  38. if (!func)
  39. return 1;
  40. addr = tep_find_function_address(event->pevent, val);
  41. trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr));
  42. return 1;
  43. }
  44. int TEP_PLUGIN_LOADER(struct tep_handle *pevent)
  45. {
  46. tep_register_event_handler(pevent, -1, "kmem", "kfree",
  47. call_site_handler, NULL);
  48. tep_register_event_handler(pevent, -1, "kmem", "kmalloc",
  49. call_site_handler, NULL);
  50. tep_register_event_handler(pevent, -1, "kmem", "kmalloc_node",
  51. call_site_handler, NULL);
  52. tep_register_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
  53. call_site_handler, NULL);
  54. tep_register_event_handler(pevent, -1, "kmem",
  55. "kmem_cache_alloc_node",
  56. call_site_handler, NULL);
  57. tep_register_event_handler(pevent, -1, "kmem", "kmem_cache_free",
  58. call_site_handler, NULL);
  59. return 0;
  60. }
  61. void TEP_PLUGIN_UNLOADER(struct tep_handle *pevent)
  62. {
  63. tep_unregister_event_handler(pevent, -1, "kmem", "kfree",
  64. call_site_handler, NULL);
  65. tep_unregister_event_handler(pevent, -1, "kmem", "kmalloc",
  66. call_site_handler, NULL);
  67. tep_unregister_event_handler(pevent, -1, "kmem", "kmalloc_node",
  68. call_site_handler, NULL);
  69. tep_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
  70. call_site_handler, NULL);
  71. tep_unregister_event_handler(pevent, -1, "kmem",
  72. "kmem_cache_alloc_node",
  73. call_site_handler, NULL);
  74. tep_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_free",
  75. call_site_handler, NULL);
  76. }