Home | History | Annotate | Download | only in liblegacy
      1 /**
      2  * @file opd_image.h
      3  * Management of binary images
      4  *
      5  * @remark Copyright 2002 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author John Levon
      9  * @author Philippe Elie
     10  */
     11 
     12 #ifndef OPD_IMAGE_H
     13 #define OPD_IMAGE_H
     14 
     15 #include "op_list.h"
     16 #include "op_config_24.h"
     17 #include "op_types.h"
     18 
     19 #include <time.h>
     20 
     21 struct opd_24_sfile;
     22 
     23 /**
     24  * A binary (library, application, kernel or module)
     25  * is represented by a struct opd_image.
     26  */
     27 struct opd_image {
     28 	/** used by container of opd_images */
     29 	struct list_head hash_next;
     30 	/** how many time this opd_image is referenced */
     31 	int ref_count;
     32 	/** all samples files belonging to this image */
     33 	struct opd_24_sfile ** sfiles[NR_CPUS];
     34 	/** name of this image */
     35 	char * name;
     36 	/** the application name where belongs this image, NULL if image has
     37 	 * no owner (such as vmlinux or module) */
     38 	char * app_name;
     39 	/** thread id, on 2.2 kernel always == to tgid */
     40 	pid_t tid;
     41 	/** thread group id  */
     42 	pid_t tgid;
     43 	/** time of last modification */
     44 	time_t mtime;
     45 	/** kernel image or not */
     46 	int kernel;
     47 	/** non zero if this image must be profiled */
     48 	int ignored;
     49 };
     50 
     51 /** callback function passed to opd_for_each_image() */
     52 typedef void (*opd_image_cb)(struct opd_image *);
     53 
     54 /**
     55  * @param imagecb callback to apply onto each existing image struct
     56  *
     57  * the callback receive a struct opd_image * (not a const struct) and is
     58  * allowed to freeze the image struct itself.
     59  */
     60 void opd_for_each_image(opd_image_cb imagecb);
     61 
     62 /**
     63  * initialize opd_image container
     64  */
     65 void opd_init_images(void);
     66 
     67 /**
     68  * @param image  the image pointer
     69  *
     70  * Decrement reference count of image, if reference count is zero flush and
     71  * close the samples files then freeze all memory belonging to this image.
     72  */
     73 void opd_delete_image(struct opd_image * image);
     74 
     75 /**
     76  * opd_get_kernel_image - get a kernel image
     77  * @param name of image
     78  * @param app_name application owner of this kernel image. non-null only
     79  *  when separate_kernel_sample != 0
     80  * @param tid  thread id
     81  * @param tgid  thread group id
     82  *
     83  * Create and initialise an image adding it to the image lists and to image
     84  * hash list. Note than at creation reference count is zero, it's caller
     85  * responsabilities to incr this count.
     86  */
     87 struct opd_image * opd_get_kernel_image(char const * name,
     88      char const * app_name, pid_t tid, pid_t tgid);
     89 
     90 /**
     91  * opd_get_image - get an image from the image structure
     92  * @param name  name of image
     93  * @param app_name  the application name where belongs this image
     94  * @param kernel  is the image a kernel/module image
     95  * @param tid  thread id
     96  * @param tgid  thread group id
     97  *
     98  * Get the image specified by the file name name from the
     99  * image structure. If it is not present, the image is
    100  * added to the structure. In either case, the image number
    101  * is returned.
    102  */
    103 struct opd_image * opd_get_image(char const * name, char const * app_name,
    104                                  int kernel, pid_t tid, pid_t tgid);
    105 
    106 /**
    107  * opd_get_nr_images - return number of images
    108  */
    109 int opd_get_nr_images(void);
    110 
    111 #endif /* OPD_IMAGE_H */
    112