1 /* Copyright (c) 2011, 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_MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME_H
24 #define TABLE_MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_mems_by_user_by_event_name.h
28   Table MEMORY_SUMMARY_BY_USER_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_user.h"
35 #include "table_helper.h"
36 
37 /**
38   @addtogroup Performance_schema_tables
39   @{
40 */
41 
42 /** A row of PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME. */
43 struct row_mems_by_user_by_event_name
44 {
45   /** Column USER. */
46   PFS_user_row m_user;
47   /** Column EVENT_NAME. */
48   PFS_event_name_row m_event_name;
49   /** Columns COUNT_ALLOC, ... */
50   PFS_memory_stat_row m_stat;
51 };
52 
53 /**
54   Position of a cursor on
55   PERFORMANCE_SCHEMA.EVENTS_MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME.
56   Index 1 on user (0 based)
57   Index 2 on memory class (1 based)
58 */
59 struct pos_mems_by_user_by_event_name
60 : public PFS_double_index
61 {
pos_mems_by_user_by_event_namepos_mems_by_user_by_event_name62   pos_mems_by_user_by_event_name()
63     : PFS_double_index(0, 1)
64   {}
65 
resetpos_mems_by_user_by_event_name66   inline void reset(void)
67   {
68     m_index_1= 0;
69     m_index_2= 1;
70   }
71 
next_userpos_mems_by_user_by_event_name72   inline void next_user(void)
73   {
74     m_index_1++;
75     m_index_2= 1;
76   }
77 
next_classpos_mems_by_user_by_event_name78   inline void next_class(void)
79   {
80     m_index_2++;
81   }
82 };
83 
84 /** Table PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME. */
85 class table_mems_by_user_by_event_name : public PFS_engine_table
86 {
87 public:
88   /** Table share */
89   static PFS_engine_table_share m_share;
90   static PFS_engine_table* create();
91   static int delete_all_rows();
92   static ha_rows get_row_count();
93 
94   virtual int rnd_next();
95   virtual int rnd_pos(const void *pos);
96   virtual void reset_position(void);
97 
98 private:
99   virtual int read_row_values(TABLE *table,
100                               unsigned char *buf,
101                               Field **fields,
102                               bool read_all);
103 
104   table_mems_by_user_by_event_name();
105 
106 public:
~table_mems_by_user_by_event_name()107   ~table_mems_by_user_by_event_name()
108   {}
109 
110 private:
111   void make_row(PFS_user *user, PFS_memory_class *klass);
112 
113   /** Table share lock. */
114   static THR_LOCK m_table_lock;
115   /** Fields definition. */
116   static TABLE_FIELD_DEF m_field_def;
117 
118   /** Current row. */
119   row_mems_by_user_by_event_name m_row;
120   /** True is the current row exists. */
121   bool m_row_exists;
122   /** Current position. */
123   pos_mems_by_user_by_event_name m_pos;
124   /** Next position. */
125   pos_mems_by_user_by_event_name m_next_pos;
126 };
127 
128 /** @} */
129 #endif
130