1/* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
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 as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software Foundation,
14 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
15
16#ifndef TABLE_EVENTS_STAGES_H
17#define TABLE_EVENTS_STAGES_H
18
19/**
20 @file storage/perfschema/table_events_stages.h
21 Table EVENTS_STAGES_xxx (declarations).
22*/
23
24#include "pfs_column_types.h"
25#include "pfs_engine_table.h"
26#include "pfs_events_stages.h"
27
28struct PFS_thread;
29
30/**
31 @addtogroup Performance_schema_tables
32 @{
33*/
34
35/** A row of table_events_stages_common. */
36struct row_events_stages
37{
38 /** Column THREAD_ID. */
39 ulonglong m_thread_internal_id;
40 /** Column EVENT_ID. */
41 ulonglong m_event_id;
42 /** Column END_EVENT_ID. */
43 ulonglong m_end_event_id;
44 /** Column NESTING_EVENT_ID. */
45 ulonglong m_nesting_event_id;
46 /** Column NESTING_EVENT_TYPE. */
47 enum_event_type m_nesting_event_type;
48 /** Column EVENT_NAME. */
49 const char *m_name;
50 /** Length in bytes of @c m_name. */
51 uint m_name_length;
52 /** Column TIMER_START. */
53 ulonglong m_timer_start;
54 /** Column TIMER_END. */
55 ulonglong m_timer_end;
56 /** Column TIMER_WAIT. */
57 ulonglong m_timer_wait;
58 /** Column SOURCE. */
59 char m_source[COL_SOURCE_SIZE];
60 /** Length in bytes of @c m_source. */
61 uint m_source_length;
62};
63
64/** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY. */
65struct pos_events_stages_history : public PFS_double_index
66{
67 pos_events_stages_history()
68 : PFS_double_index(0, 0)
69 {}
70
71 inline void reset(void)
72 {
73 m_index_1= 0;
74 m_index_2= 0;
75 }
76
77 inline void next_thread(void)
78 {
79 m_index_1++;
80 m_index_2= 0;
81 }
82};
83
84/**
85 Adapter, for table sharing the structure of
86 PERFORMANCE_SCHEMA.EVENTS_STAGES_CURRENT.
87*/
88class table_events_stages_common : public PFS_engine_table
89{
90protected:
91 virtual int read_row_values(TABLE *table,
92 unsigned char *buf,
93 Field **fields,
94 bool read_all);
95
96 table_events_stages_common(const PFS_engine_table_share *share, void *pos);
97
98 ~table_events_stages_common()
99 {}
100
101 void make_row(PFS_events_stages *stage);
102
103 /** Current row. */
104 row_events_stages m_row;
105 /** True if the current row exists. */
106 bool m_row_exists;
107};
108
109/** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_CURRENT. */
110class table_events_stages_current : public table_events_stages_common
111{
112public:
113 /** Table share */
114 static PFS_engine_table_share m_share;
115 static PFS_engine_table* create();
116 static int delete_all_rows();
117
118 virtual int rnd_init(bool scan);
119 virtual int rnd_next();
120 virtual int rnd_pos(const void *pos);
121 virtual void reset_position(void);
122
123protected:
124 table_events_stages_current();
125
126public:
127 ~table_events_stages_current()
128 {}
129
130private:
131 friend class table_events_stages_history;
132 friend class table_events_stages_history_long;
133
134 /** Table share lock. */
135 static THR_LOCK m_table_lock;
136
137 /** Current position. */
138 PFS_simple_index m_pos;
139 /** Next position. */
140 PFS_simple_index m_next_pos;
141};
142
143/** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY. */
144class table_events_stages_history : public table_events_stages_common
145{
146public:
147 /** Table share */
148 static PFS_engine_table_share m_share;
149 static PFS_engine_table* create();
150 static int delete_all_rows();
151
152 virtual int rnd_init(bool scan);
153 virtual int rnd_next();
154 virtual int rnd_pos(const void *pos);
155 virtual void reset_position(void);
156
157protected:
158 table_events_stages_history();
159
160public:
161 ~table_events_stages_history()
162 {}
163
164private:
165 /** Table share lock. */
166 static THR_LOCK m_table_lock;
167
168 /** Current position. */
169 pos_events_stages_history m_pos;
170 /** Next position. */
171 pos_events_stages_history m_next_pos;
172};
173
174/** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_HISTORY_LONG. */
175class table_events_stages_history_long : public table_events_stages_common
176{
177public:
178 /** Table share */
179 static PFS_engine_table_share m_share;
180 static PFS_engine_table* create();
181 static int delete_all_rows();
182
183 virtual int rnd_init(bool scan);
184 virtual int rnd_next();
185 virtual int rnd_pos(const void *pos);
186 virtual void reset_position(void);
187
188protected:
189 table_events_stages_history_long();
190
191public:
192 ~table_events_stages_history_long()
193 {}
194
195private:
196 /** Table share lock. */
197 static THR_LOCK m_table_lock;
198
199 /** Current position. */
200 PFS_simple_index m_pos;
201 /** Next position. */
202 PFS_simple_index m_next_pos;
203};
204
205/** @} */
206#endif
207