8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:43:02 +01:00

Some corrections (datatypes and view's column name) in the profiler plugin.

This commit is contained in:
Adriano dos Santos Fernandes 2023-01-05 08:00:59 -03:00
parent 08915c9a38
commit 8b934a38c0
3 changed files with 93 additions and 93 deletions

View File

@ -252,9 +252,9 @@ Below is the list of tables that stores profile data.
- `PROFILE_ID` type `BIGINT` - Profile session ID - `PROFILE_ID` type `BIGINT` - Profile session ID
- `STATEMENT_ID` type `BIGINT` - Statement ID - `STATEMENT_ID` type `BIGINT` - Statement ID
- `CURSOR_ID` type `BIGINT` - Cursor ID - `CURSOR_ID` type `INTEGER` - Cursor ID
- `RECORD_SOURCE_ID` type `BIGINT` - Record source ID - `RECORD_SOURCE_ID` type `INTEGER` - Record source ID
- `PARENT_RECORD_SOURCE_ID` type `BIGINT` - Parent record source ID - `PARENT_RECORD_SOURCE_ID` type `INTEGER` - Parent record source ID
- `ACCESS_PATH` type `VARCHAR(255) CHARACTER SET UTF8` - Access path for the record source - `ACCESS_PATH` type `VARCHAR(255) CHARACTER SET UTF8` - Access path for the record source
- Primary key: `PROFILE_ID, STATEMENT_ID, CURSOR_ID, RECORD_SOURCE_ID` - Primary key: `PROFILE_ID, STATEMENT_ID, CURSOR_ID, RECORD_SOURCE_ID`
@ -286,8 +286,8 @@ Below is the list of tables that stores profile data.
- `PROFILE_ID` type `BIGINT` - Profile session ID - `PROFILE_ID` type `BIGINT` - Profile session ID
- `REQUEST_ID` type `BIGINT` - Request ID - `REQUEST_ID` type `BIGINT` - Request ID
- `CURSOR_ID` type `BIGINT` - Cursor ID - `CURSOR_ID` type `INTEGER` - Cursor ID
- `RECORD_SOURCE_ID` type `BIGINT` - Record source ID - `RECORD_SOURCE_ID` type `INTEGER` - Record source ID
- `STATEMENT_ID` type `BIGINT` - Statement ID - `STATEMENT_ID` type `BIGINT` - Statement ID
- `OPEN_COUNTER` type `BIGINT` - Number of open times of the record source - `OPEN_COUNTER` type `BIGINT` - Number of open times of the record source
- `OPEN_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source open - `OPEN_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source open

View File

@ -139,8 +139,8 @@ namespace Jrd
double m_cardinality = 0.0; double m_cardinality = 0.0;
ULONG m_impure = 0; ULONG m_impure = 0;
bool m_recursive = false; bool m_recursive = false;
ULONG m_cursorProfileId; const ULONG m_cursorProfileId;
ULONG m_recSourceProfileId; const ULONG m_recSourceProfileId;
}; };

View File

@ -374,7 +374,7 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
) statementMessage(status, MasterInterfacePtr()); ) statementMessage(status, MasterInterfacePtr());
statementMessage.clear(); statementMessage.clear();
constexpr auto recSrcsSql = R"""( constexpr auto recSrcSql = R"""(
update or insert into plg$prof_record_sources update or insert into plg$prof_record_sources
(profile_id, statement_id, cursor_id, record_source_id, (profile_id, statement_id, cursor_id, record_source_id,
parent_record_source_id, access_path) parent_record_source_id, access_path)
@ -382,15 +382,15 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
matching (profile_id, statement_id, cursor_id, record_source_id) matching (profile_id, statement_id, cursor_id, record_source_id)
)"""; )""";
FB_MESSAGE(RecSrcsMessage, ThrowStatusExceptionWrapper, FB_MESSAGE(RecSrcMessage, ThrowStatusExceptionWrapper,
(FB_BIGINT, profileId) (FB_BIGINT, profileId)
(FB_BIGINT, statementId) (FB_BIGINT, statementId)
(FB_INTEGER, cursorId) (FB_INTEGER, cursorId)
(FB_INTEGER, recordSourceId) (FB_INTEGER, recordSourceId)
(FB_BIGINT, parentRecordSourceId) (FB_BIGINT, parentRecordSourceId)
(FB_INTL_VARCHAR(1024 * 4, CS_UTF8), accessPath) (FB_INTL_VARCHAR(1024 * 4, CS_UTF8), accessPath)
) recSrcsMessage(status, MasterInterfacePtr()); ) recSrcMessage(status, MasterInterfacePtr());
recSrcsMessage.clear(); recSrcMessage.clear();
constexpr auto requestSql = R"""( constexpr auto requestSql = R"""(
update or insert into plg$prof_requests update or insert into plg$prof_requests
@ -410,7 +410,7 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
) requestMessage(status, MasterInterfacePtr()); ) requestMessage(status, MasterInterfacePtr());
requestMessage.clear(); requestMessage.clear();
constexpr auto recSrcStatsSql = R"""( constexpr auto recSrcStatSql = R"""(
execute block ( execute block (
profile_id type of column plg$prof_record_source_stats.profile_id = ?, profile_id type of column plg$prof_record_source_stats.profile_id = ?,
request_id type of column plg$prof_record_source_stats.request_id = ?, request_id type of column plg$prof_record_source_stats.request_id = ?,
@ -454,7 +454,7 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
end end
)"""; )""";
FB_MESSAGE(RecSrcStatsMessage, ThrowStatusExceptionWrapper, FB_MESSAGE(RecSrcStatMessage, ThrowStatusExceptionWrapper,
(FB_BIGINT, profileId) (FB_BIGINT, profileId)
(FB_BIGINT, requestId) (FB_BIGINT, requestId)
(FB_INTEGER, cursorId) (FB_INTEGER, cursorId)
@ -468,10 +468,10 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
(FB_BIGINT, fetchMinElapsedTime) (FB_BIGINT, fetchMinElapsedTime)
(FB_BIGINT, fetchMaxElapsedTime) (FB_BIGINT, fetchMaxElapsedTime)
(FB_BIGINT, fetchTotalElapsedTime) (FB_BIGINT, fetchTotalElapsedTime)
) recSrcStatsMessage(status, MasterInterfacePtr()); ) recSrcStatMessage(status, MasterInterfacePtr());
recSrcStatsMessage.clear(); recSrcStatMessage.clear();
constexpr auto psqlStatsSql = R"""( constexpr auto psqlStatSql = R"""(
execute block ( execute block (
profile_id type of column plg$prof_psql_stats.profile_id = ?, profile_id type of column plg$prof_psql_stats.profile_id = ?,
request_id type of column plg$prof_psql_stats.request_id = ?, request_id type of column plg$prof_psql_stats.request_id = ?,
@ -505,7 +505,7 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
end end
)"""; )""";
FB_MESSAGE(PsqlStatsMessage, ThrowStatusExceptionWrapper, FB_MESSAGE(PsqlStatMessage, ThrowStatusExceptionWrapper,
(FB_BIGINT, profileId) (FB_BIGINT, profileId)
(FB_BIGINT, requestId) (FB_BIGINT, requestId)
(FB_INTEGER, lineNum) (FB_INTEGER, lineNum)
@ -515,8 +515,8 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
(FB_BIGINT, minElapsedTime) (FB_BIGINT, minElapsedTime)
(FB_BIGINT, maxElapsedTime) (FB_BIGINT, maxElapsedTime)
(FB_BIGINT, totalElapsedTime) (FB_BIGINT, totalElapsedTime)
) psqlStatsMessage(status, MasterInterfacePtr()); ) psqlStatMessage(status, MasterInterfacePtr());
psqlStatsMessage.clear(); psqlStatMessage.clear();
auto transaction = makeNoIncRef(userAttachment->startTransaction(status, 0, nullptr)); auto transaction = makeNoIncRef(userAttachment->startTransaction(status, 0, nullptr));
@ -524,17 +524,17 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
auto statementStmt = makeNoIncRef(userAttachment->prepare( auto statementStmt = makeNoIncRef(userAttachment->prepare(
status, transaction, 0, statementSql, SQL_DIALECT_CURRENT, 0)); status, transaction, 0, statementSql, SQL_DIALECT_CURRENT, 0));
auto recSrcsStmt = makeNoIncRef(userAttachment->prepare( auto recSrcsStmt = makeNoIncRef(userAttachment->prepare(
status, transaction, 0, recSrcsSql, SQL_DIALECT_CURRENT, 0)); status, transaction, 0, recSrcSql, SQL_DIALECT_CURRENT, 0));
auto requestBatch = makeNoIncRef(userAttachment->createBatch(status, transaction, 0, requestSql, SQL_DIALECT_CURRENT, auto requestBatch = makeNoIncRef(userAttachment->createBatch(status, transaction, 0, requestSql, SQL_DIALECT_CURRENT,
requestMessage.getMetadata(), 0, nullptr)); requestMessage.getMetadata(), 0, nullptr));
auto recSrcStatsBatch = makeNoIncRef(userAttachment->createBatch( auto recSrcStatsBatch = makeNoIncRef(userAttachment->createBatch(
status, transaction, 0, recSrcStatsSql, SQL_DIALECT_CURRENT, recSrcStatsMessage.getMetadata(), 0, nullptr)); status, transaction, 0, recSrcStatSql, SQL_DIALECT_CURRENT, recSrcStatMessage.getMetadata(), 0, nullptr));
auto psqlStatsBatch = makeNoIncRef(userAttachment->createBatch( auto psqlStatBatch = makeNoIncRef(userAttachment->createBatch(
status, transaction, 0, psqlStatsSql, SQL_DIALECT_CURRENT, psqlStatsMessage.getMetadata(), 0, nullptr)); status, transaction, 0, psqlStatSql, SQL_DIALECT_CURRENT, psqlStatMessage.getMetadata(), 0, nullptr));
unsigned requestBatchSize = 0; unsigned requestBatchSize = 0;
unsigned recSrcStatsBatchSize = 0; unsigned recSrcStatBatchSize = 0;
unsigned psqlStatsBatchSize = 0; unsigned psqlStatBatchSize = 0;
auto executeBatch = [&](IBatch* batch, unsigned& batchSize) auto executeBatch = [&](IBatch* batch, unsigned& batchSize)
{ {
@ -550,8 +550,8 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
auto executeBatches = [&]() auto executeBatches = [&]()
{ {
executeBatch(requestBatch, requestBatchSize); executeBatch(requestBatch, requestBatchSize);
executeBatch(recSrcStatsBatch, recSrcStatsBatchSize); executeBatch(recSrcStatsBatch, recSrcStatBatchSize);
executeBatch(psqlStatsBatch, psqlStatsBatchSize); executeBatch(psqlStatBatch, psqlStatBatchSize);
}; };
auto addBatch = [&](IBatch* batch, unsigned& batchSize, const auto& message) auto addBatch = [&](IBatch* batch, unsigned& batchSize, const auto& message)
@ -660,26 +660,26 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
const auto recSourceId = recSourceIt.first.second; const auto recSourceId = recSourceIt.first.second;
const auto& recSrc = recSourceIt.second; const auto& recSrc = recSourceIt.second;
recSrcsMessage->profileIdNull = FB_FALSE; recSrcMessage->profileIdNull = FB_FALSE;
recSrcsMessage->profileId = session->getId(); recSrcMessage->profileId = session->getId();
recSrcsMessage->statementIdNull = FB_FALSE; recSrcMessage->statementIdNull = FB_FALSE;
recSrcsMessage->statementId = statementId; recSrcMessage->statementId = statementId;
recSrcsMessage->cursorIdNull = FB_FALSE; recSrcMessage->cursorIdNull = FB_FALSE;
recSrcsMessage->cursorId = cursorId; recSrcMessage->cursorId = cursorId;
recSrcsMessage->recordSourceIdNull = FB_FALSE; recSrcMessage->recordSourceIdNull = FB_FALSE;
recSrcsMessage->recordSourceId = recSourceId; recSrcMessage->recordSourceId = recSourceId;
recSrcsMessage->parentRecordSourceIdNull = !recSrc.parentId.specified; recSrcMessage->parentRecordSourceIdNull = !recSrc.parentId.specified;
recSrcsMessage->parentRecordSourceId = recSrc.parentId.value; recSrcMessage->parentRecordSourceId = recSrc.parentId.value;
recSrcsMessage->accessPathNull = FB_FALSE; recSrcMessage->accessPathNull = FB_FALSE;
recSrcsMessage->accessPath.set(recSrc.accessPath.c_str()); recSrcMessage->accessPath.set(recSrc.accessPath.c_str());
recSrcsStmt->execute(status, transaction, recSrcsMessage.getMetadata(), recSrcsStmt->execute(status, transaction, recSrcMessage.getMetadata(),
recSrcsMessage.getData(), nullptr, nullptr); recSrcMessage.getData(), nullptr, nullptr);
} }
RightPooledMap<unsigned, Array<NonPooledPair<SINT64, Request>*>> requestsByLevel; RightPooledMap<unsigned, Array<NonPooledPair<SINT64, Request>*>> requestsByLevel;
@ -752,46 +752,46 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
const auto& cursorRecSource = statsIt.first; const auto& cursorRecSource = statsIt.first;
const auto& stats = statsIt.second; const auto& stats = statsIt.second;
recSrcStatsMessage->profileIdNull = FB_FALSE; recSrcStatMessage->profileIdNull = FB_FALSE;
recSrcStatsMessage->profileId = session->getId(); recSrcStatMessage->profileId = session->getId();
recSrcStatsMessage->requestIdNull = FB_FALSE; recSrcStatMessage->requestIdNull = FB_FALSE;
recSrcStatsMessage->requestId = profileRequestId; recSrcStatMessage->requestId = profileRequestId;
recSrcStatsMessage->cursorIdNull = FB_FALSE; recSrcStatMessage->cursorIdNull = FB_FALSE;
recSrcStatsMessage->cursorId = cursorRecSource.first; recSrcStatMessage->cursorId = cursorRecSource.first;
recSrcStatsMessage->recordSourceIdNull = FB_FALSE; recSrcStatMessage->recordSourceIdNull = FB_FALSE;
recSrcStatsMessage->recordSourceId = cursorRecSource.second; recSrcStatMessage->recordSourceId = cursorRecSource.second;
recSrcStatsMessage->statementIdNull = FB_FALSE; recSrcStatMessage->statementIdNull = FB_FALSE;
recSrcStatsMessage->statementId = profileRequest.statementId; recSrcStatMessage->statementId = profileRequest.statementId;
recSrcStatsMessage->openCounterNull = FB_FALSE; recSrcStatMessage->openCounterNull = FB_FALSE;
recSrcStatsMessage->openCounter = stats.openStats.counter; recSrcStatMessage->openCounter = stats.openStats.counter;
recSrcStatsMessage->openMinElapsedTimeNull = FB_FALSE; recSrcStatMessage->openMinElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->openMinElapsedTime = stats.openStats.minElapsedTime; recSrcStatMessage->openMinElapsedTime = stats.openStats.minElapsedTime;
recSrcStatsMessage->openMaxElapsedTimeNull = FB_FALSE; recSrcStatMessage->openMaxElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->openMaxElapsedTime = stats.openStats.maxElapsedTime; recSrcStatMessage->openMaxElapsedTime = stats.openStats.maxElapsedTime;
recSrcStatsMessage->openTotalElapsedTimeNull = FB_FALSE; recSrcStatMessage->openTotalElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->openTotalElapsedTime = stats.openStats.totalElapsedTime; recSrcStatMessage->openTotalElapsedTime = stats.openStats.totalElapsedTime;
recSrcStatsMessage->fetchCounterNull = FB_FALSE; recSrcStatMessage->fetchCounterNull = FB_FALSE;
recSrcStatsMessage->fetchCounter = stats.fetchStats.counter; recSrcStatMessage->fetchCounter = stats.fetchStats.counter;
recSrcStatsMessage->fetchMinElapsedTimeNull = FB_FALSE; recSrcStatMessage->fetchMinElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->fetchMinElapsedTime = stats.fetchStats.minElapsedTime; recSrcStatMessage->fetchMinElapsedTime = stats.fetchStats.minElapsedTime;
recSrcStatsMessage->fetchMaxElapsedTimeNull = FB_FALSE; recSrcStatMessage->fetchMaxElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->fetchMaxElapsedTime = stats.fetchStats.maxElapsedTime; recSrcStatMessage->fetchMaxElapsedTime = stats.fetchStats.maxElapsedTime;
recSrcStatsMessage->fetchTotalElapsedTimeNull = FB_FALSE; recSrcStatMessage->fetchTotalElapsedTimeNull = FB_FALSE;
recSrcStatsMessage->fetchTotalElapsedTime = stats.fetchStats.totalElapsedTime; recSrcStatMessage->fetchTotalElapsedTime = stats.fetchStats.totalElapsedTime;
addBatch(recSrcStatsBatch, recSrcStatsBatchSize, recSrcStatsMessage); addBatch(recSrcStatsBatch, recSrcStatBatchSize, recSrcStatMessage);
} }
profileRequest.recordSourcesStats.clear(); profileRequest.recordSourcesStats.clear();
@ -800,34 +800,34 @@ void ProfilerPlugin::flush(ThrowStatusExceptionWrapper* status)
{ {
const auto& lineColumn = statsIt.first; const auto& lineColumn = statsIt.first;
psqlStatsMessage->profileIdNull = FB_FALSE; psqlStatMessage->profileIdNull = FB_FALSE;
psqlStatsMessage->profileId = session->getId(); psqlStatMessage->profileId = session->getId();
psqlStatsMessage->requestIdNull = FB_FALSE; psqlStatMessage->requestIdNull = FB_FALSE;
psqlStatsMessage->requestId = profileRequestId; psqlStatMessage->requestId = profileRequestId;
psqlStatsMessage->lineNumNull = FB_FALSE; psqlStatMessage->lineNumNull = FB_FALSE;
psqlStatsMessage->lineNum = lineColumn.first; psqlStatMessage->lineNum = lineColumn.first;
psqlStatsMessage->columnNumNull = FB_FALSE; psqlStatMessage->columnNumNull = FB_FALSE;
psqlStatsMessage->columnNum = lineColumn.second; psqlStatMessage->columnNum = lineColumn.second;
psqlStatsMessage->statementIdNull = FB_FALSE; psqlStatMessage->statementIdNull = FB_FALSE;
psqlStatsMessage->statementId = profileRequest.statementId; psqlStatMessage->statementId = profileRequest.statementId;
psqlStatsMessage->counterNull = FB_FALSE; psqlStatMessage->counterNull = FB_FALSE;
psqlStatsMessage->counter = statsIt.second.counter; psqlStatMessage->counter = statsIt.second.counter;
psqlStatsMessage->minElapsedTimeNull = FB_FALSE; psqlStatMessage->minElapsedTimeNull = FB_FALSE;
psqlStatsMessage->minElapsedTime = statsIt.second.minElapsedTime; psqlStatMessage->minElapsedTime = statsIt.second.minElapsedTime;
psqlStatsMessage->maxElapsedTimeNull = FB_FALSE; psqlStatMessage->maxElapsedTimeNull = FB_FALSE;
psqlStatsMessage->maxElapsedTime = statsIt.second.maxElapsedTime; psqlStatMessage->maxElapsedTime = statsIt.second.maxElapsedTime;
psqlStatsMessage->totalElapsedTimeNull = FB_FALSE; psqlStatMessage->totalElapsedTimeNull = FB_FALSE;
psqlStatsMessage->totalElapsedTime = statsIt.second.totalElapsedTime; psqlStatMessage->totalElapsedTime = statsIt.second.totalElapsedTime;
addBatch(psqlStatsBatch, psqlStatsBatchSize, psqlStatsMessage); addBatch(psqlStatBatch, psqlStatBatchSize, psqlStatMessage);
} }
profileRequest.psqlStats.clear(); profileRequest.psqlStats.clear();
@ -913,9 +913,9 @@ void ProfilerPlugin::createMetadata(ThrowStatusExceptionWrapper* status, RefPtr<
on delete cascade on delete cascade
using index plg$prof_record_sources_profile, using index plg$prof_record_sources_profile,
statement_id bigint not null, statement_id bigint not null,
cursor_id bigint not null, cursor_id integer not null,
record_source_id bigint not null, record_source_id integer not null,
parent_record_source_id bigint, parent_record_source_id integer,
access_path varchar(1024) character set utf8 not null, access_path varchar(1024) character set utf8 not null,
constraint plg$prof_record_sources_pk constraint plg$prof_record_sources_pk
primary key (profile_id, statement_id, cursor_id, record_source_id) primary key (profile_id, statement_id, cursor_id, record_source_id)
@ -999,8 +999,8 @@ void ProfilerPlugin::createMetadata(ThrowStatusExceptionWrapper* status, RefPtr<
on delete cascade on delete cascade
using index plg$prof_record_source_stats_profile_id, using index plg$prof_record_source_stats_profile_id,
request_id bigint not null, request_id bigint not null,
cursor_id bigint not null, cursor_id integer not null,
record_source_id bigint not null, record_source_id integer not null,
statement_id bigint not null, statement_id bigint not null,
open_counter bigint not null, open_counter bigint not null,
open_min_elapsed_time bigint not null, open_min_elapsed_time bigint not null,
@ -1145,7 +1145,7 @@ void ProfilerPlugin::createMetadata(ThrowStatusExceptionWrapper* status, RefPtr<
max(rstat.fetch_max_elapsed_time) fetch_max_elapsed_time, max(rstat.fetch_max_elapsed_time) fetch_max_elapsed_time,
cast(sum(rstat.fetch_total_elapsed_time) as bigint) fetch_total_elapsed_time, cast(sum(rstat.fetch_total_elapsed_time) as bigint) fetch_total_elapsed_time,
cast(sum(rstat.fetch_total_elapsed_time) / nullif(sum(rstat.fetch_counter), 0) as bigint) fetch_avg_elapsed_time, cast(sum(rstat.fetch_total_elapsed_time) / nullif(sum(rstat.fetch_counter), 0) as bigint) fetch_avg_elapsed_time,
cast(coalesce(sum(rstat.open_total_elapsed_time), 0) + coalesce(sum(rstat.fetch_total_elapsed_time), 0) as bigint) open_fetch_total_time cast(coalesce(sum(rstat.open_total_elapsed_time), 0) + coalesce(sum(rstat.fetch_total_elapsed_time), 0) as bigint) open_fetch_total_elapsed_time
from plg$prof_record_source_stats rstat from plg$prof_record_source_stats rstat
join plg$prof_record_sources recsrc join plg$prof_record_sources recsrc
on recsrc.profile_id = rstat.profile_id and on recsrc.profile_id = rstat.profile_id and