1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates.
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, version 2.0,
5   as published by the Free Software Foundation.
6 
7   This program is also distributed with certain software (including
8   but not limited to OpenSSL) that is licensed under separate terms,
9   as designated in a particular file or component or in included license
10   documentation.  The authors of MySQL hereby grant you an additional
11   permission to link the program and your derivative works with the
12   separately licensed software that they have included with MySQL.
13 
14   This program is distributed in the hope that it will be useful,
15   but WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   GNU General Public License, version 2.0, for more details.
18 
19   You should have received a copy of the GNU General Public License
20   along with this program; if not, write to the Free Software Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef PFS_EVENTS_WAITS_H
24 #define PFS_EVENTS_WAITS_H
25 
26 /**
27   @file storage/perfschema/pfs_events_waits.h
28   Events waits data structures (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_lock.h"
33 #include "pfs_events.h"
34 
35 struct PFS_mutex;
36 struct PFS_rwlock;
37 struct PFS_cond;
38 struct PFS_table;
39 struct PFS_file;
40 struct PFS_thread;
41 struct PFS_socket;
42 struct PFS_instr_class;
43 struct PFS_table_share;
44 struct PFS_account;
45 struct PFS_user;
46 struct PFS_host;
47 struct PFS_metadata_lock;
48 
49 /** Class of a wait event. */
50 enum events_waits_class
51 {
52   NO_WAIT_CLASS= 0,
53   WAIT_CLASS_MUTEX,
54   WAIT_CLASS_RWLOCK,
55   WAIT_CLASS_COND,
56   WAIT_CLASS_TABLE,
57   WAIT_CLASS_FILE,
58   WAIT_CLASS_SOCKET,
59   WAIT_CLASS_IDLE,
60   WAIT_CLASS_METADATA
61 };
62 
63 /** A wait event record. */
64 struct PFS_events_waits : public PFS_events
65 {
66   /**
67     The type of wait.
68     Readers:
69     - the consumer threads.
70     Writers:
71     - the producer threads, in the instrumentation.
72     Out of bound Writers:
73     - TRUNCATE EVENTS_WAITS_CURRENT
74     - TRUNCATE EVENTS_WAITS_HISTORY
75     - TRUNCATE EVENTS_WAITS_HISTORY_LONG
76   */
77   events_waits_class m_wait_class;
78   /** Object type */
79   enum_object_type m_object_type;
80   /** Table share, for table operations only. */
81   PFS_table_share *m_weak_table_share;
82   /** File, for file operations only. */
83   PFS_file *m_weak_file;
84   /** Socket, for socket operations only. */
85   PFS_socket *m_weak_socket;
86   /** Metadata lock, for mdl operations only. */
87   PFS_metadata_lock *m_weak_metadata_lock;
88   /** For weak pointers, target object version. */
89   uint32 m_weak_version;
90   /** Address in memory of the object instance waited on. */
91   const void *m_object_instance_addr;
92   /** Operation performed. */
93   enum_operation_type m_operation;
94   /**
95     Number of bytes/rows read/written.
96     This member is populated for FILE READ/WRITE operations, with a number of bytes.
97     This member is populated for TABLE IO operations, with a number of rows.
98   */
99   size_t m_number_of_bytes;
100   /**
101     Index used.
102     This member is populated for TABLE IO operations only.
103   */
104   uint m_index;
105   /** Flags */
106   ulong m_flags;
107 };
108 
109 /** TIMED bit in the state flags bitfield. */
110 #define STATE_FLAG_TIMED (1<<0)
111 /** THREAD bit in the state flags bitfield. */
112 #define STATE_FLAG_THREAD (1<<1)
113 /** EVENT bit in the state flags bitfield. */
114 #define STATE_FLAG_EVENT (1<<2)
115 /** DIGEST bit in the state flags bitfield. */
116 #define STATE_FLAG_DIGEST (1<<3)
117 
118 void insert_events_waits_history(PFS_thread *thread, PFS_events_waits *wait);
119 
120 void insert_events_waits_history_long(PFS_events_waits *wait);
121 
122 extern bool flag_events_waits_current;
123 extern bool flag_events_waits_history;
124 extern bool flag_events_waits_history_long;
125 extern bool flag_global_instrumentation;
126 extern bool flag_thread_instrumentation;
127 
128 extern bool events_waits_history_long_full;
129 extern PFS_ALIGNED PFS_cacheline_uint32 events_waits_history_long_index;
130 extern PFS_events_waits *events_waits_history_long_array;
131 extern ulong events_waits_history_long_size;
132 
133 int init_events_waits_history_long(uint events_waits_history_long_sizing);
134 void cleanup_events_waits_history_long();
135 
136 void reset_events_waits_current();
137 void reset_events_waits_history();
138 void reset_events_waits_history_long();
139 void reset_events_waits_by_thread();
140 void reset_events_waits_by_account();
141 void reset_events_waits_by_user();
142 void reset_events_waits_by_host();
143 void reset_events_waits_global();
144 void aggregate_account_waits(PFS_account *account);
145 void aggregate_user_waits(PFS_user *user);
146 void aggregate_host_waits(PFS_host *host);
147 
148 void reset_table_waits_by_table();
149 void reset_table_io_waits_by_table();
150 void reset_table_lock_waits_by_table();
151 void reset_table_waits_by_table_handle();
152 void reset_table_io_waits_by_table_handle();
153 void reset_table_lock_waits_by_table_handle();
154 
155 #endif
156 
157