~percona-dev/percona-server/release-5.1.53-12-for_xtrabackup

« back to all changes in this revision

Viewing changes to response-time-distribution.patch

  • Committer: alexey.kopytov
  • Date: 2010-12-15 18:11:11 UTC
  • mfrom: (164.2.9 percona-server)
  • Revision ID: alexey.kopytov@test3.percona.com-20101215181111-a1gk67dvmzfz2wmc
Automerge from release-5.1.53.

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
diff -ruN a/sql/mysql_priv.h b/sql/mysql_priv.h
111
111
--- a/sql/mysql_priv.h  2010-11-01 08:43:57.000000000 +0000
112
112
+++ b/sql/mysql_priv.h  2010-11-01 08:52:40.000000000 +0000
113
 
@@ -2091,6 +2091,8 @@
 
113
@@ -2091,6 +2091,11 @@
114
114
 extern my_bool opt_query_cache_strip_comments;
115
115
 extern my_bool opt_use_global_long_query_time;
116
116
 extern my_bool opt_slow_query_log_microseconds_timestamp;
 
117
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
117
118
+extern ulong   opt_query_response_time_range_base;
118
119
+extern my_bool opt_enable_query_response_time_stats;
 
120
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
121
+extern SHOW_COMP_OPTION have_response_time_distribution;
119
122
 extern my_bool sp_automatic_privileges, opt_noacl;
120
123
 extern my_bool opt_old_style_user_limits, trust_function_creators;
121
124
 extern uint opt_crash_binlog_innodb;
122
125
diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc
123
126
--- a/sql/mysqld.cc     2010-11-01 08:43:57.000000000 +0000
124
127
+++ b/sql/mysqld.cc     2010-11-01 08:52:40.000000000 +0000
125
 
@@ -32,6 +32,8 @@
 
128
@@ -32,6 +32,7 @@
126
129
 
127
130
 #include "rpl_injector.h"
128
131
 
129
132
+#include "query_response_time.h"
130
 
+
131
133
 #ifdef HAVE_SYS_PRCTL_H
132
134
 #include <sys/prctl.h>
133
135
 #endif
134
 
@@ -530,6 +532,8 @@
 
136
@@ -530,6 +531,10 @@
135
137
 my_bool opt_query_cache_strip_comments = 0;
136
138
 my_bool opt_use_global_long_query_time= 0;
137
139
 my_bool opt_slow_query_log_microseconds_timestamp= 0;
 
140
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
138
141
+ulong   opt_query_response_time_range_base  = QRT_DEFAULT_BASE;
139
142
+my_bool opt_enable_query_response_time_stats= 0;
 
143
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
140
144
 my_bool lower_case_file_system= 0;
141
145
 my_bool opt_large_pages= 0;
142
146
 my_bool opt_myisam_use_mmap= 0;
143
 
@@ -1385,6 +1389,7 @@
 
147
@@ -675,6 +680,7 @@
 
148
 MY_LOCALE *my_default_lc_time_names;
 
149
 
 
150
 SHOW_COMP_OPTION have_ssl, have_symlink, have_dlopen, have_query_cache;
 
151
+SHOW_COMP_OPTION have_response_time_distribution;
 
152
 SHOW_COMP_OPTION have_geometry, have_rtree_keys;
 
153
 SHOW_COMP_OPTION have_crypt, have_compress;
 
154
 SHOW_COMP_OPTION have_community_features;
 
155
@@ -1385,6 +1391,9 @@
144
156
   free_global_thread_stats();
145
157
   free_global_table_stats();
146
158
   free_global_index_stats();
 
159
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
147
160
+  query_response_time_free();
 
161
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
148
162
 #ifdef HAVE_REPLICATION
149
163
   end_slave_list();
150
164
 #endif
151
 
@@ -4087,6 +4092,7 @@
 
165
@@ -4087,6 +4096,9 @@
152
166
 
153
167
   init_global_table_stats();
154
168
   init_global_index_stats();
 
169
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
155
170
+  query_response_time_init();
 
171
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
156
172
 
157
173
   /* We have to initialize the storage engines before CSV logging */
158
174
   if (ha_init())
159
 
@@ -5900,6 +5906,8 @@
 
175
@@ -5900,6 +5912,10 @@
160
176
   OPT_USE_GLOBAL_LONG_QUERY_TIME,
161
177
   OPT_USE_GLOBAL_LOG_SLOW_CONTROL,
162
178
   OPT_SLOW_QUERY_LOG_MICROSECONDS_TIMESTAMP,
 
179
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
163
180
+  OPT_QRT_RANGE_BASE,
164
181
+  OPT_ENABLE_QRT_STATS,
 
182
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
165
183
   OPT_IGNORE_BUILTIN_INNODB,
166
184
   OPT_BINLOG_DIRECT_NON_TRANS_UPDATE,
167
185
   OPT_DEFAULT_CHARACTER_SET_OLD
168
 
@@ -6969,6 +6977,21 @@
 
186
@@ -6969,6 +6985,23 @@
169
187
    "Use microsecond time's precision in slow query log",
170
188
    (uchar**) &opt_slow_query_log_microseconds_timestamp, (uchar**) &opt_slow_query_log_microseconds_timestamp,
171
189
    0, GET_BOOL, REQUIRED_ARG, 0, 0, 1, 0, 1, 0},
 
190
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
172
191
+  {"query_response_time_range_base", OPT_QRT_RANGE_BASE,
173
192
+     "Select base of log for query_response_time ranges. WARNING: variable change affect only after flush",
174
193
+   (uchar**) &opt_query_response_time_range_base, (uchar**) &opt_query_response_time_range_base,
184
203
+   "Enable or disable query response time statisics collecting",
185
204
+   (uchar**) &opt_enable_query_response_time_stats, (uchar**) &opt_enable_query_response_time_stats,
186
205
+   0, GET_BOOL, REQUIRED_ARG, 0, 0, 1, 0, 1, 0},
 
206
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
187
207
   {"lower_case_table_names", OPT_LOWER_CASE_TABLE_NAMES,
188
208
    "If set to 1, table names are stored in lowercase on disk and table names "
189
209
    "will be case-insensitive.  Should be set to 2 if you are using a case-"
 
210
@@ -8183,6 +8216,11 @@
 
211
 #else
 
212
   have_query_cache=SHOW_OPTION_NO;
 
213
 #endif
 
214
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
 
215
+  have_response_time_distribution= SHOW_OPTION_YES;
 
216
+#else /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
217
+  have_response_time_distribution= SHOW_OPTION_NO;
 
218
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
219
 #ifdef HAVE_SPATIAL
 
220
   have_geometry=SHOW_OPTION_YES;
 
221
 #else
190
222
diff -ruN a/sql/query_response_time.cc b/sql/query_response_time.cc
191
223
--- a/sql/query_response_time.cc        1970-01-01 00:00:00.000000000 +0000
192
224
+++ b/sql/query_response_time.cc        2010-11-02 15:34:52.000000000 +0000
193
 
@@ -0,0 +1,367 @@
 
225
@@ -0,0 +1,369 @@
194
226
+#ifdef __FreeBSD__
195
227
+#include <sys/types.h>
196
228
+#include <machine/atomic.h>
197
229
+#endif // __FreeBSD__
198
230
+#include "my_global.h"
 
231
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
199
232
+#include "mysql_priv.h"
200
233
+#include "mysql_com.h"
201
234
+#include "rpl_tblmap.h"
558
591
+{
559
592
+  return query_response_time::g_collector.fill(thd,tables,cond);
560
593
+}
 
594
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
561
595
diff -ruN a/sql/query_response_time.h b/sql/query_response_time.h
562
596
--- a/sql/query_response_time.h 1970-01-01 00:00:00.000000000 +0000
563
597
+++ b/sql/query_response_time.h 2010-11-01 08:52:40.000000000 +0000
564
 
@@ -0,0 +1,69 @@
 
598
@@ -0,0 +1,71 @@
565
599
+#ifndef QUERY_RESPONSE_TIME_H
566
600
+#define QUERY_RESPONSE_TIME_H
567
601
+
624
658
+
625
659
+extern ST_SCHEMA_TABLE query_response_time_table;
626
660
+
 
661
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
627
662
+extern void query_response_time_init   ();
628
663
+extern void query_response_time_free   ();
629
664
+extern void query_response_time_flush  ();
630
665
+extern void query_response_time_collect(ulonglong query_time);
631
666
+extern int  query_response_time_fill   (THD* thd, TABLE_LIST *tables, COND *cond);
 
667
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
632
668
+
633
669
+#endif // QUERY_RESPONSE_TIME_H
634
670
diff -ruN a/sql/set_var.cc b/sql/set_var.cc
635
671
--- a/sql/set_var.cc    2010-11-01 08:43:57.000000000 +0000
636
672
+++ b/sql/set_var.cc    2010-11-01 08:52:40.000000000 +0000
637
 
@@ -1006,6 +1006,10 @@
 
673
@@ -1006,6 +1006,14 @@
638
674
 static sys_var_use_global_long_query_time sys_use_global_long_query_time;
639
675
 static sys_var_bool_ptr       sys_slow_query_log_microseconds_timestamp(&vars, "slow_query_log_microseconds_timestamp",
640
676
                                                        &opt_slow_query_log_microseconds_timestamp);
 
677
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
641
678
+static sys_var_bool_ptr       sys_enable_query_response_time_stats(&vars, "enable_query_response_time_stats",
642
679
+                                                       &opt_enable_query_response_time_stats);
643
680
+static sys_var_long_ptr       sys_query_response_time_range_base(&vars, "query_response_time_range_base",
644
681
+                                                      &opt_query_response_time_range_base);
 
682
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
683
+static sys_var_have_variable sys_have_response_time_distribution(&vars, "have_response_time_distribution",
 
684
+                                                       &have_response_time_distribution);
645
685
 /* Synonym of "slow_query_log" for consistency with SHOW VARIABLES output */
646
686
 static sys_var_log_state sys_var_log_slow(&vars, "log_slow_queries",
647
687
                                           &opt_slow_log, QUERY_LOG_SLOW);
656
696
 
657
697
 /**
658
698
   @defgroup Runtime_Environment Runtime Environment
659
 
@@ -1750,23 +1751,31 @@
 
699
@@ -1750,23 +1751,37 @@
660
700
     Do not log administrative statements unless the appropriate option is
661
701
     set.
662
702
   */
663
 
-  if (thd->enable_slow_log)
 
703
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
664
704
+  if (opt_enable_query_response_time_stats || thd->enable_slow_log)
 
705
+#else /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
706
   if (thd->enable_slow_log)
 
707
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
665
708
   {
666
709
-    ulonglong end_utime_of_query= thd->current_utime();
667
710
-    thd_proc_info(thd, "logging slow query");
675
718
-        thd->examined_row_count >= thd->variables.min_examined_row_limit)
676
719
+    ulonglong end_utime_of_query   = thd->current_utime();
677
720
+    ulonglong query_execution_time = end_utime_of_query - thd->utime_after_lock;
 
721
+    #ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
678
722
+    if(opt_enable_query_response_time_stats)
679
723
+    {
680
724
+      query_response_time_collect(query_execution_time);
681
725
+    }
 
726
+    #endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
682
727
+    if (thd->enable_slow_log)
683
728
     {
684
729
       thd_proc_info(thd, "logging slow query");
702
747
     }
703
748
   }
704
749
   DBUG_VOID_RETURN;
705
 
@@ -1891,6 +1900,7 @@
 
750
@@ -1891,6 +1906,7 @@
706
751
   case SCH_CHARSETS:
707
752
   case SCH_ENGINES:
708
753
   case SCH_COLLATIONS:
710
755
   case SCH_COLLATION_CHARACTER_SET_APPLICABILITY:
711
756
   case SCH_USER_PRIVILEGES:
712
757
   case SCH_SCHEMA_PRIVILEGES:
713
 
@@ -7234,6 +7244,10 @@
 
758
@@ -7234,6 +7250,12 @@
714
759
     init_global_index_stats();
715
760
     pthread_mutex_unlock(&LOCK_global_index_stats);
716
761
   }
 
762
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
717
763
+  if (options & REFRESH_QUERY_RESPONSE_TIME)
718
764
+  {
719
765
+    query_response_time_flush();
720
766
+  }
 
767
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
721
768
   if (options & (REFRESH_USER_STATS | REFRESH_CLIENT_STATS | REFRESH_THREAD_STATS))
722
769
   {
723
770
     pthread_mutex_lock(&LOCK_global_user_client_stats);
732
779
 #include "debug_sync.h"
733
780
 
734
781
 #define STR_OR_NIL(S) ((S) ? (S) : "<nil>")
735
 
@@ -7467,6 +7468,14 @@
 
782
@@ -7467,6 +7468,13 @@
736
783
 
737
784
 */
738
785
 
743
790
+    {"total",  QRT_TIME_STRING_LENGTH,     MYSQL_TYPE_STRING,  0, 0,            "", SKIP_OPEN_TABLE },
744
791
+    {0,       0,                           MYSQL_TYPE_STRING,  0, 0,             0, SKIP_OPEN_TABLE }
745
792
+  };
746
 
+
747
793
 ST_SCHEMA_TABLE schema_tables[]=
748
794
 {
749
795
   {"CHARACTER_SETS", charsets_fields_info, create_schema_table, 
750
 
@@ -7521,6 +7530,8 @@
 
796
@@ -7521,6 +7529,13 @@
751
797
    1, 9, 0, OPEN_TABLE_ONLY},
752
798
   {"ROUTINES", proc_fields_info, create_schema_table, 
753
799
    fill_schema_proc, make_proc_old_format, 0, -1, -1, 0, 0},
 
800
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
754
801
+  {"QUERY_RESPONSE_TIME", query_response_time_fields_info, create_schema_table, 
755
802
+   query_response_time_fill, make_old_format, 0, -1, -1, 0, 0},
 
803
+#else /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
804
+  {"QUERY_RESPONSE_TIME", query_response_time_fields_info, create_schema_table, 
 
805
+   0, make_old_format, 0, -1, -1, 0, 0},
 
806
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
756
807
   {"SCHEMATA", schema_fields_info, create_schema_table,
757
808
    fill_schema_schemata, make_schemata_old_format, 0, 1, -1, 0, 0},
758
809
   {"SCHEMA_PRIVILEGES", schema_privileges_fields_info, create_schema_table,
767
818
 %token  QUICK
768
819
 %token  RANGE_SYM                     /* SQL-2003-R */
769
820
 %token  READS_SYM                     /* SQL-2003-R */
770
 
@@ -10396,6 +10397,13 @@
 
821
@@ -10396,6 +10397,15 @@
771
822
            if (prepare_schema_table(YYTHD, lex, 0, SCH_INDEX_STATS))
772
823
              MYSQL_YYABORT;
773
824
           }
774
825
+        | QUERY_RESPONSE_TIME_SYM wild_and_where
775
826
+         {
 
827
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
776
828
+           LEX *lex= Lex;
777
829
+           lex->sql_command= SQLCOM_SELECT;
778
830
+           if (prepare_schema_table(YYTHD, lex, 0, SCH_QUERY_RESPONSE_TIME))
779
831
+             MYSQL_YYABORT;      
 
832
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
780
833
+         }
781
834
         | CREATE PROCEDURE sp_name
782
835
           {
783
836
             LEX *lex= Lex;
784
 
@@ -10616,6 +10624,8 @@
 
837
@@ -10616,6 +10626,12 @@
785
838
           { Lex->type|= REFRESH_TABLE_STATS; }
786
839
         | INDEX_STATS_SYM
787
840
           { Lex->type|= REFRESH_INDEX_STATS; }
788
841
+        | QUERY_RESPONSE_TIME_SYM
789
 
+          { Lex->type|= REFRESH_QUERY_RESPONSE_TIME; }
 
842
+          { 
 
843
+#ifdef HAVE_RESPONSE_TIME_DISTRIBUTION
 
844
+            Lex->type|= REFRESH_QUERY_RESPONSE_TIME; 
 
845
+#endif /* HAVE_RESPONSE_TIME_DISTRIBUTION */
 
846
+          }
790
847
         | MASTER_SYM
791
848
           { Lex->type|= REFRESH_MASTER; }
792
849
         | DES_KEY_FILE
793
 
@@ -11895,6 +11905,7 @@
 
850
@@ -11895,6 +11911,7 @@
794
851
         | PROFILES_SYM             {}
795
852
         | QUARTER_SYM              {}
796
853
         | QUERY_SYM                {}
809
866
   SCH_SCHEMATA,
810
867
   SCH_SCHEMA_PRIVILEGES,
811
868
   SCH_SESSION_STATUS,
 
869
diff -ruN a/configure.in b/configure.in
 
870
--- a/configure.in      2010-12-07 19:19:42.000000000 +0300
 
871
+++ b/configure.in      2010-12-07 19:21:39.000000000 +0300
 
872
@@ -2718,7 +2718,16 @@
 
873
 AC_SUBST(readline_link)
 
874
 AC_SUBST(readline_h_ln_cmd)
 
875
 
 
876
+AC_ARG_WITH(response_time_distribution,
 
877
+    AC_HELP_STRING([--without-response_time_distribution],[Disable response_time_distribution feature.]),
 
878
+    [with_response_time_distribution=$withval],
 
879
+    [with_response_time_distribution=yes]
 
880
+)
 
881
 
 
882
+if test "$with_response_time_distribution" = "yes"
 
883
+then
 
884
+  AC_DEFINE([HAVE_RESPONSE_TIME_DISTRIBUTION], [1], [If we want to have response_time_distribution])
 
885
+fi
 
886
 
 
887
 # Include man pages, if desired, adapted to the configured parts.
 
888
 if test X"$with_man" = Xyes