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
21   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */
22 
23 #ifndef TABLE_EWS_GLOBAL_BY_EVENT_NAME_H
24 #define TABLE_EWS_GLOBAL_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_ews_global_by_event_name.h
28   Table EVENTS_WAITS_SUMMARY_GLOBAL_BY_EVENT_NAME (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_engine_table.h"
33 #include "pfs_instr_class.h"
34 #include "pfs_instr.h"
35 #include "table_helper.h"
36 
37 /**
38   @addtogroup Performance_schema_tables
39   @{
40 */
41 
42 /**
43   A row of table
44   PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_GLOBAL_BY_EVENT_NAME.
45 */
46 struct row_ews_global_by_event_name
47 {
48   /** Column EVENT_NAME. */
49   PFS_event_name_row m_event_name;
50   /** Columns COUNT_STAR, SUM/MIN/AVG/MAX TIMER_WAIT. */
51   PFS_stat_row m_stat;
52 };
53 
54 /**
55   Position of a cursor on
56   PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_GLOBAL_BY_EVENT_NAME.
57   Index 1 on instrument view
58   Index 2 on instrument class (1 based)
59 */
60 struct pos_ews_global_by_event_name
61 : public PFS_double_index, public PFS_instrument_view_constants
62 {
pos_ews_global_by_event_namepos_ews_global_by_event_name63   pos_ews_global_by_event_name()
64     : PFS_double_index(FIRST_VIEW, 1)
65   {}
66 
resetpos_ews_global_by_event_name67   inline void reset(void)
68   {
69     m_index_1= FIRST_VIEW;
70     m_index_2= 1;
71   }
72 
has_more_viewpos_ews_global_by_event_name73   inline bool has_more_view(void)
74   { return (m_index_1 <= LAST_VIEW); }
75 
next_viewpos_ews_global_by_event_name76   inline void next_view(void)
77   {
78     m_index_1++;
79     m_index_2= 1;
80   }
81 };
82 
83 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_GLOBAL_BY_EVENT_NAME. */
84 class table_ews_global_by_event_name : public PFS_engine_table
85 {
86 public:
87   /** Table share */
88   static PFS_engine_table_share m_share;
89   static PFS_engine_table* create();
90   static int delete_all_rows();
91   static ha_rows get_row_count();
92 
93   virtual int rnd_next();
94   virtual int rnd_pos(const void *pos);
95   virtual void reset_position(void);
96 
97 protected:
98   virtual int read_row_values(TABLE *table,
99                               unsigned char *buf,
100                               Field **fields,
101                               bool read_all);
102 
103   table_ews_global_by_event_name();
104 
105 public:
~table_ews_global_by_event_name()106   ~table_ews_global_by_event_name()
107   {}
108 
109 protected:
110   void make_mutex_row(PFS_mutex_class *klass);
111   void make_rwlock_row(PFS_rwlock_class *klass);
112   void make_cond_row(PFS_cond_class *klass);
113   void make_file_row(PFS_file_class *klass);
114   void make_table_io_row(PFS_instr_class *klass);
115   void make_table_lock_row(PFS_instr_class *klass);
116   void make_socket_row(PFS_socket_class *klass);
117   void make_idle_row(PFS_instr_class *klass);
118   void make_metadata_row(PFS_instr_class *klass);
119 
120 private:
121   /** Table share lock. */
122   static THR_LOCK m_table_lock;
123   /** Fields definition. */
124   static TABLE_FIELD_DEF m_field_def;
125 
126   /** Current row. */
127   row_ews_global_by_event_name m_row;
128   /** True is the current row exists. */
129   bool m_row_exists;
130   /** Current position. */
131   pos_ews_global_by_event_name m_pos;
132   /** Next position. */
133   pos_ews_global_by_event_name m_next_pos;
134 };
135 
136 /** @} */
137 #endif
138