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_BY_THREAD_BY_EVENT_NAME_H
24 #define TABLE_EWS_BY_THREAD_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_ews_by_thread_by_event_name.h
28   Table EVENTS_WAITS_SUMMARY_BY_THREAD_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_BY_THREAD_BY_EVENT_NAME.
45 */
46 struct row_ews_by_thread_by_event_name
47 {
48   /** Column THREAD_ID. */
49   ulonglong m_thread_internal_id;
50   /** Column EVENT_NAME. */
51   PFS_event_name_row m_event_name;
52   /** Columns COUNT_STAR, SUM/MIN/AVG/MAX TIMER_WAIT. */
53   PFS_stat_row m_stat;
54 };
55 
56 /**
57   Position of a cursor on
58   PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME.
59   Index 1 on thread (0 based)
60   Index 2 on instrument view
61   Index 3 on instrument class (1 based)
62 */
63 struct pos_ews_by_thread_by_event_name
64 : public PFS_triple_index, public PFS_instrument_view_constants
65 {
pos_ews_by_thread_by_event_namepos_ews_by_thread_by_event_name66   pos_ews_by_thread_by_event_name()
67     : PFS_triple_index(0, FIRST_VIEW, 1)
68   {}
69 
resetpos_ews_by_thread_by_event_name70   inline void reset(void)
71   {
72     m_index_1= 0;
73     m_index_2= FIRST_VIEW;
74     m_index_3= 1;
75   }
76 
next_threadpos_ews_by_thread_by_event_name77   inline void next_thread(void)
78   {
79     m_index_1++;
80     m_index_2= FIRST_VIEW;
81     m_index_3= 1;
82   }
83 
has_more_viewpos_ews_by_thread_by_event_name84   inline bool has_more_view(void)
85   { return (m_index_2 <= LAST_VIEW); }
86 
next_viewpos_ews_by_thread_by_event_name87   inline void next_view(void)
88   {
89     m_index_2++;
90     m_index_3= 1;
91   }
92 };
93 
94 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_THREAD_BY_EVENT_NAME. */
95 class table_ews_by_thread_by_event_name : public PFS_engine_table
96 {
97 public:
98   /** Table share */
99   static PFS_engine_table_share m_share;
100   static PFS_engine_table* create();
101   static int delete_all_rows();
102   static ha_rows get_row_count();
103 
104   virtual int rnd_next();
105   virtual int rnd_pos(const void *pos);
106   virtual void reset_position(void);
107 
108 protected:
109   virtual int read_row_values(TABLE *table,
110                               unsigned char *buf,
111                               Field **fields,
112                               bool read_all);
113 
114   table_ews_by_thread_by_event_name();
115 
116 public:
~table_ews_by_thread_by_event_name()117   ~table_ews_by_thread_by_event_name()
118   {}
119 
120 protected:
121   void make_row(PFS_thread *thread, PFS_instr_class *klass);
122 
123 private:
124   /** Table share lock. */
125   static THR_LOCK m_table_lock;
126   /** Fields definition. */
127   static TABLE_FIELD_DEF m_field_def;
128 
129   /** Current row. */
130   row_ews_by_thread_by_event_name m_row;
131   /** True is the current row exists. */
132   bool m_row_exists;
133   /** Current position. */
134   pos_ews_by_thread_by_event_name m_pos;
135   /** Next position. */
136   pos_ews_by_thread_by_event_name m_next_pos;
137 };
138 
139 /** @} */
140 #endif
141