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

More Related Content

Similar to 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 to 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
 

More from 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.pptxGeorgi 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
 

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
 
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
 

Recently uploaded

Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationHelp Desk Migration
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...Alluxio, Inc.
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Krakówbim.edu.pl
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignNeo4j
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAlluxio, Inc.
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?XfilesPro
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAlluxio, Inc.
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring SoftwareMera Monitor
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationHelp Desk Migration
 
How To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdfHow To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdfayushiqss
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Soroosh Khodami
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisNeo4j
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationWave PLM
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 

Recently uploaded (20)

Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
A Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data MigrationA Guideline to Gorgias to to Re:amaze Data Migration
A Guideline to Gorgias to to Re:amaze Data Migration
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
INGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by DesignINGKA DIGITAL: Linked Metadata by Design
INGKA DIGITAL: Linked Metadata by Design
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 
Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024Top Mobile App Development Companies 2024
Top Mobile App Development Companies 2024
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
Benefits of Employee Monitoring Software
Benefits of  Employee Monitoring SoftwareBenefits of  Employee Monitoring Software
Benefits of Employee Monitoring Software
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
How To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdfHow To Build a Successful SaaS Design.pdf
How To Build a Successful SaaS Design.pdf
 
Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024Secure Software Ecosystem Teqnation 2024
Secure Software Ecosystem Teqnation 2024
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Crafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM IntegrationCrafting the Perfect Measurement Sheet with PLM Integration
Crafting the Perfect Measurement Sheet with PLM Integration
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 

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