Skip to content

Commit 3fe37a6

Browse files
committed
Do not pass user's transaction to plugin.
Use autonomous transaction in flush.
1 parent bb139df commit 3fe37a6

File tree

7 files changed

+143
-191
lines changed

7 files changed

+143
-191
lines changed

doc/sql.extensions/README.profiler.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ A session may be paused to temporary disable statistics collecting. It may be re
2222

2323
A new session may be started when a session is already active. In this case it has the same semantics of finishing the current session with `RDB$PROFILER.FINISH_SESSION(FALSE)` so snapshots tables are not updated in the same moment.
2424

25-
To analyze the collected data, the user must flush the data to the snapshot tables, which may be done finishing or pausing a session (with `FLUSH` parameter set to `TRUE`) or calling `RDB$PROFILER.FLUSH`.
25+
To analyze the collected data, the user must flush the data to the snapshot tables, which may be done finishing or pausing a session (with `FLUSH` parameter set to `TRUE`) or calling `RDB$PROFILER.FLUSH`. Data is flushed using an autonomous transaction (a transaction started and finished for the specific purpose of profiler data update).
2626

2727
Following is a sample profile session and queries for data analysis.
2828

@@ -89,6 +89,8 @@ execute procedure rdb$profiler.finish_session(true);
8989
9090
-- Data analysis
9191
92+
commit; -- start new transaction
93+
9294
select * from plg$prof_sessions;
9395
9496
select * from plg$prof_psql_stats_view;
@@ -195,9 +197,9 @@ Input parameters:
195197

196198
After update data is stored in tables `PLG$PROF_SESSIONS`, `PLG$PROF_STATEMENTS`, `PLG$PROF_RECORD_SOURCES`, `PLG$PROF_REQUESTS`, `PLG$PROF_PSQL_STATS` and `PLG$PROF_RECORD_SOURCE_STATS` and may be read and analyzed by the user.
197199

198-
It also removes finished sessions from memory.
200+
Data is updated using an autonomous transaction, so if the procedure is called in a snapshot transaction, data will not be directly readable in the same transaction.
199201

200-
If a remote `ATTACHMENT_ID` is used the data is updated in an autonomous transaction.
202+
Once flush happens, finished sessions are removed from memory.
201203

202204
Input parameters:
203205
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`

src/include/firebird/FirebirdInterface.idl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,15 +1700,12 @@ interface ReplicatedSession : PluginBase
17001700

17011701
interface ProfilerPlugin : PluginBase
17021702
{
1703-
// The transaction should not be stored for later usage after the method returns.
1704-
void init(Status status, Attachment attachment, Transaction transaction);
1703+
void init(Status status, Attachment attachment);
17051704

1706-
// The transaction should not be stored for later usage after the method returns.
1707-
ProfilerSession startSession(Status status, Transaction transaction, const string description,
1705+
ProfilerSession startSession(Status status, const string description,
17081706
const string options, ISC_TIMESTAMP_TZ timestamp);
17091707

1710-
// The transaction should not be stored for later usage after the method returns.
1711-
void flush(Status status, Transaction transaction);
1708+
void flush(Status status);
17121709
}
17131710

17141711
interface ProfilerSession : Disposable

src/include/firebird/IdlFbInterfaces.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6648,9 +6648,9 @@ namespace Firebird
66486648
public:
66496649
struct VTable : public IPluginBase::VTable
66506650
{
6651-
void (CLOOP_CARG *init)(IProfilerPlugin* self, IStatus* status, IAttachment* attachment, ITransaction* transaction) throw();
6652-
IProfilerSession* (CLOOP_CARG *startSession)(IProfilerPlugin* self, IStatus* status, ITransaction* transaction, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) throw();
6653-
void (CLOOP_CARG *flush)(IProfilerPlugin* self, IStatus* status, ITransaction* transaction) throw();
6651+
void (CLOOP_CARG *init)(IProfilerPlugin* self, IStatus* status, IAttachment* attachment) throw();
6652+
IProfilerSession* (CLOOP_CARG *startSession)(IProfilerPlugin* self, IStatus* status, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) throw();
6653+
void (CLOOP_CARG *flush)(IProfilerPlugin* self, IStatus* status) throw();
66546654
};
66556655

66566656
protected:
@@ -6666,25 +6666,25 @@ namespace Firebird
66666666
public:
66676667
static const unsigned VERSION = 4;
66686668

6669-
template <typename StatusType> void init(StatusType* status, IAttachment* attachment, ITransaction* transaction)
6669+
template <typename StatusType> void init(StatusType* status, IAttachment* attachment)
66706670
{
66716671
StatusType::clearException(status);
6672-
static_cast<VTable*>(this->cloopVTable)->init(this, status, attachment, transaction);
6672+
static_cast<VTable*>(this->cloopVTable)->init(this, status, attachment);
66736673
StatusType::checkException(status);
66746674
}
66756675

6676-
template <typename StatusType> IProfilerSession* startSession(StatusType* status, ITransaction* transaction, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp)
6676+
template <typename StatusType> IProfilerSession* startSession(StatusType* status, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp)
66776677
{
66786678
StatusType::clearException(status);
6679-
IProfilerSession* ret = static_cast<VTable*>(this->cloopVTable)->startSession(this, status, transaction, description, options, timestamp);
6679+
IProfilerSession* ret = static_cast<VTable*>(this->cloopVTable)->startSession(this, status, description, options, timestamp);
66806680
StatusType::checkException(status);
66816681
return ret;
66826682
}
66836683

6684-
template <typename StatusType> void flush(StatusType* status, ITransaction* transaction)
6684+
template <typename StatusType> void flush(StatusType* status)
66856685
{
66866686
StatusType::clearException(status);
6687-
static_cast<VTable*>(this->cloopVTable)->flush(this, status, transaction);
6687+
static_cast<VTable*>(this->cloopVTable)->flush(this, status);
66886688
StatusType::checkException(status);
66896689
}
66906690
};
@@ -19964,27 +19964,27 @@ namespace Firebird
1996419964
this->cloopVTable = &vTable;
1996519965
}
1996619966

19967-
static void CLOOP_CARG cloopinitDispatcher(IProfilerPlugin* self, IStatus* status, IAttachment* attachment, ITransaction* transaction) throw()
19967+
static void CLOOP_CARG cloopinitDispatcher(IProfilerPlugin* self, IStatus* status, IAttachment* attachment) throw()
1996819968
{
1996919969
StatusType status2(status);
1997019970

1997119971
try
1997219972
{
19973-
static_cast<Name*>(self)->Name::init(&status2, attachment, transaction);
19973+
static_cast<Name*>(self)->Name::init(&status2, attachment);
1997419974
}
1997519975
catch (...)
1997619976
{
1997719977
StatusType::catchException(&status2);
1997819978
}
1997919979
}
1998019980

19981-
static IProfilerSession* CLOOP_CARG cloopstartSessionDispatcher(IProfilerPlugin* self, IStatus* status, ITransaction* transaction, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) throw()
19981+
static IProfilerSession* CLOOP_CARG cloopstartSessionDispatcher(IProfilerPlugin* self, IStatus* status, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) throw()
1998219982
{
1998319983
StatusType status2(status);
1998419984

1998519985
try
1998619986
{
19987-
return static_cast<Name*>(self)->Name::startSession(&status2, transaction, description, options, timestamp);
19987+
return static_cast<Name*>(self)->Name::startSession(&status2, description, options, timestamp);
1998819988
}
1998919989
catch (...)
1999019990
{
@@ -19993,13 +19993,13 @@ namespace Firebird
1999319993
}
1999419994
}
1999519995

19996-
static void CLOOP_CARG cloopflushDispatcher(IProfilerPlugin* self, IStatus* status, ITransaction* transaction) throw()
19996+
static void CLOOP_CARG cloopflushDispatcher(IProfilerPlugin* self, IStatus* status) throw()
1999719997
{
1999819998
StatusType status2(status);
1999919999

2000020000
try
2000120001
{
20002-
static_cast<Name*>(self)->Name::flush(&status2, transaction);
20002+
static_cast<Name*>(self)->Name::flush(&status2);
2000320003
}
2000420004
catch (...)
2000520005
{
@@ -20071,9 +20071,9 @@ namespace Firebird
2007120071
{
2007220072
}
2007320073

20074-
virtual void init(StatusType* status, IAttachment* attachment, ITransaction* transaction) = 0;
20075-
virtual IProfilerSession* startSession(StatusType* status, ITransaction* transaction, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) = 0;
20076-
virtual void flush(StatusType* status, ITransaction* transaction) = 0;
20074+
virtual void init(StatusType* status, IAttachment* attachment) = 0;
20075+
virtual IProfilerSession* startSession(StatusType* status, const char* description, const char* options, ISC_TIMESTAMP_TZ timestamp) = 0;
20076+
virtual void flush(StatusType* status) = 0;
2007720077
};
2007820078

2007920079
template <typename Name, typename StatusType, typename Base>

src/include/gen/Firebird.pas

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,9 @@ ISC_TIMESTAMP_TZ_EX = record
714714
IReplicatedSession_startTransactionPtr = function(this: IReplicatedSession; status: IStatus; transaction: ITransaction; number: Int64): IReplicatedTransaction; cdecl;
715715
IReplicatedSession_cleanupTransactionPtr = procedure(this: IReplicatedSession; status: IStatus; number: Int64); cdecl;
716716
IReplicatedSession_setSequencePtr = procedure(this: IReplicatedSession; status: IStatus; name: PAnsiChar; value: Int64); cdecl;
717-
IProfilerPlugin_initPtr = procedure(this: IProfilerPlugin; status: IStatus; attachment: IAttachment; transaction: ITransaction); cdecl;
718-
IProfilerPlugin_startSessionPtr = function(this: IProfilerPlugin; status: IStatus; transaction: ITransaction; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; cdecl;
719-
IProfilerPlugin_flushPtr = procedure(this: IProfilerPlugin; status: IStatus; transaction: ITransaction); cdecl;
717+
IProfilerPlugin_initPtr = procedure(this: IProfilerPlugin; status: IStatus; attachment: IAttachment); cdecl;
718+
IProfilerPlugin_startSessionPtr = function(this: IProfilerPlugin; status: IStatus; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; cdecl;
719+
IProfilerPlugin_flushPtr = procedure(this: IProfilerPlugin; status: IStatus); cdecl;
720720
IProfilerSession_getIdPtr = function(this: IProfilerSession): Int64; cdecl;
721721
IProfilerSession_getFlagsPtr = function(this: IProfilerSession): Cardinal; cdecl;
722722
IProfilerSession_cancelPtr = procedure(this: IProfilerSession; status: IStatus); cdecl;
@@ -3775,9 +3775,9 @@ ProfilerPluginVTable = class(PluginBaseVTable)
37753775
IProfilerPlugin = class(IPluginBase)
37763776
const VERSION = 4;
37773777

3778-
procedure init(status: IStatus; attachment: IAttachment; transaction: ITransaction);
3779-
function startSession(status: IStatus; transaction: ITransaction; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession;
3780-
procedure flush(status: IStatus; transaction: ITransaction);
3778+
procedure init(status: IStatus; attachment: IAttachment);
3779+
function startSession(status: IStatus; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession;
3780+
procedure flush(status: IStatus);
37813781
end;
37823782

37833783
IProfilerPluginImpl = class(IProfilerPlugin)
@@ -3787,9 +3787,9 @@ IProfilerPluginImpl = class(IProfilerPlugin)
37873787
function release(): Integer; virtual; abstract;
37883788
procedure setOwner(r: IReferenceCounted); virtual; abstract;
37893789
function getOwner(): IReferenceCounted; virtual; abstract;
3790-
procedure init(status: IStatus; attachment: IAttachment; transaction: ITransaction); virtual; abstract;
3791-
function startSession(status: IStatus; transaction: ITransaction; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; virtual; abstract;
3792-
procedure flush(status: IStatus; transaction: ITransaction); virtual; abstract;
3790+
procedure init(status: IStatus; attachment: IAttachment); virtual; abstract;
3791+
function startSession(status: IStatus; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; virtual; abstract;
3792+
procedure flush(status: IStatus); virtual; abstract;
37933793
end;
37943794

37953795
ProfilerSessionVTable = class(DisposableVTable)
@@ -8945,21 +8945,21 @@ procedure IReplicatedSession.setSequence(status: IStatus; name: PAnsiChar; value
89458945
FbException.checkException(status);
89468946
end;
89478947

8948-
procedure IProfilerPlugin.init(status: IStatus; attachment: IAttachment; transaction: ITransaction);
8948+
procedure IProfilerPlugin.init(status: IStatus; attachment: IAttachment);
89498949
begin
8950-
ProfilerPluginVTable(vTable).init(Self, status, attachment, transaction);
8950+
ProfilerPluginVTable(vTable).init(Self, status, attachment);
89518951
FbException.checkException(status);
89528952
end;
89538953

8954-
function IProfilerPlugin.startSession(status: IStatus; transaction: ITransaction; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession;
8954+
function IProfilerPlugin.startSession(status: IStatus; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession;
89558955
begin
8956-
Result := ProfilerPluginVTable(vTable).startSession(Self, status, transaction, description, options, timestamp);
8956+
Result := ProfilerPluginVTable(vTable).startSession(Self, status, description, options, timestamp);
89578957
FbException.checkException(status);
89588958
end;
89598959

8960-
procedure IProfilerPlugin.flush(status: IStatus; transaction: ITransaction);
8960+
procedure IProfilerPlugin.flush(status: IStatus);
89618961
begin
8962-
ProfilerPluginVTable(vTable).flush(Self, status, transaction);
8962+
ProfilerPluginVTable(vTable).flush(Self, status);
89638963
FbException.checkException(status);
89648964
end;
89658965

@@ -15576,28 +15576,28 @@ function IProfilerPluginImpl_getOwnerDispatcher(this: IProfilerPlugin): IReferen
1557615576
end
1557715577
end;
1557815578

15579-
procedure IProfilerPluginImpl_initDispatcher(this: IProfilerPlugin; status: IStatus; attachment: IAttachment; transaction: ITransaction); cdecl;
15579+
procedure IProfilerPluginImpl_initDispatcher(this: IProfilerPlugin; status: IStatus; attachment: IAttachment); cdecl;
1558015580
begin
1558115581
try
15582-
IProfilerPluginImpl(this).init(status, attachment, transaction);
15582+
IProfilerPluginImpl(this).init(status, attachment);
1558315583
except
1558415584
on e: Exception do FbException.catchException(status, e);
1558515585
end
1558615586
end;
1558715587

15588-
function IProfilerPluginImpl_startSessionDispatcher(this: IProfilerPlugin; status: IStatus; transaction: ITransaction; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; cdecl;
15588+
function IProfilerPluginImpl_startSessionDispatcher(this: IProfilerPlugin; status: IStatus; description: PAnsiChar; options: PAnsiChar; timestamp: ISC_TIMESTAMP_TZ): IProfilerSession; cdecl;
1558915589
begin
1559015590
try
15591-
Result := IProfilerPluginImpl(this).startSession(status, transaction, description, options, timestamp);
15591+
Result := IProfilerPluginImpl(this).startSession(status, description, options, timestamp);
1559215592
except
1559315593
on e: Exception do FbException.catchException(status, e);
1559415594
end
1559515595
end;
1559615596

15597-
procedure IProfilerPluginImpl_flushDispatcher(this: IProfilerPlugin; status: IStatus; transaction: ITransaction); cdecl;
15597+
procedure IProfilerPluginImpl_flushDispatcher(this: IProfilerPlugin; status: IStatus); cdecl;
1559815598
begin
1559915599
try
15600-
IProfilerPluginImpl(this).flush(status, transaction);
15600+
IProfilerPluginImpl(this).flush(status);
1560115601
except
1560215602
on e: Exception do FbException.catchException(status, e);
1560315603
end

0 commit comments

Comments
 (0)