SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Ähnlich wie 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
 

Ähnlich wie 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
 

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

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

Kürzlich hochgeladen

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 

Kürzlich hochgeladen (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 

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