1 #ifndef _PROFILE_H 2 #define _PROFILE_H 3 4 #include <minix/type.h> 5 #include <sys/types.h> 6 7 /* 8 * Types relating to system profiling. Types are supplied for both 9 * statistical profiling and call profiling. 10 */ 11 12 # define PROF_START 0 /* start statistical profiling */ 13 # define PROF_STOP 1 /* stop statistical profiling */ 14 15 #define PROF_RTC 0 /* RTC based profiling */ 16 #define PROF_NMI 1 /* NMI based profiling, profiles kernel too */ 17 18 /* Info struct to be copied to from kernel to user program. */ 19 struct sprof_info_s { 20 int mem_used; 21 int total_samples; 22 int idle_samples; 23 int system_samples; 24 int user_samples; 25 }; 26 27 /* What a profiling sample looks like (used for sizeof()). */ 28 struct sprof_sample { 29 endpoint_t proc; 30 void * pc; 31 }; 32 33 struct sprof_proc { 34 endpoint_t proc; 35 char name[PROC_NAME_LEN]; 36 }; 37 38 # define PROF_GET 2 /* get call profiling tables */ 39 # define PROF_RESET 3 /* reset call profiling tables */ 40 41 /* Hash table size in each profiled process is table size + index size. 42 * 43 * Table size = CPROF_TABLE_SIZE * (CPROF_CPATH_MAX_LEN + 16). 44 * Index size = CPROF_INDEX_SIZE * 4; 45 * 46 * Making CPROF_CPATH_MAX_LEN too small may cause call path overruns. 47 * Making CPROF_TABLE_SIZE too small may cause table overruns. 48 * 49 * There are some restrictions: processes in the boot image are loaded 50 * below 16 MB and the kernel is loaded in lower memory (below 640 kB). The 51 * latter is reason to use a different size for the kernel table. 52 */ 53 #define CPROF_TABLE_SIZE_OTHER 3000 /* nr of slots in hash table */ 54 #define CPROF_TABLE_SIZE_KERNEL 1500 /* kernel has a smaller table */ 55 #define CPROF_CPATH_MAX_LEN 256 /* len of cpath string field: */ 56 /* MUST BE MULTIPLE OF WORDSIZE */ 57 58 #define CPROF_INDEX_SIZE (10*1024)/* size of index to hash table */ 59 #define CPROF_STACK_SIZE 24 /* size of call stack */ 60 #define CPROF_PROCNAME_LEN 8 /* len of proc name field */ 61 62 #define CPROF_CPATH_OVERRUN 0x1 /* call path overrun */ 63 #define CPROF_STACK_OVERRUN 0x2 /* call stack overrun */ 64 #define CPROF_TABLE_OVERRUN 0x4 /* hash table overrun */ 65 66 #define CPROF_ANNOUNCE_OTHER 1 /* processes announce their profiling 67 * data on n-th entry of procentry */ 68 #define CPROF_ACCOUNCE_KERNEL 10000 /* kernel announces not directly */ 69 70 /* Prototype for function called by procentry to get size of table. */ 71 int profile_get_tbl_size(void); 72 /* Prototype for function called by procentry to get announce number. */ 73 int profile_get_announce(void); 74 /* Prototype for function called by procentry to announce control struct 75 * and table locations to the kernel. */ 76 void profile_register(void *ctl_ptr, void *tbl_ptr); 77 78 /* Info struct to be copied from kernel to user program. */ 79 struct cprof_info_s { 80 int mem_used; 81 int err; 82 }; 83 84 /* Data structures for control structure and profiling data table in the 85 * in the profiled processes. 86 */ 87 struct cprof_ctl_s { 88 int reset; /* kernel sets to have table reset */ 89 int slots_used; /* proc writes nr slots used in table */ 90 int err; /* proc writes errors that occurred */ 91 }; 92 93 struct cprof_tbl_s { 94 struct cprof_tbl_s *next; /* next in chain */ 95 char cpath[CPROF_CPATH_MAX_LEN]; /* string with call path */ 96 int calls; /* nr of executions of path */ 97 u64_t cycles; /* execution time of path, in cycles */ 98 }; 99 100 int sprofile(int action, int size, int freq, int type, void *ctl_ptr, 101 void *mem_ptr); 102 103 int cprofile(int action, int size, void *ctl_ptr, void *mem_ptr); 104 105 #endif /* PROFILE_H */ 106 107