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. static int call_site_handler(struct trace_seq *s, struct pevent_record *record,
  25. struct event_format *event, void *context)
  26. {
  27. struct format_field *field;
  28. unsigned long long val, addr;
  29. void *data = record->data;
  30. const char *func;
  31. field = pevent_find_field(event, "call_site");
  32. if (!field)
  33. return 1;
  34. if (pevent_read_number_field(field, data, &val))
  35. return 1;
  36. func = pevent_find_function(event->pevent, val);
  37. if (!func)
  38. return 1;
  39. addr = pevent_find_function_address(event->pevent, val);
  40. trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr));
  41. return 1;
  42. }
  43. int PEVENT_PLUGIN_LOADER(struct pevent *pevent)
  44. {
  45. pevent_register_event_handler(pevent, -1, "kmem", "kfree",
  46. call_site_handler, NULL);
  47. pevent_register_event_handler(pevent, -1, "kmem", "kmalloc",
  48. call_site_handler, NULL);
  49. pevent_register_event_handler(pevent, -1, "kmem", "kmalloc_node",
  50. call_site_handler, NULL);
  51. pevent_register_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
  52. call_site_handler, NULL);
  53. pevent_register_event_handler(pevent, -1, "kmem",
  54. "kmem_cache_alloc_node",
  55. call_site_handler, NULL);
  56. pevent_register_event_handler(pevent, -1, "kmem", "kmem_cache_free",
  57. call_site_handler, NULL);
  58. return 0;
  59. }
  60. void PEVENT_PLUGIN_UNLOADER(struct pevent *pevent)
  61. {
  62. pevent_unregister_event_handler(pevent, -1, "kmem", "kfree",
  63. call_site_handler, NULL);
  64. pevent_unregister_event_handler(pevent, -1, "kmem", "kmalloc",
  65. call_site_handler, NULL);
  66. pevent_unregister_event_handler(pevent, -1, "kmem", "kmalloc_node",
  67. call_site_handler, NULL);
  68. pevent_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_alloc",
  69. call_site_handler, NULL);
  70. pevent_unregister_event_handler(pevent, -1, "kmem",
  71. "kmem_cache_alloc_node",
  72. call_site_handler, NULL);
  73. pevent_unregister_event_handler(pevent, -1, "kmem", "kmem_cache_free",
  74. call_site_handler, NULL);
  75. }