SlideShare a Scribd company logo
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI1
Firebird Tour 2017Firebird Tour 2017
Advanced Trace APIAdvanced Trace API
Vlad Khorsun, Firebird Project
About Firebird Tour 2017
● Firebird Tour 2017 is organized by Firebird Project,
IBSurgeon and IBPhoenix, and devoted to Firebird
Performance.
● The Platinum sponsor is Moscow Exchange
● Tour's locations and dates:
● October 3, 2017 – Prague, Czech Republic
● October 5, 2017 – Bad Sassendorf, Germany
● November 3, 2017 – Moscow, Russia
• Platinum Sponsor
• Sponsor of
– «Firebird 2.5 SQL Language Reference»
– «Firebird 3.0 SQL Language Reference»
– «Firebird 3.0 Developer Guide»
– «Firebird 3.0 Operations Guide»
• Sponsor of Firebird 2017 Tour seminars
• www.moex.com
• Replication, Recovery
and Optimization for
Firebird since 2002
• Platinum Sponsor of
Firebird Foundation
• Based in Moscow, Russia
www.ib-aid.com
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI5
Trace Session Configuration
● fbtrace.conf file in Firebird root directory
● Self-documented
● Show all possible trace parameters
● Uses own XML-like syntax in Firebird 2.5
– Different from firebird.conf, fbintl.conf, etc
● In Firebird 3 all configuration files have same syntax
– Syntax for trace configuration slightly changed
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI6
User Trace and System Audit
● User trace session
● Initiated (started) by user
via special service
● Not preserved after
Firebird shutdown
● Output read by initiated
service connection
● Scope depends on user
privileges
● Audit trace session
● Initiated only by Firebird
itself
● Started with Firebird every
time
● Output stored in log file(s)
● Scope is not limited
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI7
User Trace and System Audit
● User trace session
● Could be temporary
paused by the Firebird
● Could be many user trace
sessions
● Could be managed by
creator user or by
SYSDBA
● Audit trace session
● Never interrupted by
Firebird
● Only one audit trace
session could exists
● Could be managed by
SYSDBA only
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI8
Trace Sessions in the Engine
Database Attachment
Trace Manager
session object
...
session object
Trace Config Storage
stored session record
stored session record
...
stored session record
Database Attachment
Trace Manager
session object
...
session object
Service Attachment
Trace Manager
session object
...
session object
Trace Services
● Start trace session
● Stop trace session
● Suspend trace session
● Resume trace session
● List of trace sessions
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI9
Trace Sessions in the Engine
● To support multiply trace sessions we need some kind of
manager
● Trace sessions need a place to keep its parameters
● ID, name, creator user, state, etc
● Trace session configuration
● TraceConfigStorage object is used for this goals
● One instance per engine process
● Common part is in shared memory
● Changes increments special counter
● Requires synchronization between engine processes
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI10
Trace Configuration Storage
● Consists from two files
● fb_trace, control file, mapped into shared memory
● fb_trace_AAAAAA, storage of trace sessions records
● Both files placed at Firebird lock directory
● by default COMMON_APPDATAfirebird
● Creates when Firebird process starts
● Shared by all Firebird processes (embedded too !)
● Deleted when last Firebird process gone
● trace sessions is not preserved between Firebird restarts
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI11
Trace Sessions in the Engine
● All trace activity in the engine done using TraceManager
object
● Each database connection has own instance of
TraceManager
● Each service connection has own instance of TraceManager
● No additional synchronization between any kind of
connections is required
● TraceManager sits between the engine and trace plugin(s)
● Load and initialize trace plugin
● Put events data into trace plugin methods
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI12
Trace Manager
● Maintains list of active trace session objects which should
be used at databaseservice connection
● Maintains list of trace plugin’s which should receive
corresponding events
● Two main tasks
● React on changes in trace sessions list
– New trace session created
– Requests to stop trace session
– Requests to suspendresume trace session
● Pass events produced by the engine into trace plugin(s)
● Should have minimal impact on engine performance!
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI13
Trace Manager
TraceManager::change_number ==
TraceConfigStorage::change_number
Event to trace
TraceManager::
update_sessions()
No
TraceManager :
Pass event into every
session object
Yes
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI14
Trace session's output
● User trace
● Many writers
– Other connections, produced events to trace
● One reader
– The service connection which creates trace session
● It is hard to directly pass events data from different engine
processes into given service connection
● Writers needs to store it somewhere and reader should
read it
● Disk space used should be limited
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI15
Trace session's output
● User trace
● Many writers
● One reader
● Disk space released while
reading
● Delete whole log when
reader gone
● Log file name set by
Firebird
● System audit trace
● Many writers
● No readers
● Log files rotation
● Log files not deleted by
Firebird
● Log file name set in trace
configuration on per-
database (service) basis
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI16
Output of user trace
Log Control File
fb_trace.{GUID}
struct ShMemHeader
{
volatile unsigned int readFileNum;
volatile unsigned int writeFileNum;
...
● Log files placed at Firebird's lock directory
● by default COMMON_APPDATAfirebird
● Maximum size of each log file is 1MB
● Maximum summary log size set in firebird.conf
● MaxUserTraceLogSize = 10
Log Files
fb_trace.{GUID}.NNNNNNN
ATTACH_DATABASE
...
START_TRANSACTION
...
COMMIT_TRANSACTION
...
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI17
Output of System Audit trace
● Stored in disk file(s)
● File name is set in trace configuration file on per-database
(per-service) basis
● «log_filename» setting in database or service section
● Each traced database or service could have own trace log file
● Log file could be “rotated” when its size reached
«max_log_size» MB
● Current log file is renamed
– log_filename.<timestamp>
● New log file is created
● Old log files should be removed by the administrator
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI18
Trace tips and hints
● The more events is traced the more performance delay
could happen
● Be careful:
● Trigger related events will appear for every record affected by
DML statements!
● If you use some PSQL function in SQL statement – function
execution could be traced as many times as records
processed!
● Same about joins with stored procedures
● Same about RDB$SET_CONTEXT usage
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI19
Trace tips and hints
● Statements like
EXECUTE PROCEDURE, or
SELECT ... FROM<procedure>
will produce
● set of SQL statement related events
– log_statement_prepare
– log_statement_free
– log_statement_start
– log_statement_finish
● set of PSQL related events
– log_procedure_start
– log_procedure_finish
● Choose what you really need
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI20
Trace tips and hints
● Question
● Database could be accessed by file name or by alias, or
● I need to trace same set of events for few databases using
one trace session
● Solution
● set all required events and params at default database
section, but do not enable it
● add few more database sections using patterns and set
enable = true there
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI21
Trace tips and hints
database
{
enabled = false
log_statement_finish = true
print_perf = true
time_threshold = 60
}
# by the file name pattern
database = c:databases%.fdb
{
enabled = true
}
# by database alias
database = mycooldb
{
enabled = true
}
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI22
Trace tips and hints
● Consider to “mark” interesting queries using comments
embedded into query text and later add filter at trace
configuration to include (or exclude) such queries:
/* no trace me */ SELECT …
exclude_filter = %(no trace me)%
● Big app with a lot of modulesqueries:
mark queries with module names to easy find source
module which run the query
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI23
Trace tips and hints
● Performance statistics in trace and in tools (isql, etc) could
be different
● Trace shows “clear” time spent by the engine only to
execute statement
● ISQL time includes
● network delays
● prepare time
● commit time (DDL statements and autoddl = on)
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI24
Trace tips and hints
● Performance statistics in trace and in tools (isql, etc) could
be different
● How ISQL measure stats and time:
● take "before" stats
● free previous stmt
● prepare current stmt
● ask for PLAN (if required)
● execute statement
● ask for record counts (if query is insupddel)
● fetch and print results
● take "after" stats
● print difference "after" - "before"
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI25
Trace tips and hints
● Log of slow queries
database
{
log_statement_finish = true
print_perf = true
time_threshold = 10000
}
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI26
Trace tips and hints
● Log DDL statements
database
{
log_statement_start = true
include_filter = %(CREATE|ALTER|DROP)%
time_threshold = 0
}
case insensitive filter could looks a bit more complex
%([Cc]Rr[Ee][Aa][Tt][Ee])%
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI27
Trace tips and hints
● Trace configuration uses regexp patterns with the same
syntax as Firebird itself
● You may check regexp patternfilter with Firebird:
SELECT ‘Matched’ FROM RDB$DATABASE
WHERE <string> IS SIMILAR TO <pattern string>
Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI28
THANK YOU FOR ATTENTION !THANK YOU FOR ATTENTION !
Questions ?Questions ?
Firebird official web site
Firebird tracker
hvlad@users.sf.net

More Related Content

PDF
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PDF
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PDF
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PDF
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PDF
NZ MEGA 2012 Presentation - GSAK 4 - Advanced
PDF
Scaling 100PB Data Warehouse in Cloud
PPTX
Scaling Flink in Cloud
PDF
PGConf.ASIA 2019 Bali - Your Business Continuity Matrix and PostgreSQL's Disa...
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
NZ MEGA 2012 Presentation - GSAK 4 - Advanced
Scaling 100PB Data Warehouse in Cloud
Scaling Flink in Cloud
PGConf.ASIA 2019 Bali - Your Business Continuity Matrix and PostgreSQL's Disa...

Similar to Firebird Advanced Trace API (20)

PDF
Continuous Database Monitoring with the Trace API
PDF
Python with Firebird: FDB driver 101
PPTX
Resolving Firebird performance problems
PDF
Professional tools for Firebird optimization and maintenance from IBSurgeon
PDF
Firebird migration: from Firebird 1.5 to Firebird 2.5
PDF
Firebird Performance 2.5/3.0.x/4.0
PDF
Life with big Firebird databases
ODP
How Firebird transactions work
PPTX
Migration from Firebird 1.5 to Firebird 2.5
PDF
45 ways to speed up firebird database
ODP
How Firebird transactions work
PDF
Firebird 2.5.0-release notes
PPTX
Firebird migration: from Firebird 1.5 to Firebird 2.5
PDF
Creating logs for data auditing in FirebirdSQL
PDF
Introduction to firebidSQL 3.x
PDF
2013 Collaborate - OAUG - Presentation
ODP
Firebird Performance counters in details
PPTX
Firebird Anti-Corruption Approach
ODP
Review of the firebird development in 2011 2012
PPTX
Firebird database recovery and protection for enterprises and ISV
Continuous Database Monitoring with the Trace API
Python with Firebird: FDB driver 101
Resolving Firebird performance problems
Professional tools for Firebird optimization and maintenance from IBSurgeon
Firebird migration: from Firebird 1.5 to Firebird 2.5
Firebird Performance 2.5/3.0.x/4.0
Life with big Firebird databases
How Firebird transactions work
Migration from Firebird 1.5 to Firebird 2.5
45 ways to speed up firebird database
How Firebird transactions work
Firebird 2.5.0-release notes
Firebird migration: from Firebird 1.5 to Firebird 2.5
Creating logs for data auditing in FirebirdSQL
Introduction to firebidSQL 3.x
2013 Collaborate - OAUG - Presentation
Firebird Performance counters in details
Firebird Anti-Corruption Approach
Review of the firebird development in 2011 2012
Firebird database recovery and protection for enterprises and ISV
Ad

More from Marius Adrian Popa (9)

PDF
The State of the Romanian Game Developers Industry Rgda 2019 report
PDF
Understanding the firebird optimizer
PDF
Firebird 3.0 statistics and plans
PDF
Tuning Linux Windows and Firebird for Heavy Workload
ODP
Django firebird project
PPT
Proiectul django firebird
PDF
Firebird Myths in Romanian
PDF
2 Firebird Technical Ro
PDF
0 What Is Mind The Bird Ro
The State of the Romanian Game Developers Industry Rgda 2019 report
Understanding the firebird optimizer
Firebird 3.0 statistics and plans
Tuning Linux Windows and Firebird for Heavy Workload
Django firebird project
Proiectul django firebird
Firebird Myths in Romanian
2 Firebird Technical Ro
0 What Is Mind The Bird Ro
Ad

Recently uploaded (20)

PDF
Introduction to Data Science and Data Analysis
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PDF
annual-report-2024-2025 original latest.
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
IB Computer Science - Internal Assessment.pptx
PPTX
Introduction to machine learning and Linear Models
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PPTX
1_Introduction to advance data techniques.pptx
PDF
Business Analytics and business intelligence.pdf
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
Business Ppt On Nestle.pptx huunnnhhgfvu
PPT
Reliability_Chapter_ presentation 1221.5784
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PDF
.pdf is not working space design for the following data for the following dat...
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
Introduction to Data Science and Data Analysis
Qualitative Qantitative and Mixed Methods.pptx
annual-report-2024-2025 original latest.
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Miokarditis (Inflamasi pada Otot Jantung)
IBA_Chapter_11_Slides_Final_Accessible.pptx
climate analysis of Dhaka ,Banglades.pptx
IB Computer Science - Internal Assessment.pptx
Introduction to machine learning and Linear Models
Galatica Smart Energy Infrastructure Startup Pitch Deck
1_Introduction to advance data techniques.pptx
Business Analytics and business intelligence.pdf
Acceptance and paychological effects of mandatory extra coach I classes.pptx
Business Ppt On Nestle.pptx huunnnhhgfvu
Reliability_Chapter_ presentation 1221.5784
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
.pdf is not working space design for the following data for the following dat...
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
ALIMENTARY AND BILIARY CONDITIONS 3-1.pptx
Recruitment and Placement PPT.pdfbjfibjdfbjfobj

Firebird Advanced Trace API

  • 1. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI1 Firebird Tour 2017Firebird Tour 2017 Advanced Trace APIAdvanced Trace API Vlad Khorsun, Firebird Project
  • 2. About Firebird Tour 2017 ● Firebird Tour 2017 is organized by Firebird Project, IBSurgeon and IBPhoenix, and devoted to Firebird Performance. ● The Platinum sponsor is Moscow Exchange ● Tour's locations and dates: ● October 3, 2017 – Prague, Czech Republic ● October 5, 2017 – Bad Sassendorf, Germany ● November 3, 2017 – Moscow, Russia
  • 3. • Platinum Sponsor • Sponsor of – «Firebird 2.5 SQL Language Reference» – «Firebird 3.0 SQL Language Reference» – «Firebird 3.0 Developer Guide» – «Firebird 3.0 Operations Guide» • Sponsor of Firebird 2017 Tour seminars • www.moex.com
  • 4. • Replication, Recovery and Optimization for Firebird since 2002 • Platinum Sponsor of Firebird Foundation • Based in Moscow, Russia www.ib-aid.com
  • 5. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI5 Trace Session Configuration ● fbtrace.conf file in Firebird root directory ● Self-documented ● Show all possible trace parameters ● Uses own XML-like syntax in Firebird 2.5 – Different from firebird.conf, fbintl.conf, etc ● In Firebird 3 all configuration files have same syntax – Syntax for trace configuration slightly changed
  • 6. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI6 User Trace and System Audit ● User trace session ● Initiated (started) by user via special service ● Not preserved after Firebird shutdown ● Output read by initiated service connection ● Scope depends on user privileges ● Audit trace session ● Initiated only by Firebird itself ● Started with Firebird every time ● Output stored in log file(s) ● Scope is not limited
  • 7. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI7 User Trace and System Audit ● User trace session ● Could be temporary paused by the Firebird ● Could be many user trace sessions ● Could be managed by creator user or by SYSDBA ● Audit trace session ● Never interrupted by Firebird ● Only one audit trace session could exists ● Could be managed by SYSDBA only
  • 8. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI8 Trace Sessions in the Engine Database Attachment Trace Manager session object ... session object Trace Config Storage stored session record stored session record ... stored session record Database Attachment Trace Manager session object ... session object Service Attachment Trace Manager session object ... session object Trace Services ● Start trace session ● Stop trace session ● Suspend trace session ● Resume trace session ● List of trace sessions
  • 9. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI9 Trace Sessions in the Engine ● To support multiply trace sessions we need some kind of manager ● Trace sessions need a place to keep its parameters ● ID, name, creator user, state, etc ● Trace session configuration ● TraceConfigStorage object is used for this goals ● One instance per engine process ● Common part is in shared memory ● Changes increments special counter ● Requires synchronization between engine processes
  • 10. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI10 Trace Configuration Storage ● Consists from two files ● fb_trace, control file, mapped into shared memory ● fb_trace_AAAAAA, storage of trace sessions records ● Both files placed at Firebird lock directory ● by default COMMON_APPDATAfirebird ● Creates when Firebird process starts ● Shared by all Firebird processes (embedded too !) ● Deleted when last Firebird process gone ● trace sessions is not preserved between Firebird restarts
  • 11. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI11 Trace Sessions in the Engine ● All trace activity in the engine done using TraceManager object ● Each database connection has own instance of TraceManager ● Each service connection has own instance of TraceManager ● No additional synchronization between any kind of connections is required ● TraceManager sits between the engine and trace plugin(s) ● Load and initialize trace plugin ● Put events data into trace plugin methods
  • 12. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI12 Trace Manager ● Maintains list of active trace session objects which should be used at databaseservice connection ● Maintains list of trace plugin’s which should receive corresponding events ● Two main tasks ● React on changes in trace sessions list – New trace session created – Requests to stop trace session – Requests to suspendresume trace session ● Pass events produced by the engine into trace plugin(s) ● Should have minimal impact on engine performance!
  • 13. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI13 Trace Manager TraceManager::change_number == TraceConfigStorage::change_number Event to trace TraceManager:: update_sessions() No TraceManager : Pass event into every session object Yes
  • 14. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI14 Trace session's output ● User trace ● Many writers – Other connections, produced events to trace ● One reader – The service connection which creates trace session ● It is hard to directly pass events data from different engine processes into given service connection ● Writers needs to store it somewhere and reader should read it ● Disk space used should be limited
  • 15. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI15 Trace session's output ● User trace ● Many writers ● One reader ● Disk space released while reading ● Delete whole log when reader gone ● Log file name set by Firebird ● System audit trace ● Many writers ● No readers ● Log files rotation ● Log files not deleted by Firebird ● Log file name set in trace configuration on per- database (service) basis
  • 16. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI16 Output of user trace Log Control File fb_trace.{GUID} struct ShMemHeader { volatile unsigned int readFileNum; volatile unsigned int writeFileNum; ... ● Log files placed at Firebird's lock directory ● by default COMMON_APPDATAfirebird ● Maximum size of each log file is 1MB ● Maximum summary log size set in firebird.conf ● MaxUserTraceLogSize = 10 Log Files fb_trace.{GUID}.NNNNNNN ATTACH_DATABASE ... START_TRANSACTION ... COMMIT_TRANSACTION ...
  • 17. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI17 Output of System Audit trace ● Stored in disk file(s) ● File name is set in trace configuration file on per-database (per-service) basis ● «log_filename» setting in database or service section ● Each traced database or service could have own trace log file ● Log file could be “rotated” when its size reached «max_log_size» MB ● Current log file is renamed – log_filename.<timestamp> ● New log file is created ● Old log files should be removed by the administrator
  • 18. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI18 Trace tips and hints ● The more events is traced the more performance delay could happen ● Be careful: ● Trigger related events will appear for every record affected by DML statements! ● If you use some PSQL function in SQL statement – function execution could be traced as many times as records processed! ● Same about joins with stored procedures ● Same about RDB$SET_CONTEXT usage
  • 19. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI19 Trace tips and hints ● Statements like EXECUTE PROCEDURE, or SELECT ... FROM<procedure> will produce ● set of SQL statement related events – log_statement_prepare – log_statement_free – log_statement_start – log_statement_finish ● set of PSQL related events – log_procedure_start – log_procedure_finish ● Choose what you really need
  • 20. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI20 Trace tips and hints ● Question ● Database could be accessed by file name or by alias, or ● I need to trace same set of events for few databases using one trace session ● Solution ● set all required events and params at default database section, but do not enable it ● add few more database sections using patterns and set enable = true there
  • 21. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI21 Trace tips and hints database { enabled = false log_statement_finish = true print_perf = true time_threshold = 60 } # by the file name pattern database = c:databases%.fdb { enabled = true } # by database alias database = mycooldb { enabled = true }
  • 22. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI22 Trace tips and hints ● Consider to “mark” interesting queries using comments embedded into query text and later add filter at trace configuration to include (or exclude) such queries: /* no trace me */ SELECT … exclude_filter = %(no trace me)% ● Big app with a lot of modulesqueries: mark queries with module names to easy find source module which run the query
  • 23. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI23 Trace tips and hints ● Performance statistics in trace and in tools (isql, etc) could be different ● Trace shows “clear” time spent by the engine only to execute statement ● ISQL time includes ● network delays ● prepare time ● commit time (DDL statements and autoddl = on)
  • 24. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI24 Trace tips and hints ● Performance statistics in trace and in tools (isql, etc) could be different ● How ISQL measure stats and time: ● take "before" stats ● free previous stmt ● prepare current stmt ● ask for PLAN (if required) ● execute statement ● ask for record counts (if query is insupddel) ● fetch and print results ● take "after" stats ● print difference "after" - "before"
  • 25. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI25 Trace tips and hints ● Log of slow queries database { log_statement_finish = true print_perf = true time_threshold = 10000 }
  • 26. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI26 Trace tips and hints ● Log DDL statements database { log_statement_start = true include_filter = %(CREATE|ALTER|DROP)% time_threshold = 0 } case insensitive filter could looks a bit more complex %([Cc]Rr[Ee][Aa][Tt][Ee])%
  • 27. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI27 Trace tips and hints ● Trace configuration uses regexp patterns with the same syntax as Firebird itself ● You may check regexp patternfilter with Firebird: SELECT ‘Matched’ FROM RDB$DATABASE WHERE <string> IS SIMILAR TO <pattern string>
  • 28. Firebird Tour 2017Firebird Tour 2017 Advanced TraceAdvanced Trace APIAPI28 THANK YOU FOR ATTENTION !THANK YOU FOR ATTENTION ! Questions ?Questions ? Firebird official web site Firebird tracker hvlad@users.sf.net