root/tools/lib/traceevent/plugins/plugin_kmem.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. call_site_handler
  2. TEP_PLUGIN_LOADER
  3. TEP_PLUGIN_UNLOADER

   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 
  24 #include "event-parse.h"
  25 #include "trace-seq.h"
  26 
  27 static int call_site_handler(struct trace_seq *s, struct tep_record *record,
  28                              struct tep_event *event, void *context)
  29 {
  30         struct tep_format_field *field;
  31         unsigned long long val, addr;
  32         void *data = record->data;
  33         const char *func;
  34 
  35         field = tep_find_field(event, "call_site");
  36         if (!field)
  37                 return 1;
  38 
  39         if (tep_read_number_field(field, data, &val))
  40                 return 1;
  41 
  42         func = tep_find_function(event->tep, val);
  43         if (!func)
  44                 return 1;
  45 
  46         addr = tep_find_function_address(event->tep, val);
  47 
  48         trace_seq_printf(s, "(%s+0x%x) ", func, (int)(val - addr));
  49         return 1;
  50 }
  51 
  52 int TEP_PLUGIN_LOADER(struct tep_handle *tep)
  53 {
  54         tep_register_event_handler(tep, -1, "kmem", "kfree",
  55                                    call_site_handler, NULL);
  56 
  57         tep_register_event_handler(tep, -1, "kmem", "kmalloc",
  58                                    call_site_handler, NULL);
  59 
  60         tep_register_event_handler(tep, -1, "kmem", "kmalloc_node",
  61                                    call_site_handler, NULL);
  62 
  63         tep_register_event_handler(tep, -1, "kmem", "kmem_cache_alloc",
  64                                    call_site_handler, NULL);
  65 
  66         tep_register_event_handler(tep, -1, "kmem",
  67                                    "kmem_cache_alloc_node",
  68                                    call_site_handler, NULL);
  69 
  70         tep_register_event_handler(tep, -1, "kmem", "kmem_cache_free",
  71                                    call_site_handler, NULL);
  72         return 0;
  73 }
  74 
  75 void TEP_PLUGIN_UNLOADER(struct tep_handle *tep)
  76 {
  77         tep_unregister_event_handler(tep, -1, "kmem", "kfree",
  78                                      call_site_handler, NULL);
  79 
  80         tep_unregister_event_handler(tep, -1, "kmem", "kmalloc",
  81                                      call_site_handler, NULL);
  82 
  83         tep_unregister_event_handler(tep, -1, "kmem", "kmalloc_node",
  84                                      call_site_handler, NULL);
  85 
  86         tep_unregister_event_handler(tep, -1, "kmem", "kmem_cache_alloc",
  87                                      call_site_handler, NULL);
  88 
  89         tep_unregister_event_handler(tep, -1, "kmem",
  90                                      "kmem_cache_alloc_node",
  91                                      call_site_handler, NULL);
  92 
  93         tep_unregister_event_handler(tep, -1, "kmem", "kmem_cache_free",
  94                                      call_site_handler, NULL);
  95 }

/* [<][>][^][v][top][bottom][index][help] */