From a8ae90d9f79339817ee54f1be6a5a708f1071283 Mon Sep 17 00:00:00 2001 From: Adriano dos Santos Fernandes Date: Fri, 13 May 2022 22:20:10 -0300 Subject: [PATCH] Add configuration parameter DefaultProfilerPlugin. Change RDB$PROFILER.START_SESSION parameters order and put defaults on them. --- builds/install/misc/firebird.conf | 6 ++++++ doc/sql.extensions/README.profiler.md | 10 ++++++---- src/common/config/config.cpp | 6 ++++++ src/common/config/config.h | 8 +++++--- src/jrd/ProfilerManager.cpp | 8 ++++---- src/jrd/ProfilerManager.h | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/builds/install/misc/firebird.conf b/builds/install/misc/firebird.conf index 7670d0f6c0..ef94160b48 100644 --- a/builds/install/misc/firebird.conf +++ b/builds/install/misc/firebird.conf @@ -508,6 +508,12 @@ # #UserManager = Srp +# Default profiler plugin used to profile connections using the RDB$PROFILER package. +# +# Per-database configurable. +# +#DefaultProfilerPlugin = Default_Profiler + # TracePlugin is used by firebird trace facility to send trace data to the user # or log file in audit case. # diff --git a/doc/sql.extensions/README.profiler.md b/doc/sql.extensions/README.profiler.md index 34284020b4..d25355c113 100644 --- a/doc/sql.extensions/README.profiler.md +++ b/doc/sql.extensions/README.profiler.md @@ -55,7 +55,7 @@ set term ;! -- Start profiling -select rdb$profiler.start_session('Default_Profiler', 'Profile Session 1') from rdb$database; +select rdb$profiler.start_session('Profile Session 1') from rdb$database; set term !; @@ -72,7 +72,7 @@ execute procedure rdb$profiler.finish_session(true); execute procedure ins; -select rdb$profiler.start_session('Default_Profiler', 'Profile Session 2') from rdb$database; +select rdb$profiler.start_session('Profile Session 2') from rdb$database; select mod(id, 5), sum(val) @@ -122,9 +122,11 @@ select pstat.* `RDB$PROFILER.START_SESSION` starts a new profiler session, turns it the current session and return its identifier. +If `PLUGIN_NAME` is `NULL` (the default) it uses the database configuration `DefaultProfilerPlugin`. + Input parameters: - - `PLUGIN_NAME` type `VARCHAR(255) CHARACTER SET UTF8` - - `DESCRIPTION` type `VARCHAR(255) CHARACTER SET UTF8` + - `DESCRIPTION` type `VARCHAR(255) CHARACTER SET UTF8` default `NULL` + - `PLUGIN_NAME` type `VARCHAR(255) CHARACTER SET UTF8` default `NULL` Return type: `BIGINT NOT NULL`. diff --git a/src/common/config/config.cpp b/src/common/config/config.cpp index 6e17cf9b50..50301d8d80 100644 --- a/src/common/config/config.cpp +++ b/src/common/config/config.cpp @@ -647,6 +647,12 @@ const char* Config::getPlugins(unsigned int type) const aKey = key; break; } + case IPluginManager::TYPE_PROFILER: + { + DECLARE_PER_DB_KEY(KEY_PLUG_PROFILER); + aKey = key; + break; + } case IPluginManager::TYPE_TRACE: { DECLARE_PER_DB_KEY(KEY_PLUG_TRACE); diff --git a/src/common/config/config.h b/src/common/config/config.h index dc73bd743a..eb24132987 100644 --- a/src/common/config/config.h +++ b/src/common/config/config.h @@ -65,9 +65,9 @@ type getParameterName() const; form, for world-wide (global) parameters static type getParameterName(); - should be used. Also, for world-wide parameters, values of default + should be used. Also, for world-wide parameters, values of default config instance (see getDefaultConfig()) should be used. - 5. Macros CONFIG_GET_GLOBAL_XXX and CONFIG_GET_PER_DB_XXX helps to + 5. Macros CONFIG_GET_GLOBAL_XXX and CONFIG_GET_PER_DB_XXX helps to declare and implement trivial getXXX functions and to enforce rule (4). **/ @@ -163,6 +163,7 @@ enum ConfigKey KEY_PLUG_AUTH_SERVER, KEY_PLUG_AUTH_CLIENT, KEY_PLUG_AUTH_MANAGE, + KEY_PLUG_PROFILER, KEY_PLUG_TRACE, KEY_SECURITY_DATABASE, KEY_SERVER_MODE, @@ -271,6 +272,7 @@ constexpr ConfigEntry entries[MAX_CONFIG_KEY] = {TYPE_STRING, "AuthClient", false, "Srp256, Srp, Legacy_Auth"}, #endif {TYPE_STRING, "UserManager", false, "Srp"}, + {TYPE_STRING, "DefaultProfilerPlugin", false, "Default_Profiler"}, {TYPE_STRING, "TracePlugin", false, "fbtrace"}, {TYPE_STRING, "SecurityDatabase", false, nullptr}, // sec/db alias - rely on ConfigManager::getDefaultSecurityDb( {TYPE_STRING, "ServerMode", true, nullptr}, // actual value differs in boot/regular cases and set at setupDefaultConfig( @@ -434,7 +436,7 @@ public: // CONFIG_GET_GLOBAL_XXX (CONFIG_GET_PER_DB_XXX) set of macros helps to - // create trivial static (non-static) getXXX functions. + // create trivial static (non-static) getXXX functions. // Correctness of declaration and implementation is enforced with help // of entries[XXX].is_global. diff --git a/src/jrd/ProfilerManager.cpp b/src/jrd/ProfilerManager.cpp index ec5690cf6e..a8bde29eb0 100644 --- a/src/jrd/ProfilerManager.cpp +++ b/src/jrd/ProfilerManager.cpp @@ -151,8 +151,8 @@ void ProfilerPackage::startSessionFunction(ThrowStatusExceptionWrapper* /*status const auto attachment = tdbb->getAttachment(); const auto transaction = tdbb->getTransaction(); - const PathName pluginName(in->pluginName.str, in->pluginName.length); const string description(in->description.str, in->descriptionNull ? 0 : in->description.length); + const PathName pluginName(in->pluginName.str, in->pluginNameNull ? 0 : in->pluginName.length); const auto profilerManager = attachment->getProfilerManager(tdbb); AutoSetRestore pauseProfiler(&profilerManager->paused, true); @@ -200,7 +200,7 @@ SINT64 ProfilerManager::startSession(thread_db* tdbb, const PathName& pluginName } else { - GetPlugins plugins(IPluginManager::TYPE_PROFILER, pluginName.c_str()); + GetPlugins plugins(IPluginManager::TYPE_PROFILER, pluginName.nullStr()); if (!plugins.hasData()) { @@ -578,8 +578,8 @@ ProfilerPackage::ProfilerPackage(MemoryPool& pool) SystemFunctionFactory(), // parameters { - {"PLUGIN_NAME", fld_file_name2, true}, - {"DESCRIPTION", fld_short_description, true} + {"DESCRIPTION", fld_short_description, true, "null", {blr_null}}, + {"PLUGIN_NAME", fld_file_name2, true, "null", {blr_null}}, }, {fld_prof_ses_id, false} ) diff --git a/src/jrd/ProfilerManager.h b/src/jrd/ProfilerManager.h index 7d4b01ce63..05721aa88d 100644 --- a/src/jrd/ProfilerManager.h +++ b/src/jrd/ProfilerManager.h @@ -163,9 +163,9 @@ private: //---------- FB_MESSAGE(StartSessionInput, Firebird::ThrowStatusExceptionWrapper, + (FB_INTL_VARCHAR(255, CS_METADATA), description) (FB_INTL_VARCHAR(255, CS_METADATA), pluginName) //// TODO: Options: PSQL, SQL. - (FB_INTL_VARCHAR(255, CS_METADATA), description) //// TODO: Plugin options. );