1 /* Copyright (c) 2017, Percona and/or its affiliates. All rights reserved.
2 
3    This program is free software; you can redistribute it and/or modify
4    it under the terms of the GNU General Public License as published by
5    the Free Software Foundation; version 2 of the License.
6 
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11 
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
15 
16 #ifdef USE_PRAGMA_IMPLEMENTATION
17 #pragma implementation  // gcc: Class implementation
18 #endif
19 
20 #define MYSQL_SERVER 1
21 
22 /* The C++ file's header */
23 #include "./rdb_psi.h"
24 
25 namespace myrocks {
26 
27 /*
28   The following is needed as an argument for mysql_stage_register,
29   irrespectively of whether we're compiling with P_S or not.
30 */
31 my_core::PSI_stage_info stage_waiting_on_row_lock = {0, "Waiting for row lock",
32                                                      0};
33 
34 #ifdef HAVE_PSI_INTERFACE
35 my_core::PSI_stage_info *all_rocksdb_stages[] = {&stage_waiting_on_row_lock};
36 
37 my_core::PSI_thread_key rdb_background_psi_thread_key,
38     rdb_drop_idx_psi_thread_key, rdb_mc_psi_thread_key;
39 
40 my_core::PSI_thread_info all_rocksdb_threads[] = {
41     {&rdb_background_psi_thread_key, "background", PSI_FLAG_GLOBAL},
42     {&rdb_drop_idx_psi_thread_key, "drop index", PSI_FLAG_GLOBAL},
43     {&rdb_mc_psi_thread_key, "manual compaction", PSI_FLAG_GLOBAL},
44 };
45 
46 my_core::PSI_mutex_key rdb_psi_open_tbls_mutex_key, rdb_signal_bg_psi_mutex_key,
47     rdb_signal_drop_idx_psi_mutex_key, rdb_signal_mc_psi_mutex_key,
48     rdb_collation_data_mutex_key, rdb_mem_cmp_space_mutex_key,
49     key_mutex_tx_list, rdb_sysvars_psi_mutex_key, rdb_cfm_mutex_key,
50     rdb_sst_commit_key, rdb_block_cache_resize_mutex_key;
51 
52 my_core::PSI_mutex_info all_rocksdb_mutexes[] = {
53     {&rdb_psi_open_tbls_mutex_key, "open tables", PSI_FLAG_GLOBAL},
54     {&rdb_signal_bg_psi_mutex_key, "stop background", PSI_FLAG_GLOBAL},
55     {&rdb_signal_drop_idx_psi_mutex_key, "signal drop index", PSI_FLAG_GLOBAL},
56     {&rdb_signal_mc_psi_mutex_key, "signal manual compaction", PSI_FLAG_GLOBAL},
57     {&rdb_collation_data_mutex_key, "collation data init", PSI_FLAG_GLOBAL},
58     {&rdb_mem_cmp_space_mutex_key, "collation space char data init",
59      PSI_FLAG_GLOBAL},
60     {&key_mutex_tx_list, "tx_list", PSI_FLAG_GLOBAL},
61     {&rdb_sysvars_psi_mutex_key, "setting sysvar", PSI_FLAG_GLOBAL},
62     {&rdb_cfm_mutex_key, "column family manager", PSI_FLAG_GLOBAL},
63     {&rdb_sst_commit_key, "sst commit", PSI_FLAG_GLOBAL},
64     {&rdb_block_cache_resize_mutex_key, "resizing block cache",
65      PSI_FLAG_GLOBAL},
66 };
67 
68 my_core::PSI_rwlock_key key_rwlock_collation_exception_list,
69     key_rwlock_read_free_rpl_tables, key_rwlock_skip_unique_check_tables;
70 
71 my_core::PSI_rwlock_info all_rocksdb_rwlocks[] = {
72     {&key_rwlock_collation_exception_list, "collation_exception_list",
73      PSI_FLAG_GLOBAL},
74     {&key_rwlock_read_free_rpl_tables, "read_free_rpl_tables", PSI_FLAG_GLOBAL},
75     {&key_rwlock_skip_unique_check_tables, "skip_unique_check_tables",
76      PSI_FLAG_GLOBAL},
77 };
78 
79 my_core::PSI_cond_key rdb_signal_bg_psi_cond_key,
80     rdb_signal_drop_idx_psi_cond_key, rdb_signal_mc_psi_cond_key;
81 
82 my_core::PSI_cond_info all_rocksdb_conds[] = {
83     {&rdb_signal_bg_psi_cond_key, "cond signal background", PSI_FLAG_GLOBAL},
84     {&rdb_signal_drop_idx_psi_cond_key, "cond signal drop index",
85      PSI_FLAG_GLOBAL},
86     {&rdb_signal_mc_psi_cond_key, "cond signal manual compaction",
87      PSI_FLAG_GLOBAL},
88 };
89 
init_rocksdb_psi_keys()90 void init_rocksdb_psi_keys() {
91   const char *const category = "rocksdb";
92   int count;
93 
94   count = array_elements(all_rocksdb_mutexes);
95   mysql_mutex_register(category, all_rocksdb_mutexes, count);
96 
97   count = array_elements(all_rocksdb_rwlocks);
98   mysql_rwlock_register(category, all_rocksdb_rwlocks, count);
99 
100   count = array_elements(all_rocksdb_conds);
101   // TODO(jay) Disabling PFS for conditions due to the bug
102   // https://github.com/MySQLOnRocksDB/mysql-5.6/issues/92
103   // PSI_server->register_cond(category, all_rocksdb_conds, count);
104 
105   count = array_elements(all_rocksdb_stages);
106   mysql_stage_register(category, all_rocksdb_stages, count);
107 
108   count = array_elements(all_rocksdb_threads);
109   mysql_thread_register(category, all_rocksdb_threads, count);
110 }
111 #else   // HAVE_PSI_INTERFACE
init_rocksdb_psi_keys()112 void init_rocksdb_psi_keys() {}
113 #endif  // HAVE_PSI_INTERFACE
114 
115 }  // namespace myrocks
116