Skip to content

Commit cfb27d1

Browse files
committed
Follow Dimitry Sibiryakov's suggestion to unify get*Counters methods.
1 parent 089060f commit cfb27d1

File tree

6 files changed

+59
-72
lines changed

6 files changed

+59
-72
lines changed

doc/Using_OO_API.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,8 +2124,14 @@ The returned pointer may be `nullptr` if the corresponding trace object is not i
21242124

21252125
- ISC_UINT64 getElapsedTime() - returns the elapsed time, in milliseconds
21262126
- ISC_UINT64 getFetchedRecords() - returns number of records fetched during execution
2127-
- IPerformanceCounters* getPageCounters() - returns per-pagespace performance counters
2128-
- IPerformanceCounters* getTableCounters() - returns per-table performance counters
2127+
- IPerformanceCounters* getCounters(unsigned group) - returns the requested performance counters group
2128+
2129+
The following groups of performance counters are currently supported:
2130+
2131+
- COUNTER_GROUP_PAGES - per-pagespace counters
2132+
- COUNTER_GROUP_TABLES - per-table counters
2133+
2134+
If `getCounters()` is called with a counter group not supported by the implementation, `nullptr` is returned.
21292135

21302136
<a name="PerformanceCounters"></a> PerformanceCounters interface:
21312137

src/include/firebird/FirebirdInterface.idl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,10 +1932,12 @@ interface PerformanceCounters : Versioned
19321932

19331933
interface PerformanceStats : Versioned
19341934
{
1935+
const uint COUNTER_GROUP_PAGES = 0;
1936+
const uint COUNTER_GROUP_TABLES = 1;
1937+
19351938
uint64 getElapsedTime(); // in milliseconds
19361939
uint64 getFetchedRecords();
19371940

1938-
PerformanceCounters getPageCounters();
1939-
PerformanceCounters getTableCounters();
1941+
PerformanceCounters getCounters(uint group);
19401942
}
19411943

src/include/firebird/IdlFbInterfaces.h

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7693,8 +7693,7 @@ namespace Firebird
76937693
{
76947694
ISC_UINT64 (CLOOP_CARG *getElapsedTime)(IPerformanceStats* self) CLOOP_NOEXCEPT;
76957695
ISC_UINT64 (CLOOP_CARG *getFetchedRecords)(IPerformanceStats* self) CLOOP_NOEXCEPT;
7696-
IPerformanceCounters* (CLOOP_CARG *getPageCounters)(IPerformanceStats* self) CLOOP_NOEXCEPT;
7697-
IPerformanceCounters* (CLOOP_CARG *getTableCounters)(IPerformanceStats* self) CLOOP_NOEXCEPT;
7696+
IPerformanceCounters* (CLOOP_CARG *getCounters)(IPerformanceStats* self, unsigned group) CLOOP_NOEXCEPT;
76987697
};
76997698

77007699
protected:
@@ -7710,6 +7709,9 @@ namespace Firebird
77107709
public:
77117710
static CLOOP_CONSTEXPR unsigned VERSION = FIREBIRD_IPERFORMANCE_STATS_VERSION;
77127711

7712+
static CLOOP_CONSTEXPR unsigned COUNTER_GROUP_PAGES = 0;
7713+
static CLOOP_CONSTEXPR unsigned COUNTER_GROUP_TABLES = 1;
7714+
77137715
ISC_UINT64 getElapsedTime()
77147716
{
77157717
ISC_UINT64 ret = static_cast<VTable*>(this->cloopVTable)->getElapsedTime(this);
@@ -7722,15 +7724,9 @@ namespace Firebird
77227724
return ret;
77237725
}
77247726

7725-
IPerformanceCounters* getPageCounters()
7726-
{
7727-
IPerformanceCounters* ret = static_cast<VTable*>(this->cloopVTable)->getPageCounters(this);
7728-
return ret;
7729-
}
7730-
7731-
IPerformanceCounters* getTableCounters()
7727+
IPerformanceCounters* getCounters(unsigned group)
77327728
{
7733-
IPerformanceCounters* ret = static_cast<VTable*>(this->cloopVTable)->getTableCounters(this);
7729+
IPerformanceCounters* ret = static_cast<VTable*>(this->cloopVTable)->getCounters(this, group);
77347730
return ret;
77357731
}
77367732
};
@@ -22139,8 +22135,7 @@ namespace Firebird
2213922135
this->version = Base::VERSION;
2214022136
this->getElapsedTime = &Name::cloopgetElapsedTimeDispatcher;
2214122137
this->getFetchedRecords = &Name::cloopgetFetchedRecordsDispatcher;
22142-
this->getPageCounters = &Name::cloopgetPageCountersDispatcher;
22143-
this->getTableCounters = &Name::cloopgetTableCountersDispatcher;
22138+
this->getCounters = &Name::cloopgetCountersDispatcher;
2214422139
}
2214522140
} vTable;
2214622141

@@ -22173,24 +22168,11 @@ namespace Firebird
2217322168
}
2217422169
}
2217522170

22176-
static IPerformanceCounters* CLOOP_CARG cloopgetPageCountersDispatcher(IPerformanceStats* self) CLOOP_NOEXCEPT
22177-
{
22178-
try
22179-
{
22180-
return static_cast<Name*>(self)->Name::getPageCounters();
22181-
}
22182-
catch (...)
22183-
{
22184-
StatusType::catchException(0);
22185-
return static_cast<IPerformanceCounters*>(0);
22186-
}
22187-
}
22188-
22189-
static IPerformanceCounters* CLOOP_CARG cloopgetTableCountersDispatcher(IPerformanceStats* self) CLOOP_NOEXCEPT
22171+
static IPerformanceCounters* CLOOP_CARG cloopgetCountersDispatcher(IPerformanceStats* self, unsigned group) CLOOP_NOEXCEPT
2219022172
{
2219122173
try
2219222174
{
22193-
return static_cast<Name*>(self)->Name::getTableCounters();
22175+
return static_cast<Name*>(self)->Name::getCounters(group);
2219422176
}
2219522177
catch (...)
2219622178
{
@@ -22215,8 +22197,7 @@ namespace Firebird
2221522197

2221622198
virtual ISC_UINT64 getElapsedTime() = 0;
2221722199
virtual ISC_UINT64 getFetchedRecords() = 0;
22218-
virtual IPerformanceCounters* getPageCounters() = 0;
22219-
virtual IPerformanceCounters* getTableCounters() = 0;
22200+
virtual IPerformanceCounters* getCounters(unsigned group) = 0;
2222022201
};
2222122202
};
2222222203

src/include/gen/Firebird.pas

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -785,8 +785,7 @@ ISC_TIMESTAMP_TZ_EX = record
785785
IPerformanceCounters_getObjectCountersPtr = function(this: IPerformanceCounters; index: Cardinal): Int64Ptr; cdecl;
786786
IPerformanceStats_getElapsedTimePtr = function(this: IPerformanceStats): QWord; cdecl;
787787
IPerformanceStats_getFetchedRecordsPtr = function(this: IPerformanceStats): QWord; cdecl;
788-
IPerformanceStats_getPageCountersPtr = function(this: IPerformanceStats): IPerformanceCounters; cdecl;
789-
IPerformanceStats_getTableCountersPtr = function(this: IPerformanceStats): IPerformanceCounters; cdecl;
788+
IPerformanceStats_getCountersPtr = function(this: IPerformanceStats; group: Cardinal): IPerformanceCounters; cdecl;
790789

791790
VersionedVTable = class
792791
version: NativeInt;
@@ -4112,26 +4111,25 @@ IPerformanceCountersImpl = class(IPerformanceCounters)
41124111
PerformanceStatsVTable = class(VersionedVTable)
41134112
getElapsedTime: IPerformanceStats_getElapsedTimePtr;
41144113
getFetchedRecords: IPerformanceStats_getFetchedRecordsPtr;
4115-
getPageCounters: IPerformanceStats_getPageCountersPtr;
4116-
getTableCounters: IPerformanceStats_getTableCountersPtr;
4114+
getCounters: IPerformanceStats_getCountersPtr;
41174115
end;
41184116

41194117
IPerformanceStats = class(IVersioned)
41204118
const VERSION = 2;
4119+
const COUNTER_GROUP_PAGES = Cardinal(0);
4120+
const COUNTER_GROUP_TABLES = Cardinal(1);
41214121

41224122
function getElapsedTime(): QWord;
41234123
function getFetchedRecords(): QWord;
4124-
function getPageCounters(): IPerformanceCounters;
4125-
function getTableCounters(): IPerformanceCounters;
4124+
function getCounters(group: Cardinal): IPerformanceCounters;
41264125
end;
41274126

41284127
IPerformanceStatsImpl = class(IPerformanceStats)
41294128
constructor create;
41304129

41314130
function getElapsedTime(): QWord; virtual; abstract;
41324131
function getFetchedRecords(): QWord; virtual; abstract;
4133-
function getPageCounters(): IPerformanceCounters; virtual; abstract;
4134-
function getTableCounters(): IPerformanceCounters; virtual; abstract;
4132+
function getCounters(group: Cardinal): IPerformanceCounters; virtual; abstract;
41354133
end;
41364134

41374135
{$IFNDEF NO_FBCLIENT}
@@ -10253,14 +10251,9 @@ function IPerformanceStats.getFetchedRecords(): QWord;
1025310251
Result := PerformanceStatsVTable(vTable).getFetchedRecords(Self);
1025410252
end;
1025510253

10256-
function IPerformanceStats.getPageCounters(): IPerformanceCounters;
10254+
function IPerformanceStats.getCounters(group: Cardinal): IPerformanceCounters;
1025710255
begin
10258-
Result := PerformanceStatsVTable(vTable).getPageCounters(Self);
10259-
end;
10260-
10261-
function IPerformanceStats.getTableCounters(): IPerformanceCounters;
10262-
begin
10263-
Result := PerformanceStatsVTable(vTable).getTableCounters(Self);
10256+
Result := PerformanceStatsVTable(vTable).getCounters(Self, group);
1026410257
end;
1026510258

1026610259
var
@@ -17915,21 +17908,11 @@ function IPerformanceStatsImpl_getFetchedRecordsDispatcher(this: IPerformanceSta
1791517908
end
1791617909
end;
1791717910

17918-
function IPerformanceStatsImpl_getPageCountersDispatcher(this: IPerformanceStats): IPerformanceCounters; cdecl;
17919-
begin
17920-
Result := nil;
17921-
try
17922-
Result := IPerformanceStatsImpl(this).getPageCounters();
17923-
except
17924-
on e: Exception do FbException.catchException(nil, e);
17925-
end
17926-
end;
17927-
17928-
function IPerformanceStatsImpl_getTableCountersDispatcher(this: IPerformanceStats): IPerformanceCounters; cdecl;
17911+
function IPerformanceStatsImpl_getCountersDispatcher(this: IPerformanceStats; group: Cardinal): IPerformanceCounters; cdecl;
1792917912
begin
1793017913
Result := nil;
1793117914
try
17932-
Result := IPerformanceStatsImpl(this).getTableCounters();
17915+
Result := IPerformanceStatsImpl(this).getCounters(group);
1793317916
except
1793417917
on e: Exception do FbException.catchException(nil, e);
1793517918
end
@@ -19020,8 +19003,7 @@ initialization
1902019003
IPerformanceStatsImpl_vTable.version := 2;
1902119004
IPerformanceStatsImpl_vTable.getElapsedTime := @IPerformanceStatsImpl_getElapsedTimeDispatcher;
1902219005
IPerformanceStatsImpl_vTable.getFetchedRecords := @IPerformanceStatsImpl_getFetchedRecordsDispatcher;
19023-
IPerformanceStatsImpl_vTable.getPageCounters := @IPerformanceStatsImpl_getPageCountersDispatcher;
19024-
IPerformanceStatsImpl_vTable.getTableCounters := @IPerformanceStatsImpl_getTableCountersDispatcher;
19006+
IPerformanceStatsImpl_vTable.getCounters := @IPerformanceStatsImpl_getCountersDispatcher;
1902519007

1902619008
finalization
1902719009
IVersionedImpl_vTable.destroy;

src/jrd/trace/TraceObjects.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,25 @@ class TraceRuntimeStats :
182182
return m_info.pin_records_fetched;
183183
}
184184

185-
Firebird::IPerformanceCounters* getPageCounters()
185+
Firebird::IPerformanceCounters* getCounters(unsigned group)
186186
{
187-
return &m_pageCounters;
188-
}
187+
Firebird::IPerformanceCounters* counters = nullptr;
189188

190-
Firebird::IPerformanceCounters* getTableCounters()
191-
{
192-
return &m_tableCounters;
189+
switch (group)
190+
{
191+
case IPerformanceStats::COUNTER_GROUP_PAGES:
192+
counters = &m_pageCounters;
193+
break;
194+
195+
case IPerformanceStats::COUNTER_GROUP_TABLES:
196+
counters = &m_tableCounters;
197+
break;
198+
199+
default:
200+
fb_assert(false);
201+
}
202+
203+
return counters;
193204
}
194205

195206
Firebird::PerformanceInfo* getInfo()

src/utilities/ntrace/TracePluginImpl.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,8 @@ void TracePluginImpl::appendGlobalCounts(IPerformanceStats* stats)
636636
temp.printf("%7" QUADFORMAT"d ms", stats->getElapsedTime());
637637
record.append(temp);
638638

639-
const auto pageCounters = stats->getPageCounters();
639+
const auto pageCounters = stats->getCounters(IPerformanceStats::COUNTER_GROUP_PAGES);
640+
fb_assert(pageCounters);
640641

641642
if (const auto count = pageCounters->getObjectCount())
642643
{
@@ -681,10 +682,14 @@ void TracePluginImpl::appendGlobalCounts(IPerformanceStats* stats)
681682

682683
void TracePluginImpl::appendTableCounts(IPerformanceStats* stats)
683684
{
684-
const auto tableCounters = stats->getTableCounters();
685-
const auto count = tableCounters->getObjectCount();
685+
if (!config.print_perf)
686+
return;
686687

687-
if (!config.print_perf || !count)
688+
const auto tableCounters = stats->getCounters(IPerformanceStats::COUNTER_GROUP_TABLES);
689+
fb_assert(tableCounters);
690+
691+
const auto count = tableCounters->getObjectCount();
692+
if (!count)
688693
return;
689694

690695
FB_SIZE_T max_len = 0;

0 commit comments

Comments
 (0)