SlideShare una empresa de Scribd logo
1 de 31
Georgi Kodinov
Team Lead, MySQL server general team
How to Instrument Your Code in
MySQL Performance Schema
© 2019 Oracle1
Safe harbor statement
The following is intended to outline our general product direction. It is intended for information purposes
only, and may not be incorporated into any contract. It is not a commitment to deliver any material,
code, or functionality, and should not be relied upon in making purchasing decisions.
The development, release, timing, and pricing of any features or functionality described for Oracle’s
products may change and remains at the sole discretion of Oracle Corporation.
2 © 2019 Oracle
Topics Covered
Why should I instrument my code ?
How do I go about instrumenting it ?
Mechanics of instrumentation
PERFORMANCE_SCHEMA: not just about performance
© 2019 Oracle3
Why should I instrument my code ?
• Understand what resources it uses:
• memory, locks, time, files, etc.
• More debuggable
• Provides extra insight into code operation and issues
• Expose extra volatile information to users and administrators
• Make your code more portable
© 2019 Oracle4
How do I instrument my code ?
Contribute data to the instruments provided
Future: add your own instruments
© 2019 Oracle5
Most of the times it’sTHAT easy !
#include <pthread.h>
pthread_mutex_t foo;
void do_something()
{
pthread_mutex_lock(&foo);
...
pthread_mutex_unlock(&foo);
}
#include "mysql/psi/mysql_mutex.h“
mysql_mutex_t foo;
void do_something()
{
mysql_mutex_lock(&foo);
...
mysql_mutex_unlock(&foo);
}
© 2019 Oracle6
Extra step: register your objects
#ifdef HAVE_PSI_MUTEX_INTERFACE
PSI_mutex_key mutex_key_foo = PSI_NOT_INSTRUMENTED;
static PSI_mutex_info all_mutexes[]=
{
{ &mutex_key_foo, "LOCK_foo", PSI_FLAG_SINGLETON, 0, "example doc"},
..
}
..
count = static_cast<int>(array_elements(all_mutexes));
mysql_mutex_register(“category_foo”, all_mutexes, count);
..
mysql_mutex_init(mutex_key_foo, &foo, MY_MUTEX_INIT_FAST);
#endif /* HAVE_PSI_MUTEX_INTERFACE */
© 2019 Oracle7
Instrumentation inventory: inline functions
• POSIX threads
• POSIX conditions
• POSIX mutexes
• POSIX read/write locks
• POSIX sockets
• Buffered and unbuffered file I/O
• MySQL stages
• MySQL metadata locks
mysql_thread.h
mysql_cond.h
mysql_mutex.h
mysql_rwlock.h
mysql_socket.h
mysql_file.h
mysql_stage.h
mysql_mdl.h
© 2019 Oracle8
How do I instrument my memory use ?
#include <stdlib.h>
void *foo;
void do_something()
{
foo = malloc(12);
...
free(foo);
}
#include "mysys.h“
void *foo;
void do_something()
{
foo = my_malloc(mem_key_foo, 12, MYF(0));
...
my_free(foo);
}
© 2019 Oracle9
Extra step: register your objects
#ifdef HAVE_PSI_MEMORY_INTERFACE
PSI_memory_key mem_key_foo = PSI_NOT_INSTRUMENTED;
static PSI_memory_info all_memory[] = {
{&mem_key_foo, “FOO", PSI_FLAG_ONLY_GLOBAL_STAT, 0, "example doc"}};
…
count = static_cast<int>(array_elements(all_memory));
mysql_memory_register(category, all_memory, count);
#endif /* HAVE_PSI_MEMORY_INTERFACE */
© 2019 Oracle10
Instrumentation inventory: memory
• Plugin service implemented in mysys:
my_malloc(), my_free(), my_memdup()
etc.
• Static mysys inspired library to link with
components: just my_malloc() and my_free()
include/mysql/service_mysql_alloc.h
components/library_mysys/my_memory.h
© 2019 Oracle11
Instrumenting other stuff: utility macros
#include <mysql/psi/mysql_idle.h>
…
PSI_idle_locker *m_idle_psi = NULL;
PSI_idle_locker_state m_idle_state;
…
MYSQL_START_IDLE_WAIT(m_idle_psi, &m_idle_state);
…
MYSQL_END_IDLE_WAIT(m_idle_psi);
…
© 2019 Oracle12
Instrumentation inventory: utility macros
• Transactions
• Table locks
• “System” (currently shared objects)
• Statements
• Stored programs
• Prepared statements
• MySQL stages
• Errors
• Data locks
 Idle
mysql_transaction.h
mysql_table.h
mysql_system.h
mysql_statement.h
mysql_sp.h
mysql_ps.h
mysql_stage.h
mysql_error.h
mysql_data_lock.h
mysql_idle.h
© 2019 Oracle13
Mechanics of code instrumentation
Under the hood
© 2019 Oracle14
Calling instrumentation: PSI_*_CALL macros
• Server code: direct call
• #define PSI_FILE_CALL(M) pfs_##M##_v1
• Plugins: function pointer
• #define PSI_FILE_CALL(M) psi_file_service->M
• Components: component service handle
• #define PSI_FILE_CALL(M) mysql_service_psi_file_v1->M
© 2019 Oracle15
Random thoughts on good code instrumentation
• Always release the artifacts that instruments returned via the
intended methods !
• Instrumentation can be costly !
• Consider using component infrastructure
© 2019 Oracle16
Performance Schema
Not just about performance !
© 2019 Oracle17
PERFORMANCE_SCHEMA: Not just performance !
• Started as performance instrumentation. Still does it !
• Grown into general storage for fast-changing volatile data
• System variables
• Connection attributes
• Replication, innodb state
• Now supports adding new tables from components
© 2019 Oracle18
Add a PERFORMANCE_SCHEMA table
From a component
© 2019 Oracle19
Step 1:The data
© 2019 Oracle20
Step 2: Basic table APIs
© 2019 Oracle21
Step 3: Data retrieval
© 2019 Oracle22
Step 4: Component code
© 2019 Oracle23
How it drives
© 2019 Oracle24
Let’s look at the table
© 2019 Oracle25
Where to go from here ?
• MySQL Internals Doxygen:
https://dev.mysql.com/doc/dev/mysql-
server/latest/PAGE_PFS.html
• Reference Manual:
https://dev.mysql.com/doc/refman/8.0/en/performance-
schema.html
© 2019 Oracle26
Questions And Answers
© 2019 Oracle27
Copyright © 2019 Oracle and/or its affiliates.28
Meet the MySQL Team at the Conference
Sunny Bains
Luis Soares
Kenny Gryp
Frédéric Descamps
Dimitri Kravtchuk
Ståle Deraas
Pedro Gomes
Geir HøydalsvikNorvald Ryeng
Georgi Kodinov
Join us on MySQL Community Slack
Copyright © 2019 Oracle and/or its affiliates.29
https://lefred.be/mysql-community-on-slack/
Follow us on Social Media
Copyright © 2019 Oracle and/or its affiliates.30
https://www.facebook.com/mysql
https://twitter.com/mysql
https://www.linkedin.com/company/mysql
Thank you !
Georgi “Joro” Kodinov
Team Lead,
MySQL Server GeneralTeam
Georgi.Kodinov@oracle.com
31 © 2019 Oracle

Más contenido relacionado

Similar a PLe19 How To Instrument Your Code in performance_schema

Oracle plsql code refactoring - from anonymous block to stored procedure
Oracle plsql code refactoring - from anonymous block to stored procedureOracle plsql code refactoring - from anonymous block to stored procedure
Oracle plsql code refactoring - from anonymous block to stored procedureCarlos Oliveira
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeGeorgi Kodinov
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaMark Leith
 
A Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreA Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreDave Stokes
 
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...Miguel Araújo
 
Oracle Database 19c - poslední z rodiny 12.2 a co přináší nového
Oracle Database 19c - poslední z rodiny 12.2 a co přináší novéhoOracle Database 19c - poslední z rodiny 12.2 a co přináší nového
Oracle Database 19c - poslední z rodiny 12.2 a co přináší novéhoMarketingArrowECS_CZ
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetConfoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetDave Stokes
 
MySQL Document Store and Node.JS
MySQL Document Store and Node.JSMySQL Document Store and Node.JS
MySQL Document Store and Node.JSReggie Burnett
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Geir Høydalsvik
 
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.Cloud Native Day Tel Aviv
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Morgan Tocker
 
MySQL Technology Overview
MySQL Technology OverviewMySQL Technology Overview
MySQL Technology OverviewKeith Hollman
 
Oracle Autonomous Database - introducción técnica y hands on lab
Oracle Autonomous Database  - introducción técnica y hands on labOracle Autonomous Database  - introducción técnica y hands on lab
Oracle Autonomous Database - introducción técnica y hands on lab"Diego \"Perico\"" Sanchez
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...Geir Høydalsvik
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document StoreRui Quelhas
 
Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4Tejas Purohit
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGiuliano Iacobelli
 

Similar a PLe19 How To Instrument Your Code in performance_schema (20)

MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
 
Oracle plsql code refactoring - from anonymous block to stored procedure
Oracle plsql code refactoring - from anonymous block to stored procedureOracle plsql code refactoring - from anonymous block to stored procedure
Oracle plsql code refactoring - from anonymous block to stored procedure
 
OUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source CodeOUGLS 2016: Guided Tour On The MySQL Source Code
OUGLS 2016: Guided Tour On The MySQL Source Code
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
 
A Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document StoreA Step by Step Introduction to the MySQL Document Store
A Step by Step Introduction to the MySQL Document Store
 
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
MySQL Shell - A DevOps-engineer day with MySQL’s development and administrati...
 
Oracle Database 19c - poslední z rodiny 12.2 a co přináší nového
Oracle Database 19c - poslední z rodiny 12.2 a co přináší novéhoOracle Database 19c - poslední z rodiny 12.2 a co přináší nového
Oracle Database 19c - poslední z rodiny 12.2 a co přináší nového
 
Confoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSetConfoo 202 - MySQL Group Replication and ReplicaSet
Confoo 202 - MySQL Group Replication and ReplicaSet
 
MySQL Document Store and Node.JS
MySQL Document Store and Node.JSMySQL Document Store and Node.JS
MySQL Document Store and Node.JS
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
 
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
Simplifying MySQL, Pre-FOSDEM MySQL Days, Brussels, January 30, 2020.
 
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
MySQL Shell: the daily tool for devs and admins. By Vittorio Cioe.
 
Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7Upcoming changes in MySQL 5.7
Upcoming changes in MySQL 5.7
 
MySQL Technology Overview
MySQL Technology OverviewMySQL Technology Overview
MySQL Technology Overview
 
Oracle Autonomous Database - introducción técnica y hands on lab
Oracle Autonomous Database  - introducción técnica y hands on labOracle Autonomous Database  - introducción técnica y hands on lab
Oracle Autonomous Database - introducción técnica y hands on lab
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
 
Node.js and the MySQL Document Store
Node.js and the MySQL Document StoreNode.js and the MySQL Document Store
Node.js and the MySQL Document Store
 
Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
Get things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplicationsGet things done with Yii - quickly build webapplications
Get things done with Yii - quickly build webapplications
 

Más de Georgi Kodinov

2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptxGeorgi Kodinov
 
2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptxGeorgi Kodinov
 
OpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneOpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneGeorgi Kodinov
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql cloneGeorgi Kodinov
 
2019 BGOUG Autumn MySQL Clone
2019  BGOUG Autumn MySQL Clone2019  BGOUG Autumn MySQL Clone
2019 BGOUG Autumn MySQL CloneGeorgi Kodinov
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database serverGeorgi Kodinov
 
DevTalks.ro 2019 What's New in MySQL 8.0 Security
DevTalks.ro 2019 What's New in MySQL 8.0 SecurityDevTalks.ro 2019 What's New in MySQL 8.0 Security
DevTalks.ro 2019 What's New in MySQL 8.0 SecurityGeorgi Kodinov
 
DevTalks.ro 2019 MySQL Data Masking Talk
DevTalks.ro 2019 MySQL Data Masking TalkDevTalks.ro 2019 MySQL Data Masking Talk
DevTalks.ro 2019 MySQL Data Masking TalkGeorgi Kodinov
 
FOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component InfrastructureFOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component InfrastructureGeorgi Kodinov
 
MySQL Enterprise Data Masking
MySQL Enterprise Data MaskingMySQL Enterprise Data Masking
MySQL Enterprise Data MaskingGeorgi Kodinov
 
Percona Live Europe 2018: What's New in MySQL 8.0 Security
Percona Live Europe 2018: What's New in MySQL 8.0 SecurityPercona Live Europe 2018: What's New in MySQL 8.0 Security
Percona Live Europe 2018: What's New in MySQL 8.0 SecurityGeorgi Kodinov
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQLGeorgi Kodinov
 
BGOUG17: Cloudy with a chance of MySQL
BGOUG17: Cloudy with a chance of MySQLBGOUG17: Cloudy with a chance of MySQL
BGOUG17: Cloudy with a chance of MySQLGeorgi Kodinov
 
Pl17: MySQL 8.0: security
Pl17: MySQL 8.0: securityPl17: MySQL 8.0: security
Pl17: MySQL 8.0: securityGeorgi Kodinov
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database serverGeorgi Kodinov
 
2016 oSC MySQL Firewall
2016 oSC MySQL Firewall2016 oSC MySQL Firewall
2016 oSC MySQL FirewallGeorgi Kodinov
 
OUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQLOUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQLGeorgi Kodinov
 
Openfest15 MySQL Plugin Development
Openfest15 MySQL Plugin DevelopmentOpenfest15 MySQL Plugin Development
Openfest15 MySQL Plugin DevelopmentGeorgi Kodinov
 
BGOUG 2014 Decrease Your MySQL Attack Surface
BGOUG 2014 Decrease Your MySQL Attack SurfaceBGOUG 2014 Decrease Your MySQL Attack Surface
BGOUG 2014 Decrease Your MySQL Attack SurfaceGeorgi Kodinov
 

Más de Georgi Kodinov (20)

2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx
 
2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx
 
OpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneOpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL Clone
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql clone
 
2019 BGOUG Autumn MySQL Clone
2019  BGOUG Autumn MySQL Clone2019  BGOUG Autumn MySQL Clone
2019 BGOUG Autumn MySQL Clone
 
2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server2019 indit blackhat_honeypot your database server
2019 indit blackhat_honeypot your database server
 
DevTalks.ro 2019 What's New in MySQL 8.0 Security
DevTalks.ro 2019 What's New in MySQL 8.0 SecurityDevTalks.ro 2019 What's New in MySQL 8.0 Security
DevTalks.ro 2019 What's New in MySQL 8.0 Security
 
DevTalks.ro 2019 MySQL Data Masking Talk
DevTalks.ro 2019 MySQL Data Masking TalkDevTalks.ro 2019 MySQL Data Masking Talk
DevTalks.ro 2019 MySQL Data Masking Talk
 
FOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component InfrastructureFOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component Infrastructure
 
MySQL Enterprise Data Masking
MySQL Enterprise Data MaskingMySQL Enterprise Data Masking
MySQL Enterprise Data Masking
 
Percona Live Europe 2018: What's New in MySQL 8.0 Security
Percona Live Europe 2018: What's New in MySQL 8.0 SecurityPercona Live Europe 2018: What's New in MySQL 8.0 Security
Percona Live Europe 2018: What's New in MySQL 8.0 Security
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQL
 
Pl18 saving bandwidth
Pl18 saving bandwidthPl18 saving bandwidth
Pl18 saving bandwidth
 
BGOUG17: Cloudy with a chance of MySQL
BGOUG17: Cloudy with a chance of MySQLBGOUG17: Cloudy with a chance of MySQL
BGOUG17: Cloudy with a chance of MySQL
 
Pl17: MySQL 8.0: security
Pl17: MySQL 8.0: securityPl17: MySQL 8.0: security
Pl17: MySQL 8.0: security
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database server
 
2016 oSC MySQL Firewall
2016 oSC MySQL Firewall2016 oSC MySQL Firewall
2016 oSC MySQL Firewall
 
OUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQLOUGLS 2016: How profiling works in MySQL
OUGLS 2016: How profiling works in MySQL
 
Openfest15 MySQL Plugin Development
Openfest15 MySQL Plugin DevelopmentOpenfest15 MySQL Plugin Development
Openfest15 MySQL Plugin Development
 
BGOUG 2014 Decrease Your MySQL Attack Surface
BGOUG 2014 Decrease Your MySQL Attack SurfaceBGOUG 2014 Decrease Your MySQL Attack Surface
BGOUG 2014 Decrease Your MySQL Attack Surface
 

Último

WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxalwaysnagaraju26
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in sowetomasabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...masabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park masabamasaba
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxAnnaArtyushina1
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...masabamasaba
 

Último (20)

WSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - KanchanaWSO2Con2024 - Hello Choreo Presentation - Kanchana
WSO2Con2024 - Hello Choreo Presentation - Kanchana
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
WSO2Con2024 - GitOps in Action: Navigating Application Deployment in the Plat...
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 

PLe19 How To Instrument Your Code in performance_schema

  • 1. Georgi Kodinov Team Lead, MySQL server general team How to Instrument Your Code in MySQL Performance Schema © 2019 Oracle1
  • 2. Safe harbor statement The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, timing, and pricing of any features or functionality described for Oracle’s products may change and remains at the sole discretion of Oracle Corporation. 2 © 2019 Oracle
  • 3. Topics Covered Why should I instrument my code ? How do I go about instrumenting it ? Mechanics of instrumentation PERFORMANCE_SCHEMA: not just about performance © 2019 Oracle3
  • 4. Why should I instrument my code ? • Understand what resources it uses: • memory, locks, time, files, etc. • More debuggable • Provides extra insight into code operation and issues • Expose extra volatile information to users and administrators • Make your code more portable © 2019 Oracle4
  • 5. How do I instrument my code ? Contribute data to the instruments provided Future: add your own instruments © 2019 Oracle5
  • 6. Most of the times it’sTHAT easy ! #include <pthread.h> pthread_mutex_t foo; void do_something() { pthread_mutex_lock(&foo); ... pthread_mutex_unlock(&foo); } #include "mysql/psi/mysql_mutex.h“ mysql_mutex_t foo; void do_something() { mysql_mutex_lock(&foo); ... mysql_mutex_unlock(&foo); } © 2019 Oracle6
  • 7. Extra step: register your objects #ifdef HAVE_PSI_MUTEX_INTERFACE PSI_mutex_key mutex_key_foo = PSI_NOT_INSTRUMENTED; static PSI_mutex_info all_mutexes[]= { { &mutex_key_foo, "LOCK_foo", PSI_FLAG_SINGLETON, 0, "example doc"}, .. } .. count = static_cast<int>(array_elements(all_mutexes)); mysql_mutex_register(“category_foo”, all_mutexes, count); .. mysql_mutex_init(mutex_key_foo, &foo, MY_MUTEX_INIT_FAST); #endif /* HAVE_PSI_MUTEX_INTERFACE */ © 2019 Oracle7
  • 8. Instrumentation inventory: inline functions • POSIX threads • POSIX conditions • POSIX mutexes • POSIX read/write locks • POSIX sockets • Buffered and unbuffered file I/O • MySQL stages • MySQL metadata locks mysql_thread.h mysql_cond.h mysql_mutex.h mysql_rwlock.h mysql_socket.h mysql_file.h mysql_stage.h mysql_mdl.h © 2019 Oracle8
  • 9. How do I instrument my memory use ? #include <stdlib.h> void *foo; void do_something() { foo = malloc(12); ... free(foo); } #include "mysys.h“ void *foo; void do_something() { foo = my_malloc(mem_key_foo, 12, MYF(0)); ... my_free(foo); } © 2019 Oracle9
  • 10. Extra step: register your objects #ifdef HAVE_PSI_MEMORY_INTERFACE PSI_memory_key mem_key_foo = PSI_NOT_INSTRUMENTED; static PSI_memory_info all_memory[] = { {&mem_key_foo, “FOO", PSI_FLAG_ONLY_GLOBAL_STAT, 0, "example doc"}}; … count = static_cast<int>(array_elements(all_memory)); mysql_memory_register(category, all_memory, count); #endif /* HAVE_PSI_MEMORY_INTERFACE */ © 2019 Oracle10
  • 11. Instrumentation inventory: memory • Plugin service implemented in mysys: my_malloc(), my_free(), my_memdup() etc. • Static mysys inspired library to link with components: just my_malloc() and my_free() include/mysql/service_mysql_alloc.h components/library_mysys/my_memory.h © 2019 Oracle11
  • 12. Instrumenting other stuff: utility macros #include <mysql/psi/mysql_idle.h> … PSI_idle_locker *m_idle_psi = NULL; PSI_idle_locker_state m_idle_state; … MYSQL_START_IDLE_WAIT(m_idle_psi, &m_idle_state); … MYSQL_END_IDLE_WAIT(m_idle_psi); … © 2019 Oracle12
  • 13. Instrumentation inventory: utility macros • Transactions • Table locks • “System” (currently shared objects) • Statements • Stored programs • Prepared statements • MySQL stages • Errors • Data locks  Idle mysql_transaction.h mysql_table.h mysql_system.h mysql_statement.h mysql_sp.h mysql_ps.h mysql_stage.h mysql_error.h mysql_data_lock.h mysql_idle.h © 2019 Oracle13
  • 14. Mechanics of code instrumentation Under the hood © 2019 Oracle14
  • 15. Calling instrumentation: PSI_*_CALL macros • Server code: direct call • #define PSI_FILE_CALL(M) pfs_##M##_v1 • Plugins: function pointer • #define PSI_FILE_CALL(M) psi_file_service->M • Components: component service handle • #define PSI_FILE_CALL(M) mysql_service_psi_file_v1->M © 2019 Oracle15
  • 16. Random thoughts on good code instrumentation • Always release the artifacts that instruments returned via the intended methods ! • Instrumentation can be costly ! • Consider using component infrastructure © 2019 Oracle16
  • 17. Performance Schema Not just about performance ! © 2019 Oracle17
  • 18. PERFORMANCE_SCHEMA: Not just performance ! • Started as performance instrumentation. Still does it ! • Grown into general storage for fast-changing volatile data • System variables • Connection attributes • Replication, innodb state • Now supports adding new tables from components © 2019 Oracle18
  • 19. Add a PERFORMANCE_SCHEMA table From a component © 2019 Oracle19
  • 20. Step 1:The data © 2019 Oracle20
  • 21. Step 2: Basic table APIs © 2019 Oracle21
  • 22. Step 3: Data retrieval © 2019 Oracle22
  • 23. Step 4: Component code © 2019 Oracle23
  • 24. How it drives © 2019 Oracle24
  • 25. Let’s look at the table © 2019 Oracle25
  • 26. Where to go from here ? • MySQL Internals Doxygen: https://dev.mysql.com/doc/dev/mysql- server/latest/PAGE_PFS.html • Reference Manual: https://dev.mysql.com/doc/refman/8.0/en/performance- schema.html © 2019 Oracle26
  • 27. Questions And Answers © 2019 Oracle27
  • 28. Copyright © 2019 Oracle and/or its affiliates.28 Meet the MySQL Team at the Conference Sunny Bains Luis Soares Kenny Gryp Frédéric Descamps Dimitri Kravtchuk Ståle Deraas Pedro Gomes Geir HøydalsvikNorvald Ryeng Georgi Kodinov
  • 29. Join us on MySQL Community Slack Copyright © 2019 Oracle and/or its affiliates.29 https://lefred.be/mysql-community-on-slack/
  • 30. Follow us on Social Media Copyright © 2019 Oracle and/or its affiliates.30 https://www.facebook.com/mysql https://twitter.com/mysql https://www.linkedin.com/company/mysql
  • 31. Thank you ! Georgi “Joro” Kodinov Team Lead, MySQL Server GeneralTeam Georgi.Kodinov@oracle.com 31 © 2019 Oracle