Skip to content

Commit 7f1c5f9

Browse files
committed
WL#5766 : PERFORMANCE SCHEMA, stored programs instrumentation.
Details: - 4th round of review comment from Marc.
1 parent 5ac264b commit 7f1c5f9

File tree

7 files changed

+63
-33
lines changed

7 files changed

+63
-33
lines changed

include/mysql/psi/mysql_sp.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ enum enum_sp_object_type
7070
SP_OBJECT_TYPE_PROCEDURE= 3,
7171
SP_OBJECT_TYPE_TABLE= 4,
7272
SP_OBJECT_TYPE_TRIGGER= 5,
73-
SP_OBJECT_TYPE_TEMPORARY_TABLE= 6
73+
SP_OBJECT_TYPE_TEMPORARY_TABLE= 7,
74+
SP_OBJECT_TYPE_NONE= 7
7475
};
7576

7677
static inline struct PSI_sp_locker*

storage/perfschema/pfs.cc

+25-15
Original file line numberDiff line numberDiff line change
@@ -4555,12 +4555,18 @@ pfs_get_thread_statement_locker_v1(PSI_statement_locker_state *state,
45554555
PFS_program *parent_sp= reinterpret_cast<PFS_program*>(sp_share);
45564556
pfs->m_sp_type= parent_sp->m_type;
45574557
memcpy(pfs->m_schema_name, parent_sp->m_schema_name,
4558-
parent_sp->m_schema_name_length);
4559-
pfs->m_schema_name_length= parent_sp->m_schema_name_length;
4558+
parent_sp->m_schema_name_length);
4559+
pfs->m_schema_name_length= parent_sp->m_schema_name_length;
45604560
memcpy(pfs->m_object_name, parent_sp->m_object_name,
45614561
parent_sp->m_object_name_length);
4562-
pfs->m_object_name_length= parent_sp->m_object_name_length;
4563-
}
4562+
pfs->m_object_name_length= parent_sp->m_object_name_length;
4563+
}
4564+
else
4565+
{
4566+
pfs->m_sp_type= OBJECT_TYPE_NONE;
4567+
pfs->m_schema_name_length= 0;
4568+
pfs->m_object_name_length= 0;
4569+
}
45644570

45654571
state->m_statement= pfs;
45664572
flags|= STATE_FLAG_EVENT;
@@ -5153,28 +5159,32 @@ void pfs_release_sp_share_v1(PSI_sp_share* sp_share)
51535159

51545160
PSI_sp_locker* pfs_start_sp_v1(PSI_sp_locker_state *state, PSI_sp_share *sp_share)
51555161
{
5156-
PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
5157-
if (unlikely(pfs_thread == NULL))
5162+
DBUG_ASSERT(state != NULL);
5163+
if (! flag_global_instrumentation)
51585164
return NULL;
51595165

5160-
PFS_program *pfs_program= reinterpret_cast<PFS_program*>(sp_share);
5166+
if (flag_thread_instrumentation)
5167+
{
5168+
PFS_thread *pfs_thread= my_pthread_get_THR_PFS();
5169+
if (unlikely(pfs_thread == NULL))
5170+
return NULL;
5171+
}
5172+
51615173
/*
51625174
sp share might be null in case when stat array is full and no new
51635175
stored program stats are being inserted into it.
51645176
*/
5177+
PFS_program *pfs_program= reinterpret_cast<PFS_program*>(sp_share);
51655178
if (pfs_program == NULL || !pfs_program->m_enabled)
51665179
return NULL;
51675180

5168-
state->m_thread= reinterpret_cast<PSI_thread *> (pfs_thread);
5169-
5170-
ulonglong timer_start= 0;
5181+
state->m_flags= 0;
51715182

51725183
if(pfs_program->m_timed)
51735184
{
5174-
state->m_flags |= STATE_FLAG_TIMED;
5175-
timer_start= get_timer_raw_value_and_function(statement_timer,
5185+
state->m_flags|= STATE_FLAG_TIMED;
5186+
state->m_timer_start= get_timer_raw_value_and_function(statement_timer,
51765187
& state->m_timer);
5177-
state->m_timer_start= timer_start;
51785188
}
51795189

51805190
state->m_sp_share= sp_share;
@@ -5187,8 +5197,8 @@ void pfs_end_sp_v1(PSI_sp_locker *locker)
51875197
PSI_sp_locker_state *state= reinterpret_cast<PSI_sp_locker_state*> (locker);
51885198
DBUG_ASSERT(state != NULL);
51895199

5190-
ulonglong timer_end= 0;
5191-
ulonglong wait_time= 0;
5200+
ulonglong timer_end;
5201+
ulonglong wait_time;
51925202

51935203
PFS_program *pfs_program= reinterpret_cast<PFS_program *>(state->m_sp_share);
51945204
PFS_sp_stat *stat= &pfs_program->m_sp_stat;

storage/perfschema/pfs_column_types.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ enum enum_object_type
191191
OBJECT_TYPE_PROCEDURE= 3,
192192
OBJECT_TYPE_TABLE= 4,
193193
OBJECT_TYPE_TRIGGER= 5,
194-
OBJECT_TYPE_TEMPORARY_TABLE= 6
194+
OBJECT_TYPE_TEMPORARY_TABLE= 6,
195+
OBJECT_TYPE_NONE= 7
195196
};
196197
/** Integer, first value of @sa enum_object_type. */
197198
#define FIRST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_EVENT))
198199
/** Integer, last value of @sa enum_object_type. */
199-
#define LAST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_TEMPORARY_TABLE))
200+
#define LAST_OBJECT_TYPE (static_cast<int> (OBJECT_TYPE_NONE))
200201
/** Integer, number of values of @sa enum_object_type. */
201202
#define COUNT_OBJECT_TYPE (LAST_OBJECT_TYPE - FIRST_OBJECT_TYPE + 1)
202203

storage/perfschema/pfs_program.cc

+27-9
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,18 @@ bool flag_programs= true;
3838
/** Current index in Stat array where new record is to be inserted. */
3939
volatile uint32 program_index= 0;
4040

41+
/** Max size of the program array. */
4142
ulong program_max= 0;
43+
/** Number of stored program instanes lost. */
4244
ulong program_lost= 0;
45+
/** True when program array is full. */
46+
bool program_full;
4347

4448
LF_HASH program_hash;
4549
static bool program_hash_inited= false;
4650

4751
/**
48-
Initialize table EVENTS_STATEMENTS_SUMMARY_BY_ROUTINE.
52+
Initialize table EVENTS_STATEMENTS_SUMMARY_BY_PROGRAM.
4953
@param param performance schema sizing
5054
*/
5155
int init_program(const PFS_global_param *param)
@@ -56,6 +60,7 @@ int init_program(const PFS_global_param *param)
5660
*/
5761
program_max= param->m_program_sizing;
5862
program_lost= 0;
63+
program_full= false;
5964

6065
if (program_max == 0)
6166
return 0;
@@ -202,10 +207,18 @@ find_or_create_program(PFS_thread *thread,
202207
const char *schema_name,
203208
uint schema_name_length)
204209
{
210+
bool is_enabled, is_timed;
211+
205212
if (program_array == NULL || program_max == 0 ||
206213
object_name_length ==0 || schema_name_length == 0)
207214
return NULL;
208215

216+
if(program_full)
217+
{
218+
program_lost++;
219+
return NULL;
220+
}
221+
209222
LF_PINS *pins= get_program_hash_pins(thread);
210223
if (unlikely(pins == NULL))
211224
return NULL;
@@ -239,6 +252,15 @@ find_or_create_program(PFS_thread *thread,
239252

240253
lf_hash_search_unpin(pins);
241254

255+
/*
256+
First time while inserting this record to program array we need to
257+
find out if it is enabled and timed.
258+
*/
259+
lookup_setup_object(thread, object_type,
260+
schema_name, schema_name_length,
261+
object_name, object_name_length,
262+
&is_enabled, &is_timed);
263+
242264
/* Else create a new record in program stat array. */
243265
while (++attempts <= program_max)
244266
{
@@ -258,15 +280,9 @@ find_or_create_program(PFS_thread *thread,
258280
pfs->m_object_name_length= object_name_length;
259281
pfs->m_schema_name= pfs->m_object_name + object_name_length + 1;
260282
pfs->m_schema_name_length= schema_name_length;
283+
pfs->m_enabled= is_enabled;
284+
pfs->m_timed= is_timed;
261285

262-
/*
263-
First time while inserting this record to program array we need to
264-
find out if it is enabled and timed.
265-
*/
266-
lookup_setup_object(thread, pfs->m_type,
267-
pfs->m_schema_name, pfs->m_schema_name_length,
268-
pfs->m_object_name, pfs->m_object_name_length,
269-
&pfs->m_enabled, &pfs->m_timed);
270286

271287
/* Insert this record. */
272288
int res= lf_hash_insert(&program_hash, pins, &pfs);
@@ -297,6 +313,7 @@ find_or_create_program(PFS_thread *thread,
297313
}
298314
}
299315
program_lost++;
316+
program_full= true;
300317
return NULL;
301318
}
302319

@@ -330,6 +347,7 @@ void drop_program(PFS_thread *thread,
330347
lf_hash_delete(&program_hash, pins,
331348
key.m_hash_key, key.m_key_length);
332349
pfs->m_lock.allocated_to_free();
350+
program_full= false;
333351
}
334352

335353
lf_hash_search_unpin(pins);

storage/perfschema/pfs_program.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
along with this program; if not, write to the Free Software Foundation,
1414
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
1515

16-
#ifndef PFS_ROUTINE_H
17-
#define PFS_ROUTINE_H
16+
#ifndef PFS_PROGRAM_H
17+
#define PFS_PROGRAM_H
1818

1919
/**
2020
@file storage/perfschema/pfs_program.h
@@ -46,7 +46,7 @@ struct PFS_program_key
4646
uint m_key_length;
4747
};
4848

49-
struct PFS_program : public PFS_instr
49+
struct PFS_ALIGNED PFS_program : public PFS_instr
5050
{
5151
/** Object type. */
5252
enum_object_type m_type;

storage/perfschema/table_esms_by_program.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
/**
1717
@file storage/perfschema/table_esms_by_program.cc
18-
Table EVENTS_STATEMENTS_SUMMARY_BY_ROUTINE (implementation).
18+
Table EVENTS_STATEMENTS_SUMMARY_BY_PROGRAM (implementation).
1919
*/
2020

2121
#include "my_global.h"

storage/perfschema/table_esms_by_program.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
along with this program; if not, write to the Free Software
1414
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
1515

16-
#ifndef TABLE_ESMS_BY_ROUTINE_H
17-
#define TABLE_ESMS_BY_ROUTINE_H
16+
#ifndef TABLE_ESMS_BY_PROGRAM_H
17+
#define TABLE_ESMS_BY_PROGRAM_H
1818

1919
/**
2020
@file storage/perfschema/table_esms_by_program.h

0 commit comments

Comments
 (0)