16 #ifndef _SQL_PROFILE_H
17 #define _SQL_PROFILE_H
27 int make_profile_table_for_show(THD *thd,
ST_SCHEMA_TABLE *schema_table);
30 #define PROFILE_NONE (uint)0
31 #define PROFILE_CPU (uint)(1<<0)
32 #define PROFILE_MEMORY (uint)(1<<1)
33 #define PROFILE_BLOCK_IO (uint)(1<<2)
34 #define PROFILE_CONTEXT (uint)(1<<3)
35 #define PROFILE_PAGE_FAULTS (uint)(1<<4)
36 #define PROFILE_IPC (uint)(1<<5)
37 #define PROFILE_SWAPS (uint)(1<<6)
38 #define PROFILE_SOURCE (uint)(1<<16)
39 #define PROFILE_ALL (uint)(~0)
42 #if defined(ENABLED_PROFILING)
46 #ifdef HAVE_SYS_RESOURCE_H
47 #include <sys/resource.h>
51 class PROF_MEASUREMENT;
60 template <
class T>
class Queue
67 struct queue_item *next, *previous;
70 struct queue_item *first, *last;
81 struct queue_item *
i, *after_i;
82 for (i= first; i != NULL; i= after_i)
92 void push_back(T *payload)
94 struct queue_item *new_item;
96 new_item= (
struct queue_item *) my_malloc(
sizeof(
struct queue_item), MYF(0));
98 new_item->payload= payload;
104 DBUG_ASSERT(last->next == NULL);
105 last->next= new_item;
107 new_item->previous= last;
108 new_item->next= NULL;
116 struct queue_item *old_item= first;
121 DBUG_PRINT(
"warning", (
"tried to pop nonexistent item from Queue"));
125 ret= old_item->payload;
126 if (first->next != NULL)
127 first->next->previous= NULL;
140 DBUG_ASSERT(((elements > 0) && (first != NULL)) || ((elements == 0) || (first == NULL)));
141 return (elements == 0);
149 void *iterator_next(
void *current)
151 return ((
struct queue_item *) current)->next;
154 T *iterator_value(
void *current)
156 return ((
struct queue_item *) current)->payload;
165 class PROF_MEASUREMENT
168 friend class QUERY_PROFILE;
169 friend class PROFILING;
171 QUERY_PROFILE *profile;
173 #ifdef HAVE_GETRUSAGE
175 #elif defined(_WIN32)
176 FILETIME ftKernel, ftUser;
185 char *allocated_status_memory;
187 void set_label(
const char *status_arg,
const char *function_arg,
188 const char *file_arg,
unsigned int line_arg);
192 PROF_MEASUREMENT(QUERY_PROFILE *profile_arg,
const char *status_arg);
193 PROF_MEASUREMENT(QUERY_PROFILE *profile_arg,
const char *status_arg,
194 const char *function_arg,
195 const char *file_arg,
unsigned int line_arg);
208 friend class PROFILING;
210 PROFILING *profiling;
212 query_id_t profiling_query_id;
215 double m_start_time_usecs;
216 double m_end_time_usecs;
218 Queue<PROF_MEASUREMENT> entries;
221 QUERY_PROFILE(PROFILING *profiling_arg,
const char *status_arg);
224 void set_query_source(
char *query_source_arg, uint query_length_arg);
227 void new_status(
const char *status_arg,
228 const char *function_arg,
229 const char *file_arg,
unsigned int line_arg);
235 bool show(uint options);
245 friend class PROF_MEASUREMENT;
246 friend class QUERY_PROFILE;
251 query_id_t profile_id_counter;
256 QUERY_PROFILE *current;
258 Queue<QUERY_PROFILE> history;
260 query_id_t next_profile_id() {
return(profile_id_counter++); }
265 void set_query_source(
char *query_source_arg, uint query_length_arg);
267 void start_new_query(
const char *initial_state=
"starting");
269 void discard_current_query();
271 void finish_current_query();
273 void status_change(
const char *status_arg,
274 const char *function_arg,
275 const char *file_arg,
unsigned int line_arg);
277 inline void set_thd(THD *thd_arg) { thd= thd_arg; };
280 bool show_profiles();
283 int fill_statistics_info(THD *thd,
TABLE_LIST *tables,
Item *cond);