1 /*
2 * Copyright (c) 2015, 2021, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is also distributed with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation.  The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have included with MySQL.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License, version 2.0, for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
23 * 02110-1301  USA
24 */
25 
26 #include "xpl_performance_schema.h"
27 #include "ngs/memory.h"
28 
29 
30 #ifdef HAVE_PSI_INTERFACE
31 
32 PSI_thread_key KEY_thread_x_acceptor = PSI_NOT_INSTRUMENTED;
33 PSI_thread_key KEY_thread_x_worker = PSI_NOT_INSTRUMENTED;
34 
35 static PSI_thread_info all_x_threads[] = {
36   { &KEY_thread_x_acceptor, "acceptor_network", 0 },
37   { &KEY_thread_x_worker,   "worker", 0 },
38 };
39 
40 PSI_mutex_key KEY_mutex_x_lock_list_access = PSI_NOT_INSTRUMENTED;
41 PSI_mutex_key KEY_mutex_x_scheduler_dynamic_worker_pending = PSI_NOT_INSTRUMENTED;
42 PSI_mutex_key KEY_mutex_x_scheduler_dynamic_thread_exit = PSI_NOT_INSTRUMENTED;
43 
44 static PSI_mutex_info all_x_mutexes[] = {
45   { &KEY_mutex_x_lock_list_access, "lock_list_access", 0 },
46   { &KEY_mutex_x_scheduler_dynamic_worker_pending, "scheduler_dynamic_worker_pending", 0 },
47   { &KEY_mutex_x_scheduler_dynamic_thread_exit, "scheduler_dynamic_thread_exit", 0 },
48 };
49 
50 PSI_cond_key KEY_cond_x_scheduler_dynamic_worker_pending = PSI_NOT_INSTRUMENTED;
51 PSI_cond_key KEY_cond_x_scheduler_dynamic_thread_exit = PSI_NOT_INSTRUMENTED;
52 
53 static PSI_cond_info all_x_conds[] = {
54   { &KEY_cond_x_scheduler_dynamic_worker_pending, "scheduler_dynamic_worker_pending", 0 },
55   { &KEY_cond_x_scheduler_dynamic_thread_exit, "scheduler_dynamic_thread_exit", 0 },
56 };
57 
58 
59 PSI_rwlock_key KEY_rwlock_x_client_list_clients = PSI_NOT_INSTRUMENTED;
60 
61 static PSI_rwlock_info all_x_rwlocks[] = {
62   { &KEY_rwlock_x_client_list_clients, "client_list_clients", 0 },
63 };
64 
65 
66 PSI_socket_key KEY_socket_x_tcpip = PSI_NOT_INSTRUMENTED;
67 PSI_socket_key KEY_socket_x_unix = PSI_NOT_INSTRUMENTED;
68 PSI_socket_key KEY_socket_x_client_connection = PSI_NOT_INSTRUMENTED;
69 
70 #ifdef HAVE_PSI_SOCKET_INTERFACE
71 
72 static PSI_socket_info all_x_sockets[] =
73 {
74   { &KEY_socket_x_tcpip, "tcpip_socket", 0 },
75   { &KEY_socket_x_unix, "unix_socket", 0 },
76   { &KEY_socket_x_client_connection, "client_connection", 0 },
77 
78 };
79 
80 #endif // HAVE_PSI_SOCKET_INTERFACE
81 
82 PSI_memory_key KEY_memory_x_objects = PSI_NOT_INSTRUMENTED;
83 PSI_memory_key KEY_memory_x_recv_buffer = PSI_NOT_INSTRUMENTED;
84 PSI_memory_key KEY_memory_x_send_buffer = PSI_NOT_INSTRUMENTED;
85 
86 static PSI_memory_info all_x_memory[] =
87 {
88     { &KEY_memory_x_objects, "objects", PSI_FLAG_GLOBAL },
89     { &KEY_memory_x_recv_buffer, "recv_buffer", PSI_FLAG_GLOBAL },
90     { &KEY_memory_x_send_buffer, "send_buffer", PSI_FLAG_GLOBAL },
91 };
92 
93 #endif // HAVE_PSI_INTERFACE
94 
95 
xpl_init_performance_schema()96 void xpl_init_performance_schema()
97 {
98 #ifdef HAVE_PSI_INTERFACE
99 
100   const char * const category = "mysqlx";
101 
102   mysql_thread_register(category, all_x_threads, array_elements(all_x_threads));
103   mysql_mutex_register(category, all_x_mutexes, array_elements(all_x_mutexes));
104   mysql_cond_register(category, all_x_conds, array_elements(all_x_conds));
105   mysql_rwlock_register(category, all_x_rwlocks, array_elements(all_x_rwlocks));
106   mysql_socket_register(category, all_x_sockets, array_elements(all_x_sockets));
107   mysql_memory_register(category, all_x_memory, array_elements(all_x_memory));
108 
109   ngs::x_psf_objects_key = KEY_memory_x_objects;
110 
111 #endif // HAVE_PSI_INTERFACE
112 }
113