SlideShare a Scribd company logo
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
Ad

More Related Content

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

MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
Morgan Tocker
 
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
Carlos 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 Code
Georgi Kodinov
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
Mark 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 Store
Dave 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ého
MarketingArrowECS_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 ReplicaSet
Dave Stokes
 
MySQL Document Store and Node.JS
MySQL Document Store and Node.JSMySQL Document Store and Node.JS
MySQL Document Store and Node.JS
Reggie Burnett
 
Codeigniter
CodeigniterCodeigniter
Codeigniter
Joram Salinas
 
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.7
Morgan Tocker
 
MySQL Technology Overview
MySQL Technology OverviewMySQL Technology Overview
MySQL Technology Overview
Keith 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 Store
Rui Quelhas
 
Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4
Tejas 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 Tool
Miguel 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 webapplications
Giuliano Iacobelli
 
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
Carlos 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 Code
Georgi Kodinov
 
Instrumenting plugins for Performance Schema
Instrumenting plugins for Performance SchemaInstrumenting plugins for Performance Schema
Instrumenting plugins for Performance Schema
Mark 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 Store
Dave 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ého
MarketingArrowECS_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 ReplicaSet
Dave Stokes
 
MySQL Document Store and Node.JS
MySQL Document Store and Node.JSMySQL Document Store and Node.JS
MySQL Document Store and Node.JS
Reggie 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.7
Morgan Tocker
 
MySQL Technology Overview
MySQL Technology OverviewMySQL Technology Overview
MySQL Technology Overview
Keith 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 Store
Rui Quelhas
 
Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4Ahmedabad MuleSoft Meetup #4
Ahmedabad MuleSoft Meetup #4
Tejas 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 Tool
Miguel 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 webapplications
Giuliano Iacobelli
 

More from Georgi Kodinov (20)

2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx
Georgi Kodinov
 
2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx
Georgi Kodinov
 
OpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneOpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL Clone
Georgi Kodinov
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql clone
Georgi Kodinov
 
2019 BGOUG Autumn MySQL Clone
2019  BGOUG Autumn MySQL Clone2019  BGOUG Autumn MySQL Clone
2019 BGOUG Autumn MySQL Clone
Georgi 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 server
Georgi 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 Security
Georgi 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 Talk
Georgi Kodinov
 
FOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component InfrastructureFOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component Infrastructure
Georgi Kodinov
 
MySQL Enterprise Data Masking
MySQL Enterprise Data MaskingMySQL Enterprise Data Masking
MySQL Enterprise Data Masking
Georgi 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 Security
Georgi Kodinov
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQL
Georgi Kodinov
 
Pl18 saving bandwidth
Pl18 saving bandwidthPl18 saving bandwidth
Pl18 saving bandwidth
Georgi 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 MySQL
Georgi Kodinov
 
Pl17: MySQL 8.0: security
Pl17: MySQL 8.0: securityPl17: MySQL 8.0: security
Pl17: MySQL 8.0: security
Georgi Kodinov
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database server
Georgi Kodinov
 
2016 oSC MySQL Firewall
2016 oSC MySQL Firewall2016 oSC MySQL Firewall
2016 oSC MySQL Firewall
Georgi 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 MySQL
Georgi Kodinov
 
Openfest15 MySQL Plugin Development
Openfest15 MySQL Plugin DevelopmentOpenfest15 MySQL Plugin Development
Openfest15 MySQL Plugin Development
Georgi Kodinov
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx2023 TurnovoConf MySQL Authentication.pptx
2023 TurnovoConf MySQL Authentication.pptx
Georgi Kodinov
 
2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx2022 TurnovoConf MySQL за начинаещи.pptx
2022 TurnovoConf MySQL за начинаещи.pptx
Georgi Kodinov
 
OpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL CloneOpenSUSE Conf 2020 MySQL Clone
OpenSUSE Conf 2020 MySQL Clone
Georgi Kodinov
 
2020 pre fosdem mysql clone
2020 pre fosdem   mysql clone2020 pre fosdem   mysql clone
2020 pre fosdem mysql clone
Georgi Kodinov
 
2019 BGOUG Autumn MySQL Clone
2019  BGOUG Autumn MySQL Clone2019  BGOUG Autumn MySQL Clone
2019 BGOUG Autumn MySQL Clone
Georgi 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 server
Georgi 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 Security
Georgi 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 Talk
Georgi Kodinov
 
FOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component InfrastructureFOSDEM19 MySQL Component Infrastructure
FOSDEM19 MySQL Component Infrastructure
Georgi Kodinov
 
MySQL Enterprise Data Masking
MySQL Enterprise Data MaskingMySQL Enterprise Data Masking
MySQL Enterprise Data Masking
Georgi 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 Security
Georgi Kodinov
 
How to add stuff to MySQL
How to add stuff to MySQLHow to add stuff to MySQL
How to add stuff to MySQL
Georgi 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 MySQL
Georgi Kodinov
 
Pl17: MySQL 8.0: security
Pl17: MySQL 8.0: securityPl17: MySQL 8.0: security
Pl17: MySQL 8.0: security
Georgi Kodinov
 
Fosdem17 honeypot your database server
Fosdem17 honeypot your database serverFosdem17 honeypot your database server
Fosdem17 honeypot your database server
Georgi Kodinov
 
2016 oSC MySQL Firewall
2016 oSC MySQL Firewall2016 oSC MySQL Firewall
2016 oSC MySQL Firewall
Georgi 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 MySQL
Georgi Kodinov
 
Openfest15 MySQL Plugin Development
Openfest15 MySQL Plugin DevelopmentOpenfest15 MySQL Plugin Development
Openfest15 MySQL Plugin Development
Georgi Kodinov
 
Ad

Recently uploaded (20)

TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRYLEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
LEARN SEO AND INCREASE YOUR KNOWLDGE IN SOFTWARE INDUSTRY
NidaFarooq10
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New VersionPixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
Pixologic ZBrush Crack Plus Activation Key [Latest 2025] New Version
saimabibi60507
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
Not So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java WebinarNot So Common Memory Leaks in Java Webinar
Not So Common Memory Leaks in Java Webinar
Tier1 app
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Top 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docxTop 10 Client Portal Software Solutions for 2025.docx
Top 10 Client Portal Software Solutions for 2025.docx
Portli
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
Ad

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 [email protected] 31 © 2019 Oracle