operf_kernel.cpp

Go to the documentation of this file.
00001 /*
00002  * @file pe_profiling/operf_kernel.cpp
00003  * This file is based on daemon/opd_kernel and is used for
00004  * dealing with the kernel and kernel module samples.
00005  *
00006  * @remark Copyright 2011 OProfile authors
00007  * @remark Read the file COPYING
00008  *
00009  * Created on: Dec 12, 2011
00010  * @author Maynard Johnson
00011  * (C) Copyright IBM Corp. 2011
00012  */
00013 
00014 #include <stdio.h>
00015 #include <iostream>
00016 #include <unistd.h>
00017 #include <stdlib.h>
00018 #include "operf_kernel.h"
00019 #include "operf_sfile.h"
00020 #include "op_list.h"
00021 #include "op_libiberty.h"
00022 #include "cverb.h"
00023 #include "op_fileio.h"
00024 
00025 
00026 extern verbose vmisc;
00027 extern bool no_vmlinux;
00028 
00029 static LIST_HEAD(modules);
00030 
00031 static struct operf_kernel_image vmlinux_image;
00032 
00033 using namespace std;
00034 
00035 void operf_create_vmlinux(char const * name, char const * arg)
00036 {
00037     /* vmlinux is *not* on the list of modules */
00038     list_init(&vmlinux_image.list);
00039 
00040     /* for no vmlinux */
00041     if (no_vmlinux) {
00042         vmlinux_image.name = xstrdup("no-vmlinux");
00043         return;
00044     }
00045 
00046     vmlinux_image.name = xstrdup(name);
00047 
00048     sscanf(arg, "%llx,%llx", &vmlinux_image.start, &vmlinux_image.end);
00049 
00050     cverb << vmisc << "kernel_start = " << hex <<  vmlinux_image.start
00051             << "; kernel_end = " << vmlinux_image.end << endl;
00052 
00053     if (!vmlinux_image.start && !vmlinux_image.end) {
00054         cerr << "error: mis-parsed kernel range: " << hex << vmlinux_image.start
00055                 << "; kernel_end = " << vmlinux_image.end << endl;
00056         exit(EXIT_FAILURE);
00057     }
00058 }
00059 
00060 
00067 void operf_create_module(char const * name, vma_t start, vma_t end)
00068 {
00069     struct operf_kernel_image * image =(struct operf_kernel_image *) xmalloc(sizeof(struct operf_kernel_image));
00070 
00071     image->name = xstrdup(name);
00072     image->start = start;
00073     image->end = end;
00074     list_add(&image->list, &modules);
00075 }
00076 
00077 void operf_free_modules_list(void)
00078 {
00079     struct list_head * pos;
00080     struct list_head * pos2;
00081     struct operf_kernel_image * image;
00082     list_for_each_safe(pos, pos2, &modules) {
00083         image = list_entry(pos, struct operf_kernel_image, list);
00084         free(image->name);
00085         list_del(&image->list);
00086         free(image);
00087     }
00088 
00089 }
00090 
00099 struct operf_kernel_image * operf_find_kernel_image(vma_t pc)
00100 {
00101     struct list_head * pos;
00102     struct operf_kernel_image * image = &vmlinux_image;
00103 
00104     if (no_vmlinux)
00105         return image;
00106 
00107     if (image->start <= pc && image->end > pc)
00108         return image;
00109 
00110     list_for_each(pos, &modules) {
00111         image = list_entry(pos, struct operf_kernel_image, list);
00112         if (image->start <= pc && image->end > pc)
00113             return image;
00114     }
00115 
00116     return NULL;
00117 }
00118 
00119 const char * operf_get_vmlinux_name(void)
00120 {
00121     return vmlinux_image.name;
00122 }

Generated on 8 Nov 2012 for Oprofile by  doxygen 1.6.1