From 901b79a76825139f765913ea56ad51efcaee4831 Mon Sep 17 00:00:00 2001 From: "bogdan.khavronin" Date: Tue, 28 Oct 2025 11:45:32 +0300 Subject: [PATCH 1/2] getPerfCounters() now uses scope tags --- src/yvalve/perf.cpp | 58 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/src/yvalve/perf.cpp b/src/yvalve/perf.cpp index 7e3227f6b93..f567aa5d46e 100644 --- a/src/yvalve/perf.cpp +++ b/src/yvalve/perf.cpp @@ -315,6 +315,7 @@ struct KnownCounters const char* name; unsigned type; unsigned code; + unsigned scope = 0; }; #define TOTAL_COUNTERS 11 @@ -324,18 +325,21 @@ constexpr KnownCounters knownCounters[TOTAL_COUNTERS] = { {"RealTime", CNT_TIMER, CNT_TIME_REAL}, {"UserTime", CNT_TIMER, CNT_TIME_USER}, {"SystemTime", CNT_TIMER, CNT_TIME_SYSTEM}, - {"Fetches", CNT_DB_INFO, isc_info_fetches}, - {"Marks", CNT_DB_INFO, isc_info_marks}, - {"Reads", CNT_DB_INFO, isc_info_reads}, - {"Writes", CNT_DB_INFO, isc_info_writes}, - {"CurrentMemory", CNT_DB_INFO, isc_info_current_memory}, - {"MaxMemory", CNT_DB_INFO, isc_info_max_memory}, + {"Fetches", CNT_DB_INFO, isc_info_fetches, fb_info_counts_scope_att}, + {"Marks", CNT_DB_INFO, isc_info_marks, fb_info_counts_scope_att}, + {"Reads", CNT_DB_INFO, isc_info_reads, fb_info_counts_scope_att}, + {"Writes", CNT_DB_INFO, isc_info_writes, fb_info_counts_scope_att}, + {"CurrentMemory", CNT_DB_INFO, isc_info_current_memory, fb_info_counts_scope_db}, + {"MaxMemory", CNT_DB_INFO, isc_info_max_memory, fb_info_counts_scope_db}, {"Buffers", CNT_DB_INFO, isc_info_num_buffers}, {"PageSize", CNT_DB_INFO, isc_info_page_size} }; } // anonymous namespace +static Firebird::IAttachment* lastAttachment = nullptr; +static bool scopeTagsSupported = false; + void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, Firebird::IAttachment* att, const char* countersSet, ISC_INT64* counters) { @@ -350,8 +354,35 @@ void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, constexpr const char* delim = " \t,;"; unsigned typeMask = 0; unsigned n = 0; - UCHAR info[TOTAL_COUNTERS]; // will never use all, but do not care about few bytes + // We multiply by two because tags are in random order and we need to store their scope before process + UCHAR info[TOTAL_COUNTERS * 2]; // will never use all, but do not care about few bytes UCHAR* pinfo = info; + unsigned lastScope = 0; + + if (lastAttachment != att) + { + lastAttachment = att; + scopeTagsSupported = true; + + const UCHAR tags[] = + { + fb_info_counts_scope_att, + fb_info_counts_scope_db, + isc_info_end + }; + + UCHAR buffer[BUFFER_TINY]; + att->getInfo(status, sizeof(tags), tags, sizeof(buffer), buffer); + + for (UCHAR* p = buffer; *p != isc_info_end; p++) + { + if (*p == isc_info_error) + { + scopeTagsSupported = false; + break; + } + } + } #ifdef WIN_NT #define strtok_r strtok_s @@ -372,7 +403,14 @@ void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, typeMask |= knownCounters[i].type; if (knownCounters[i].type == CNT_DB_INFO) - *pinfo++ = knownCounters[i].code; + { + const UCHAR tag = knownCounters[i].code; + const unsigned scope = knownCounters[i].scope; + + if (scopeTagsSupported && scope && lastScope != scope) *pinfo++ = lastScope = scope; + + *pinfo++ = tag; + } goto found; } @@ -442,6 +480,10 @@ found: ; switch (ipb) { + case fb_info_counts_scope_att: + case fb_info_counts_scope_db: + continue; + case isc_info_reads: case isc_info_writes: case isc_info_marks: From 8bb31839b86bf7fc956bad8e5d60d026a7460ad0 Mon Sep 17 00:00:00 2001 From: "bogdan.khavronin" Date: Thu, 30 Oct 2025 11:54:43 +0300 Subject: [PATCH 2/2] Removed unnecessary try-catch since `isc_info_error` is already handled --- src/yvalve/perf.cpp | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/yvalve/perf.cpp b/src/yvalve/perf.cpp index f567aa5d46e..2276257215a 100644 --- a/src/yvalve/perf.cpp +++ b/src/yvalve/perf.cpp @@ -337,9 +337,6 @@ constexpr KnownCounters knownCounters[TOTAL_COUNTERS] = { } // anonymous namespace -static Firebird::IAttachment* lastAttachment = nullptr; -static bool scopeTagsSupported = false; - void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, Firebird::IAttachment* att, const char* countersSet, ISC_INT64* counters) { @@ -359,31 +356,6 @@ void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, UCHAR* pinfo = info; unsigned lastScope = 0; - if (lastAttachment != att) - { - lastAttachment = att; - scopeTagsSupported = true; - - const UCHAR tags[] = - { - fb_info_counts_scope_att, - fb_info_counts_scope_db, - isc_info_end - }; - - UCHAR buffer[BUFFER_TINY]; - att->getInfo(status, sizeof(tags), tags, sizeof(buffer), buffer); - - for (UCHAR* p = buffer; *p != isc_info_end; p++) - { - if (*p == isc_info_error) - { - scopeTagsSupported = false; - break; - } - } - } - #ifdef WIN_NT #define strtok_r strtok_s #endif @@ -407,7 +379,7 @@ void Why::UtilInterface::getPerfCounters(Firebird::CheckStatusWrapper* status, const UCHAR tag = knownCounters[i].code; const unsigned scope = knownCounters[i].scope; - if (scopeTagsSupported && scope && lastScope != scope) *pinfo++ = lastScope = scope; + if (scope && lastScope != scope) *pinfo++ = lastScope = scope; *pinfo++ = tag; }