00001 #ifndef __QOS_PROF_H__
00002 #define __QOS_PROF_H__
00003
00055
00056 #include "qos_debug.h"
00057
00058 #ifdef QOS_KS
00059
00060 # include <linux/kernel.h>
00061 # include <linux/version.h>
00062 # include <linux/module.h>
00063 # include <linux/string.h>
00064 # include <linux/aquosa/rres_time.h>
00065 #else
00066 # include <string.h>
00067 #endif
00068
00074 #define QOS_PROF_MAX_COUNTS 128
00075
00077 #define QOS_PROF_NAME_SIZE 32
00078
00080 typedef struct {
00081 unsigned long int counter;
00082 unsigned long long time;
00083 char func_name[QOS_PROF_NAME_SIZE];
00084 } qos_profile_t;
00085
00086 #ifdef QOS_PROFILE
00087
00089 extern qos_profile_t qos_prof_data[QOS_PROF_MAX_COUNTS];
00090
00092 extern int qos_prof_num;
00093
00095 void prof_dump(void);
00096
00097 #else
00098
00099 static inline void prof_dump(void) { }
00100
00101 #endif
00102
00103 static inline qos_profile_t * prof_register(const char *name) {
00104 #ifdef QOS_PROFILE
00105 qos_profile_t * p;
00106 if (qos_prof_num == QOS_PROF_MAX_COUNTS) {
00107 qos_log_crit("Profile slots exhausted, so I'm rewriting last one. Please, increment QOS_PROF_MAX_COUNTS.");
00108 qos_prof_num--;
00109 }
00110 p = qos_prof_data + qos_prof_num;
00111 qos_prof_num++;
00112 strncpy(p->func_name, name, sizeof(p->func_name));
00113 p->counter = 0;
00114 p->time = 0;
00115 return p;
00116 #else
00117 return 0;
00118 #endif
00119 }
00120
00122 #ifdef QOS_PROFILE
00123 # define prof_vars \
00124 unsigned long long _prof_clk1, _prof_clk2; \
00125 static qos_profile_t *_p_prof = 0
00126 #else
00127 # define prof_vars
00128 #endif
00129
00130
00131
00132
00133
00134
00136 #ifdef QOS_PROFILE
00137 #define prof_func() do { \
00138 if (_p_prof == 0) \
00139 _p_prof = prof_register(__func__); \
00140 _prof_clk1 = sched_read_clock(); \
00141 } while (0)
00142 #else
00143 #define prof_func()
00144 #endif
00145
00146 #ifdef QOS_PROFILE
00147
00148 #define _update_prof_var() do { \
00149 _prof_clk2 = sched_read_clock(); \
00150 _p_prof->counter++; \
00151 _p_prof->time += _prof_clk2 - _prof_clk1; \
00152 } while (0)
00153
00155 #define prof_return(args...) do { \
00156 _update_prof_var(); \
00157 return args; \
00158 } while (0)
00159
00161 #define prof_end() do { \
00162 _update_prof_var(); \
00163 } while (0)
00164 #define prof_call(args...) do { prof_func(); args; prof_end(); } while(0)
00165 #else
00166 #define prof_return(args...) do { return args; } while (0)
00167 #define prof_end() do { } while (0)
00168 #define prof_call(args...) do { } while (0)
00169 #endif
00170
00171 #endif