00001 /** 00002 * @file opd_proc.h 00003 * Management of processes 00004 * 00005 * @remark Copyright 2002 OProfile authors 00006 * @remark Read the file COPYING 00007 * 00008 * @author John Levon 00009 * @author Philippe Elie 00010 */ 00011 00012 #ifndef OPD_PROC_H 00013 #define OPD_PROC_H 00014 00015 #include "op_types.h" 00016 #include "op_list.h" 00017 00018 struct opd_map; 00019 struct opd_image; 00020 struct op_note; 00021 struct op_sample; 00022 00023 /** 00024 * track process, created either by a fork or an exec notification. 00025 */ 00026 struct opd_proc { 00027 /** maps are always added to the end of head, so search will be done 00028 * from the newest map to the oldest which mean we don't care about 00029 * munmap. First added map must be the primary image */ 00030 struct list_head maps; 00031 /** process name */ 00032 char const * name; 00033 /** thread id for this process, always equal to tgid for 2.2 kernel */ 00034 pid_t tid; 00035 /** thread group id for this process */ 00036 pid_t tgid; 00037 /** non-zero if this process receive any samples, this field 00038 * is used with dead field to defer opd_proc deletion */ 00039 int accessed; 00040 /** Set to non-zero when an exit notification occur for this process */ 00041 int dead; 00042 /** used by container of opd_proc */ 00043 struct list_head next; 00044 }; 00045 00046 /** 00047 * initialize opd_proc container 00048 */ 00049 void opd_init_procs(void); 00050 00051 /** 00052 * opd_put_sample - process a sample 00053 * @param sample sample to process 00054 * 00055 * Write out the sample to the appropriate sample file. This 00056 * routine handles kernel and module samples as well as ordinary ones. 00057 */ 00058 void opd_put_sample(struct op_sample const * sample); 00059 00060 /** 00061 * opd_put_image_sample - write sample to file 00062 * @param image image for sample 00063 * @param offset (file) offset to write to 00064 * @param counter counter number 00065 * 00066 * Add to the count stored at position offset in the 00067 * image file. Overflow pins the count at the maximum 00068 * value. 00069 */ 00070 void opd_put_image_sample(struct opd_image * image, unsigned long offset, u32 counter); 00071 00072 /** 00073 * opd_handle_fork - deal with fork notification 00074 * @param note note to handle 00075 * 00076 * Deal with a fork() notification by creating a new process 00077 * structure, and copying mapping information from the old process. 00078 * 00079 * sample->pid contains the process id of the old process. 00080 * sample->eip contains the process id of the new process. 00081 */ 00082 void opd_handle_fork(struct op_note const * note); 00083 00084 /** 00085 * opd_handle_exec - deal with notification of execve() 00086 * @param tid tid for this process 00087 * @param tgid tgid for this process 00088 * 00089 * Drop all mapping information for the process. 00090 */ 00091 void opd_handle_exec(pid_t tid, pid_t tgid); 00092 00093 /** 00094 * opd_handle_exit - deal with exit notification 00095 * @param note note to handle 00096 * 00097 * Deal with an exit() notification by setting the flag "dead" 00098 * on a process. These will be later cleaned up by the %SIGALRM 00099 * handler. 00100 * 00101 * sample->pid contains the process id of the exited process. 00102 */ 00103 void opd_handle_exit(struct op_note const * note); 00104 00105 /** 00106 * opd_get_proc - get process from process list 00107 * @param tid tid for this process 00108 * @param tgid tgid for this process 00109 * 00110 * A process with pid tid is searched on the process list, 00111 * maintaining LRU order. If it is not found, %NULL is returned, 00112 * otherwise the process structure is returned. 00113 */ 00114 struct opd_proc * opd_get_proc(pid_t tid, pid_t tgid); 00115 00116 /** 00117 * opd_new_proc - create a new process structure 00118 * @param tid tid for this process 00119 * @param tgid tgid for this process 00120 * 00121 * Allocate and initialise a process structure and insert 00122 * it into the procs hash table. 00123 */ 00124 struct opd_proc * opd_new_proc(pid_t tid, pid_t tgid); 00125 00126 /** 00127 * opd_get_nr_procs - return number of processes tracked 00128 */ 00129 int opd_get_nr_procs(void); 00130 00131 /** 00132 * opd_age_procs - age all dead process preparing them for a deletion 00133 */ 00134 void opd_age_procs(void); 00135 00136 /** 00137 * freeze all resource used by opd_procs managment 00138 */ 00139 void opd_proc_cleanup(void); 00140 00141 /** 00142 * opd_clear_kernel_mapping - remove all kernel mapping for all opd_proc 00143 * 00144 * invalidate (by removing them) all kernel mapping. This function do nothing 00145 * when separate_kernel == 0 because we don't add mapping for kernel 00146 * sample in proc struct. As side effect decrease reference count of 00147 * associated with these mapping which eventually close this image 00148 */ 00149 void opd_clear_kernel_mapping(void); 00150 00151 #endif /* OPD_PROC_H */
1.6.1