Mike Dodd | 8cfa702 | 2010-11-17 11:12:26 -0800 | [diff] [blame^] | 1 | /** |
| 2 | * @file opd_proc.h |
| 3 | * Management of processes |
| 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_PROC_H |
| 13 | #define OPD_PROC_H |
| 14 | |
| 15 | #include "op_types.h" |
| 16 | #include "op_list.h" |
| 17 | |
| 18 | struct opd_map; |
| 19 | struct opd_image; |
| 20 | struct op_note; |
| 21 | struct op_sample; |
| 22 | |
| 23 | /** |
| 24 | * track process, created either by a fork or an exec notification. |
| 25 | */ |
| 26 | struct opd_proc { |
| 27 | /** maps are always added to the end of head, so search will be done |
| 28 | * from the newest map to the oldest which mean we don't care about |
| 29 | * munmap. First added map must be the primary image */ |
| 30 | struct list_head maps; |
| 31 | /** process name */ |
| 32 | char const * name; |
| 33 | /** thread id for this process, always equal to tgid for 2.2 kernel */ |
| 34 | pid_t tid; |
| 35 | /** thread group id for this process */ |
| 36 | pid_t tgid; |
| 37 | /** non-zero if this process receive any samples, this field |
| 38 | * is used with dead field to defer opd_proc deletion */ |
| 39 | int accessed; |
| 40 | /** Set to non-zero when an exit notification occur for this process */ |
| 41 | int dead; |
| 42 | /** used by container of opd_proc */ |
| 43 | struct list_head next; |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * initialize opd_proc container |
| 48 | */ |
| 49 | void opd_init_procs(void); |
| 50 | |
| 51 | /** |
| 52 | * opd_put_sample - process a sample |
| 53 | * @param sample sample to process |
| 54 | * |
| 55 | * Write out the sample to the appropriate sample file. This |
| 56 | * routine handles kernel and module samples as well as ordinary ones. |
| 57 | */ |
| 58 | void opd_put_sample(struct op_sample const * sample); |
| 59 | |
| 60 | /** |
| 61 | * opd_put_image_sample - write sample to file |
| 62 | * @param image image for sample |
| 63 | * @param offset (file) offset to write to |
| 64 | * @param counter counter number |
| 65 | * |
| 66 | * Add to the count stored at position offset in the |
| 67 | * image file. Overflow pins the count at the maximum |
| 68 | * value. |
| 69 | */ |
| 70 | void opd_put_image_sample(struct opd_image * image, unsigned long offset, u32 counter); |
| 71 | |
| 72 | /** |
| 73 | * opd_handle_fork - deal with fork notification |
| 74 | * @param note note to handle |
| 75 | * |
| 76 | * Deal with a fork() notification by creating a new process |
| 77 | * structure, and copying mapping information from the old process. |
| 78 | * |
| 79 | * sample->pid contains the process id of the old process. |
| 80 | * sample->eip contains the process id of the new process. |
| 81 | */ |
| 82 | void opd_handle_fork(struct op_note const * note); |
| 83 | |
| 84 | /** |
| 85 | * opd_handle_exec - deal with notification of execve() |
| 86 | * @param tid tid for this process |
| 87 | * @param tgid tgid for this process |
| 88 | * |
| 89 | * Drop all mapping information for the process. |
| 90 | */ |
| 91 | void opd_handle_exec(pid_t tid, pid_t tgid); |
| 92 | |
| 93 | /** |
| 94 | * opd_handle_exit - deal with exit notification |
| 95 | * @param note note to handle |
| 96 | * |
| 97 | * Deal with an exit() notification by setting the flag "dead" |
| 98 | * on a process. These will be later cleaned up by the %SIGALRM |
| 99 | * handler. |
| 100 | * |
| 101 | * sample->pid contains the process id of the exited process. |
| 102 | */ |
| 103 | void opd_handle_exit(struct op_note const * note); |
| 104 | |
| 105 | /** |
| 106 | * opd_get_proc - get process from process list |
| 107 | * @param tid tid for this process |
| 108 | * @param tgid tgid for this process |
| 109 | * |
| 110 | * A process with pid tid is searched on the process list, |
| 111 | * maintaining LRU order. If it is not found, %NULL is returned, |
| 112 | * otherwise the process structure is returned. |
| 113 | */ |
| 114 | struct opd_proc * opd_get_proc(pid_t tid, pid_t tgid); |
| 115 | |
| 116 | /** |
| 117 | * opd_new_proc - create a new process structure |
| 118 | * @param tid tid for this process |
| 119 | * @param tgid tgid for this process |
| 120 | * |
| 121 | * Allocate and initialise a process structure and insert |
| 122 | * it into the procs hash table. |
| 123 | */ |
| 124 | struct opd_proc * opd_new_proc(pid_t tid, pid_t tgid); |
| 125 | |
| 126 | /** |
| 127 | * opd_get_nr_procs - return number of processes tracked |
| 128 | */ |
| 129 | int opd_get_nr_procs(void); |
| 130 | |
| 131 | /** |
| 132 | * opd_age_procs - age all dead process preparing them for a deletion |
| 133 | */ |
| 134 | void opd_age_procs(void); |
| 135 | |
| 136 | /** |
| 137 | * freeze all resource used by opd_procs managment |
| 138 | */ |
| 139 | void opd_proc_cleanup(void); |
| 140 | |
| 141 | /** |
| 142 | * opd_clear_kernel_mapping - remove all kernel mapping for all opd_proc |
| 143 | * |
| 144 | * invalidate (by removing them) all kernel mapping. This function do nothing |
| 145 | * when separate_kernel == 0 because we don't add mapping for kernel |
| 146 | * sample in proc struct. As side effect decrease reference count of |
| 147 | * associated with these mapping which eventually close this image |
| 148 | */ |
| 149 | void opd_clear_kernel_mapping(void); |
| 150 | |
| 151 | #endif /* OPD_PROC_H */ |