1 /* Copyright (c) 2010, 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 TABLE_EVENTS_STAGES_H
24 #define TABLE_EVENTS_STAGES_H
25 
26 /**
27   @file storage/perfschema/table_events_stages.h
28   Table EVENTS_STAGES_xxx (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_engine_table.h"
33 #include "pfs_events_stages.h"
34 
35 struct PFS_thread;
36 
37 /**
38   @addtogroup Performance_schema_tables
39   @{
40 */
41 
42 /** A row of table_events_stages_common. */
43 struct row_events_stages
44 {
45   /** Column THREAD_ID. */
46   ulonglong m_thread_internal_id;
47   /** Column EVENT_ID. */
48   ulonglong m_event_id;
49   /** Column END_EVENT_ID. */
50   ulonglong m_end_event_id;
51   /** Column NESTING_EVENT_ID. */
52   ulonglong m_nesting_event_id;
53   /** Column NESTING_EVENT_TYPE. */
54   enum_event_type m_nesting_event_type;
55   /** Column EVENT_NAME. */
56   const char *m_name;
57   /** Length in bytes of @c m_name. */
58   uint m_name_length;
59   /** Column TIMER_START. */
60   ulonglong m_timer_start;
61   /** Column TIMER_END. */
62   ulonglong m_timer_end;
63   /** Column TIMER_WAIT. */
64   ulonglong m_timer_wait;
65   /** Column SOURCE. */
66   char m_source[COL_SOURCE_SIZE];
67   /** Length in bytes of @c m_source. */
68   uint m_source_length;
69   bool m_progress;
70   /** Column WORK_COMPLETED. */
71   ulonglong m_work_completed;
72   /** Column WORK_ESTIMATED. */
73   ulonglong m_work_estimated;
74 };
75 
76 /** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY. */
77 struct pos_events_stages_history : public PFS_double_index
78 {
pos_events_stages_historypos_events_stages_history79   pos_events_stages_history()
80     : PFS_double_index(0, 0)
81   {}
82 
resetpos_events_stages_history83   inline void reset(void)
84   {
85     m_index_1= 0;
86     m_index_2= 0;
87   }
88 
next_threadpos_events_stages_history89   inline void next_thread(void)
90   {
91     m_index_1++;
92     m_index_2= 0;
93   }
94 };
95 
96 /**
97   Adapter, for table sharing the structure of
98   PERFORMANCE_SCHEMA.EVENTS_STAGES_CURRENT.
99 */
100 class table_events_stages_common : public PFS_engine_table
101 {
102 protected:
103   virtual int read_row_values(TABLE *table,
104                               unsigned char *buf,
105                               Field **fields,
106                               bool read_all);
107 
108   table_events_stages_common(const PFS_engine_table_share *share, void *pos);
109 
~table_events_stages_common()110   ~table_events_stages_common()
111   {}
112 
113   void make_row(PFS_events_stages *stage);
114 
115   /** Current row. */
116   row_events_stages m_row;
117   /** True if the current row exists. */
118   bool m_row_exists;
119 };
120 
121 /** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_CURRENT. */
122 class table_events_stages_current : public table_events_stages_common
123 {
124 public:
125   /** Table share */
126   static PFS_engine_table_share m_share;
127   static PFS_engine_table* create();
128   static int delete_all_rows();
129   static ha_rows get_row_count();
130 
131   virtual int rnd_init(bool scan);
132   virtual int rnd_next();
133   virtual int rnd_pos(const void *pos);
134   virtual void reset_position(void);
135 
136 protected:
137   table_events_stages_current();
138 
139 public:
~table_events_stages_current()140   ~table_events_stages_current()
141   {}
142 
143 private:
144   friend class table_events_stages_history;
145   friend class table_events_stages_history_long;
146 
147   /** Table share lock. */
148   static THR_LOCK m_table_lock;
149   /**
150     Fields definition.
151     Also used by table_events_stages_history
152     and table_events_stages_history_long.
153   */
154   static TABLE_FIELD_DEF m_field_def;
155 
156   /** Current position. */
157   PFS_simple_index m_pos;
158   /** Next position. */
159   PFS_simple_index m_next_pos;
160 };
161 
162 /** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY. */
163 class table_events_stages_history : public table_events_stages_common
164 {
165 public:
166   /** Table share */
167   static PFS_engine_table_share m_share;
168   static PFS_engine_table* create();
169   static int delete_all_rows();
170   static ha_rows get_row_count();
171 
172   virtual int rnd_init(bool scan);
173   virtual int rnd_next();
174   virtual int rnd_pos(const void *pos);
175   virtual void reset_position(void);
176 
177 protected:
178   table_events_stages_history();
179 
180 public:
~table_events_stages_history()181   ~table_events_stages_history()
182   {}
183 
184 private:
185   /** Table share lock. */
186   static THR_LOCK m_table_lock;
187 
188   /** Current position. */
189   pos_events_stages_history m_pos;
190   /** Next position. */
191   pos_events_stages_history m_next_pos;
192 };
193 
194 /** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY_LONG. */
195 class table_events_stages_history_long : public table_events_stages_common
196 {
197 public:
198   /** Table share */
199   static PFS_engine_table_share m_share;
200   static PFS_engine_table* create();
201   static int delete_all_rows();
202   static ha_rows get_row_count();
203 
204   virtual int rnd_init(bool scan);
205   virtual int rnd_next();
206   virtual int rnd_pos(const void *pos);
207   virtual void reset_position(void);
208 
209 protected:
210   table_events_stages_history_long();
211 
212 public:
~table_events_stages_history_long()213   ~table_events_stages_history_long()
214   {}
215 
216 private:
217   /** Table share lock. */
218   static THR_LOCK m_table_lock;
219 
220   /** Current position. */
221   PFS_simple_index m_pos;
222   /** Next position. */
223   PFS_simple_index m_next_pos;
224 };
225 
226 /** @} */
227 #endif
228