102.1.1
by kinoyasu
add header and rule, as the first step of the reordering patch for separate release |
1 |
# name : profiling_slow.patch |
2 |
# introduced : 11 or before |
|
3 |
# maintainer : Yasufumi |
|
4 |
# |
|
5 |
#!!! notice !!! |
|
6 |
# Any small change to this file in the main branch |
|
7 |
# should be done or reviewed by the maintainer! |
|
135.5.1
by Oleg Tsarev
fix bug 673426 |
8 |
diff -ruN /dev/null b/patch_info/profiling_slow.info
|
106
by kinoyasu
Port Yasufumi maintaining patches to 5.1.50: |
9 |
--- /dev/null 1970-01-01 03:00:00.000000000 +0300
|
54.2.6
by Oleg Tsarev
normalize patches |
10 |
+++ b/patch_info/profiling_slow.info 2010-07-07 03:32:18.108972002 +0400
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
11 |
@@ -0,0 +1,9 @@
|
12 |
+File=profiling_slow.info
|
|
13 |
+Name=profiling from SHOW PROFILE to slow.log
|
|
14 |
+Version=1.0
|
|
15 |
+Author=Percona <info@percona.com>
|
|
16 |
+License=GPL
|
|
17 |
+Comment=
|
|
18 |
+Changelog
|
|
19 |
+2009-05-18
|
|
20 |
+Initial implementation
|
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
21 |
diff -ruN a/sql/log.cc b/sql/log.cc
|
54.2.6
by Oleg Tsarev
normalize patches |
22 |
--- a/sql/log.cc 2010-07-07 03:32:17.588972002 +0400
|
23 |
+++ b/sql/log.cc 2010-07-07 03:32:18.108972002 +0400
|
|
133
by kinoyasu
port maintainer-Yasufumi patches for 5.1.52 |
24 |
@@ -2433,6 +2433,11 @@
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
25 |
my_b_printf(&log_file,"# No InnoDB statistics available for this query\n") == (uint) -1) |
26 |
tmp_errno=errno; |
|
27 |
} |
|
28 |
+
|
|
29 |
+#if defined(ENABLED_PROFILING) && defined(COMMUNITY_SERVER)
|
|
30 |
+ thd->profiling.print_current(&log_file);
|
|
31 |
+#endif
|
|
32 |
+
|
|
33 |
if (thd->db && strcmp(thd->db, db)) |
|
34 |
{ // Database changed |
|
35 |
if (my_b_printf(&log_file,"use %s;\n",thd->db) == (uint) -1) |
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
36 |
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
|
54.2.6
by Oleg Tsarev
normalize patches |
37 |
--- a/sql/mysqld.cc 2010-07-07 03:32:17.598972002 +0400
|
38 |
+++ b/sql/mysqld.cc 2010-07-07 03:32:18.108972002 +0400
|
|
127
by kinoyasu
port maintainer-Yasufumi patches for 5.1.51 |
39 |
@@ -5778,6 +5778,8 @@
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
40 |
OPT_LOG_OUTPUT, |
41 |
OPT_PORT_OPEN_TIMEOUT, |
|
42 |
OPT_PROFILING, |
|
43 |
+ OPT_PROFILING_SERVER,
|
|
44 |
+ OPT_PROFILING_USE_GETRUSAGE,
|
|
45 |
OPT_KEEP_FILES_ON_CREATE, |
|
46 |
OPT_GENERAL_LOG, |
|
47 |
OPT_SLOW_LOG, |
|
127
by kinoyasu
port maintainer-Yasufumi patches for 5.1.51 |
48 |
@@ -6390,6 +6392,16 @@
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
49 |
&global_system_variables.profiling_history_size, |
50 |
&max_system_variables.profiling_history_size, |
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
51 |
0, GET_ULONG, REQUIRED_ARG, 15, 0, 100, 0, 0, 0}, |
52 |
+ {"profiling_server", OPT_PROFILING_SERVER,
|
|
53 |
+ "Enable profiling of all threads",
|
|
54 |
+ (uchar**) &global_system_variables.profiling_server,
|
|
55 |
+ (uchar**) &max_system_variables.profiling_server, 0, GET_BOOL,
|
|
56 |
+ OPT_ARG, 0, 0, 0, 0, 0, 0 },
|
|
57 |
+ {"profiling_use_getrusage", OPT_PROFILING_USE_GETRUSAGE,
|
|
58 |
+ "Enable getrusage function call for profiling",
|
|
59 |
+ (uchar**) &global_system_variables.profiling_use_getrusage,
|
|
60 |
+ (uchar**) &max_system_variables.profiling_use_getrusage, 0, GET_BOOL,
|
|
61 |
+ OPT_ARG, 0, 0, 0, 0, 0, 0 },
|
|
62 |
#endif |
|
63 |
{"relay-log", OPT_RELAY_LOG, |
|
64 |
"The location and name to use for relay logs.", |
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
65 |
diff -ruN a/sql/set_var.cc b/sql/set_var.cc
|
54.2.6
by Oleg Tsarev
normalize patches |
66 |
--- a/sql/set_var.cc 2010-07-07 03:32:17.588972002 +0400
|
67 |
+++ b/sql/set_var.cc 2010-07-07 03:32:18.118972002 +0400
|
|
135.5.1
by Oleg Tsarev
fix bug 673426 |
68 |
@@ -847,6 +847,10 @@
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
69 |
ulonglong(OPTION_PROFILING)); |
70 |
static sys_var_thd_ulong sys_profiling_history_size(&vars, "profiling_history_size", |
|
71 |
&SV::profiling_history_size); |
|
72 |
+static sys_var_thd_bool sys_profiling_server(&vars, "profiling_server",
|
|
73 |
+ &SV::profiling_server);
|
|
74 |
+static sys_var_thd_bool sys_profiling_use_getrusage(&vars, "profiling_use_getrusage",
|
|
75 |
+ &SV::profiling_use_getrusage);
|
|
76 |
#endif |
|
77 |
||
78 |
/* Local state variables */ |
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
79 |
diff -ruN a/sql/sql_class.h b/sql/sql_class.h
|
54.2.6
by Oleg Tsarev
normalize patches |
80 |
--- a/sql/sql_class.h 2010-07-07 03:32:17.588972002 +0400
|
81 |
+++ b/sql/sql_class.h 2010-07-07 03:32:18.118972002 +0400
|
|
106
by kinoyasu
Port Yasufumi maintaining patches to 5.1.50: |
82 |
@@ -328,6 +328,8 @@
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
83 |
ulong optimizer_switch; |
84 |
ulong preload_buff_size; |
|
85 |
ulong profiling_history_size; |
|
86 |
+ my_bool profiling_server;
|
|
87 |
+ my_bool profiling_use_getrusage;
|
|
88 |
ulong query_cache_type; |
|
89 |
ulong read_buff_size; |
|
90 |
ulong read_rnd_buff_size; |
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
91 |
diff -ruN a/sql/sql_profile.cc b/sql/sql_profile.cc
|
54.2.6
by Oleg Tsarev
normalize patches |
92 |
--- a/sql/sql_profile.cc 2010-07-07 03:32:17.598972002 +0400
|
93 |
+++ b/sql/sql_profile.cc 2010-07-07 03:32:18.118972002 +0400
|
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
94 |
@@ -221,9 +221,22 @@
|
95 |
*/ |
|
96 |
void PROF_MEASUREMENT::collect() |
|
97 |
{ |
|
98 |
+ struct timespec tp;
|
|
99 |
time_usecs= (double) my_getsystime() / 10.0; /* 1 sec was 1e7, now is 1e6 */ |
|
100 |
#ifdef HAVE_GETRUSAGE |
|
101 |
- getrusage(RUSAGE_SELF, &rusage);
|
|
102 |
+ if ((profile->get_profiling())->enabled_getrusage())
|
|
103 |
+ getrusage(RUSAGE_SELF, &rusage);
|
|
104 |
+#endif
|
|
105 |
+
|
|
106 |
+#ifdef HAVE_CLOCK_GETTIME
|
|
107 |
+ if (!(clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tp)))
|
|
108 |
+ {
|
|
109 |
+ cpu_time_usecs= tp.tv_sec*1000000000.0 + tp.tv_nsec;
|
|
110 |
+ }
|
|
111 |
+ else
|
|
112 |
+ {
|
|
113 |
+ cpu_time_usecs= 0;
|
|
114 |
+ }
|
|
115 |
#endif |
|
116 |
} |
|
117 |
||
118 |
@@ -341,7 +354,7 @@
|
|
119 |
finish_current_query(); |
|
120 |
} |
|
121 |
||
122 |
- enabled= (((thd)->options & OPTION_PROFILING) != 0);
|
|
123 |
+ enabled= (((thd)->options & OPTION_PROFILING) != 0) || ( thd->variables.profiling_server );
|
|
124 |
||
125 |
if (! enabled) DBUG_VOID_RETURN; |
|
126 |
||
127 |
@@ -379,7 +392,8 @@
|
|
128 |
status_change("ending", NULL, NULL, 0); |
|
129 |
||
130 |
if ((enabled) && /* ON at start? */ |
|
131 |
- ((thd->options & OPTION_PROFILING) != 0) && /* and ON at end? */
|
|
132 |
+ (((thd->options & OPTION_PROFILING) != 0) ||
|
|
133 |
+ (thd->variables.profiling_server)) && /* and ON at end? */
|
|
134 |
(current->query_source != NULL) && |
|
135 |
(! current->entries.is_empty())) |
|
136 |
{ |
|
137 |
@@ -480,6 +494,88 @@
|
|
138 |
DBUG_VOID_RETURN; |
|
139 |
} |
|
140 |
||
141 |
+bool PROFILING::enabled_getrusage()
|
|
142 |
+{
|
|
143 |
+ return thd->variables.profiling_use_getrusage;
|
|
144 |
+}
|
|
145 |
+
|
|
146 |
+/**
|
|
147 |
+ Print output for current query to file
|
|
148 |
+*/
|
|
149 |
+
|
|
150 |
+int PROFILING::print_current(IO_CACHE *log_file)
|
|
151 |
+{
|
|
152 |
+ DBUG_ENTER("PROFILING::print_current");
|
|
153 |
+ ulonglong row_number= 0;
|
|
154 |
+ char query_time_buff[22+7];
|
|
155 |
+ char query_cpu_time_buff[22+7];
|
|
156 |
+
|
|
157 |
+ QUERY_PROFILE *query;
|
|
158 |
+ /* Get current query */
|
|
159 |
+ if (current == NULL)
|
|
160 |
+ {
|
|
161 |
+ DBUG_RETURN(0);
|
|
162 |
+ }
|
|
163 |
+
|
|
164 |
+ query= current;
|
|
165 |
+
|
|
166 |
+ my_b_printf(log_file, "# PROFILE_VALUES ");
|
|
167 |
+
|
|
168 |
+ void *entry_iterator;
|
|
169 |
+ PROF_MEASUREMENT *entry, *previous= NULL, *first= NULL;
|
|
170 |
+ /* ...and for each query, go through all its state-change steps. */
|
|
171 |
+ for (entry_iterator= query->entries.new_iterator();
|
|
172 |
+ entry_iterator != NULL;
|
|
173 |
+ entry_iterator= query->entries.iterator_next(entry_iterator),
|
|
174 |
+ previous=entry, row_number++)
|
|
175 |
+ {
|
|
176 |
+ entry= query->entries.iterator_value(entry_iterator);
|
|
177 |
+
|
|
178 |
+ /* Skip the first. We count spans of fence, not fence-posts. */
|
|
179 |
+ if (previous == NULL) {first= entry; continue;}
|
|
180 |
+
|
|
181 |
+ if (thd->lex->sql_command == SQLCOM_SHOW_PROFILE)
|
|
182 |
+ {
|
|
183 |
+ /*
|
|
184 |
+ We got here via a SHOW command. That means that we stored
|
|
185 |
+ information about the query we wish to show and that isn't
|
|
186 |
+ in a WHERE clause at a higher level to filter out rows we
|
|
187 |
+ wish to exclude.
|
|
188 |
+
|
|
189 |
+ Because that functionality isn't available in the server yet,
|
|
190 |
+ we must filter here, at the wrong level. Once one can con-
|
|
191 |
+ struct where and having conditions at the SQL layer, then this
|
|
192 |
+ condition should be ripped out.
|
|
193 |
+ */
|
|
194 |
+ if (thd->lex->profile_query_id == 0) /* 0 == show final query */
|
|
195 |
+ {
|
|
196 |
+ if (query != last)
|
|
197 |
+ continue;
|
|
198 |
+ }
|
|
199 |
+ else
|
|
200 |
+ {
|
|
201 |
+ if (thd->lex->profile_query_id != query->profiling_query_id)
|
|
202 |
+ continue;
|
|
203 |
+ }
|
|
204 |
+ }
|
|
205 |
+
|
|
206 |
+ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f", (entry->time_usecs-previous->time_usecs)/(1000.0*1000));
|
|
207 |
+ snprintf(query_cpu_time_buff, sizeof(query_cpu_time_buff), "%.6f", (entry->cpu_time_usecs-previous->cpu_time_usecs)/(1000.0*1000*1000));
|
|
208 |
+ my_b_printf(log_file, "%s: %s (cpu: %s), ", previous->status, query_time_buff, query_cpu_time_buff);
|
|
209 |
+
|
|
210 |
+ }
|
|
211 |
+
|
|
212 |
+ my_b_printf(log_file, "\n");
|
|
213 |
+ if ((entry != NULL) && (first != NULL))
|
|
214 |
+ {
|
|
215 |
+ snprintf(query_time_buff, sizeof(query_time_buff), "%.6f", (entry->time_usecs-first->time_usecs)/(1000.0*1000));
|
|
216 |
+ snprintf(query_cpu_time_buff, sizeof(query_cpu_time_buff), "%.6f", (entry->cpu_time_usecs-first->cpu_time_usecs)/(1000.0*1000*1000));
|
|
217 |
+ my_b_printf(log_file, "# PROFILE_TOTALS Total: %s (cpu: %s)\n", query_time_buff, query_cpu_time_buff);
|
|
218 |
+ }
|
|
219 |
+
|
|
220 |
+ DBUG_RETURN(0);
|
|
221 |
+}
|
|
222 |
+
|
|
223 |
/** |
|
224 |
Fill the information schema table, "query_profile", as defined in show.cc . |
|
225 |
There are two ways to get to this function: Selecting from the information |
|
77
by kinoyasu
port and adjust the part of the patches to 5.1.49: But query_cache_with_comments.patch, response-time-distribution.patch, mysql_remove_eol_carret.patch, log_connection_error.patch, status_wait_query_cache_mutex.patch and sql_no_fcache.patch were not ported yet. Please port them. |
226 |
diff -ruN a/sql/sql_profile.h b/sql/sql_profile.h
|
54.2.6
by Oleg Tsarev
normalize patches |
227 |
--- a/sql/sql_profile.h 2010-07-07 03:32:17.608972002 +0400
|
228 |
+++ b/sql/sql_profile.h 2010-07-07 03:32:18.118972002 +0400
|
|
1
by kinoyasu
merge, reorder and port patches based on mysql 5.1.46 innodb 1.0.7 |
229 |
@@ -180,6 +180,7 @@
|
230 |
unsigned int line; |
|
231 |
||
232 |
double time_usecs; |
|
233 |
+ double cpu_time_usecs;
|
|
234 |
char *allocated_status_memory; |
|
235 |
||
236 |
void set_label(const char *status_arg, const char *function_arg, |
|
237 |
@@ -230,6 +231,11 @@
|
|
238 |
||
239 |
/* Show this profile. This is called by PROFILING. */ |
|
240 |
bool show(uint options); |
|
241 |
+
|
|
242 |
+public:
|
|
243 |
+
|
|
244 |
+ inline PROFILING * get_profiling() { return profiling; };
|
|
245 |
+
|
|
246 |
}; |
|
247 |
||
248 |
||
249 |
@@ -275,9 +281,11 @@
|
|
250 |
||
251 |
/* SHOW PROFILES */ |
|
252 |
bool show_profiles(); |
|
253 |
+ bool enabled_getrusage();
|
|
254 |
||
255 |
/* ... from INFORMATION_SCHEMA.PROFILING ... */ |
|
256 |
int fill_statistics_info(THD *thd, TABLE_LIST *tables, Item *cond); |
|
257 |
+ int print_current(IO_CACHE *log_file);
|
|
258 |
}; |
|
259 |
||
260 |
# endif /* HAVE_PROFILING */ |