Skip to content

Commit 00bb8e4

Browse files
committed
Improvement #7652 - Make the profiler store aggregated requests by default, with option for detailed store.
1 parent cfffebf commit 00bb8e4

File tree

9 files changed

+317
-250
lines changed

9 files changed

+317
-250
lines changed

doc/sql.extensions/README.profiler.md

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ set term ;!
5757
5858
-- Start profiling
5959
60-
select rdb$profiler.start_session('Profile Session 1') from rdb$database;
60+
select rdb$profiler.start_session('Profile Session 1', null, null, null, 'DETAILED_REQUESTS') from rdb$database;
6161
6262
set term !;
6363
@@ -126,16 +126,20 @@ select pstat.*
126126

127127
`RDB$PROFILER.START_SESSION` starts a new profiler session, makes it the current session (of the given `ATTACHMENT_ID`) and returns its identifier.
128128

129-
If `FLUSH_INTERVAL` is different from `NULL`, auto-flush is setup in the same way as manually calling `RDB$PROFILER.SET_FLUSH_INTERVAL`.
129+
If `FLUSH_INTERVAL` is different than `NULL`, auto-flush is setup in the same way as manually calling `RDB$PROFILER.SET_FLUSH_INTERVAL`.
130130

131131
If `PLUGIN_NAME` is `NULL` (the default), it uses the database configuration `DefaultProfilerPlugin`.
132132

133-
`PLUGIN_OPTIONS` are plugin specific options and currently should be `NULL` for `Default_Profiler` plugin.
133+
`PLUGIN_OPTIONS` are plugin specific options and currently could be `NULL` or the string `DETAILED_REQUESTS` for `Default_Profiler` plugin.
134+
135+
When `DETAILED_REQUESTS` is used, `PLG$PROF_REQUESTS` will store detailed requests data, i.e., one record per each invocation of a statement. This may generate a lot of records, causing `RDB$PROFILER.FLUSH` to be slow.
136+
137+
When `DETAILED_REQUESTS` is not used (the default), `PLG$PROF_REQUESTS` stores an aggregated record per statement, using `REQUEST_ID = 0`.
134138

135139
Input parameters:
136140
- `DESCRIPTION` type `VARCHAR(255) CHARACTER SET UTF8` default `NULL`
137141
- `FLUSH_INTERVAL` type `INTEGER` default `NULL`
138-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
142+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
139143
- `PLUGIN_NAME` type `VARCHAR(255) CHARACTER SET UTF8` default `NULL`
140144
- `PLUGIN_OPTIONS` type `VARCHAR(255) CHARACTER SET UTF8` default `NULL`
141145

@@ -151,14 +155,14 @@ Calling `RDB$PROFILER.PAUSE_SESSION(TRUE)` has the same semantics of calling `RD
151155

152156
Input parameters:
153157
- `FLUSH` type `BOOLEAN NOT NULL` default `FALSE`
154-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
158+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
155159

156160
## Procedure `RESUME_SESSION`
157161

158162
`RDB$PROFILER.RESUME_SESSION` resumes the current profiler session (of the given `ATTACHMENT_ID`), if it was paused, so the next executed statements statistics are collected again.
159163

160164
Input parameters:
161-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
165+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
162166

163167
## Procedure `FINISH_SESSION`
164168

@@ -170,7 +174,7 @@ Calling `RDB$PROFILER.FINISH_SESSION(TRUE)` has the same semantics of calling `R
170174

171175
Input parameters:
172176
- `FLUSH` type `BOOLEAN NOT NULL` default `TRUE`
173-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
177+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
174178

175179
## Procedure `CANCEL_SESSION`
176180

@@ -181,7 +185,7 @@ All session data present in the profiler plugin is discarded and will not be flu
181185
Data already flushed is not deleted automatically.
182186

183187
Input parameters:
184-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
188+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
185189

186190
## Procedure `DISCARD`
187191

@@ -190,7 +194,7 @@ Input parameters:
190194
If there is a active session, it is cancelled.
191195

192196
Input parameters:
193-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
197+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
194198

195199
## Procedure `FLUSH`
196200

@@ -203,7 +207,7 @@ Data is updated using an autonomous transaction, so if the procedure is called i
203207
Once flush happens, finished sessions are removed from memory.
204208

205209
Input parameters:
206-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
210+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
207211

208212
## Procedure `SET_FLUSH_INTERVAL`
209213

@@ -213,7 +217,7 @@ Input parameters:
213217

214218
Input parameters:
215219
- `FLUSH_INTERVAL` type `INTEGER NOT NULL`
216-
- `ATTACHMENT_ID` type `BIGINT NOT NULL` default `CURRENT_CONNECTION`
220+
- `ATTACHMENT_ID` type `BIGINT` default `NULL` (meaning `CURRENT_CONNECTION`)
217221

218222
# Snapshot tables
219223

@@ -267,34 +271,35 @@ Below is the list of tables that stores profile data.
267271
## Table `PLG$PROF_REQUESTS`
268272

269273
- `PROFILE_ID` type `BIGINT` - Profile session ID
270-
- `REQUEST_ID` type `BIGINT` - Request ID
271274
- `STATEMENT_ID` type `BIGINT` - Statement ID
275+
- `REQUEST_ID` type `BIGINT` - Request ID
276+
- `CALLER_STATEMENT_ID` type `BIGINT` - Caller statement ID
272277
- `CALLER_REQUEST_ID` type `BIGINT` - Caller request ID
273278
- `START_TIMESTAMP` type `TIMESTAMP WITH TIME ZONE` - Moment this request was first gathered profile data
274279
- `FINISH_TIMESTAMP` type `TIMESTAMP WITH TIME ZONE` - Moment this request was finished
275280
- `TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the request
276-
- Primary key: `PROFILE_ID, REQUEST_ID`
281+
- Primary key: `PROFILE_ID, STATEMENT_ID, REQUEST_ID`
277282

278283
## Table `PLG$PROF_PSQL_STATS`
279284

280285
- `PROFILE_ID` type `BIGINT` - Profile session ID
286+
- `STATEMENT_ID` type `BIGINT` - Statement ID
281287
- `REQUEST_ID` type `BIGINT` - Request ID
282288
- `LINE_NUM` type `INTEGER` - Line number of the statement
283289
- `COLUMN_NUM` type `INTEGER` - Column number of the statement
284-
- `STATEMENT_ID` type `BIGINT` - Statement ID
285290
- `COUNTER` type `BIGINT` - Number of executed times of the line/column
286291
- `MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a line/column execution
287292
- `MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a line/column execution
288293
- `TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the line/column executions
289-
- Primary key: `PROFILE_ID, REQUEST_ID, LINE_NUM, COLUMN_NUM`
294+
- Primary key: `PROFILE_ID, STATEMENT_ID, REQUEST_ID, LINE_NUM, COLUMN_NUM`
290295

291296
## Table `PLG$PROF_RECORD_SOURCE_STATS`
292297

293298
- `PROFILE_ID` type `BIGINT` - Profile session ID
299+
- `STATEMENT_ID` type `BIGINT` - Statement ID
294300
- `REQUEST_ID` type `BIGINT` - Request ID
295301
- `CURSOR_ID` type `INTEGER` - Cursor ID
296302
- `RECORD_SOURCE_ID` type `INTEGER` - Record source ID
297-
- `STATEMENT_ID` type `BIGINT` - Statement ID
298303
- `OPEN_COUNTER` type `BIGINT` - Number of open times of the record source
299304
- `OPEN_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source open
300305
- `OPEN_MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a record source open
@@ -303,7 +308,7 @@ Below is the list of tables that stores profile data.
303308
- `FETCH_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source fetch
304309
- `FETCH_MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a record source fetch
305310
- `FETCH_TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the record source fetches
306-
- Primary key: `PROFILE_ID, REQUEST_ID, CURSOR_ID, RECORD_SOURCE_ID`
311+
- Primary key: `PROFILE_ID, STATEMENT_ID, REQUEST_ID, CURSOR_ID, RECORD_SOURCE_ID`
307312

308313
# Auxiliary views
309314

src/include/firebird/FirebirdInterface.idl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1746,19 +1746,22 @@ interface ProfilerSession : Disposable
17461746
void defineRecordSource(int64 statementId, uint cursorId, uint recSourceId,
17471747
const string accessPath, uint parentRecSourceId);
17481748

1749-
void onRequestStart(Status status, int64 requestId, int64 statementId, int64 callerRequestId,
1750-
ISC_TIMESTAMP_TZ timestamp);
1749+
void onRequestStart(Status status, int64 statementId, int64 requestId,
1750+
int64 callerStatementId, int64 callerRequestId, ISC_TIMESTAMP_TZ timestamp);
17511751

1752-
void onRequestFinish(Status status, int64 requestId, ISC_TIMESTAMP_TZ timestamp, ProfilerStats stats);
1752+
void onRequestFinish(Status status, int64 statementId, int64 requestId,
1753+
ISC_TIMESTAMP_TZ timestamp, ProfilerStats stats);
17531754

1754-
void beforePsqlLineColumn(int64 requestId, uint line, uint column);
1755-
void afterPsqlLineColumn(int64 requestId, uint line, uint column, ProfilerStats stats);
1755+
void beforePsqlLineColumn(int64 statementId, int64 requestId, uint line, uint column);
1756+
void afterPsqlLineColumn(int64 statementId, int64 requestId, uint line, uint column, ProfilerStats stats);
17561757

1757-
void beforeRecordSourceOpen(int64 requestId, uint cursorId, uint recSourceId);
1758-
void afterRecordSourceOpen(int64 requestId, uint cursorId, uint recSourceId, ProfilerStats stats);
1758+
void beforeRecordSourceOpen(int64 statementId, int64 requestId, uint cursorId, uint recSourceId);
1759+
void afterRecordSourceOpen(int64 statementId, int64 requestId, uint cursorId, uint recSourceId,
1760+
ProfilerStats stats);
17591761

1760-
void beforeRecordSourceGetRecord(int64 requestId, uint cursorId, uint recSourceId);
1761-
void afterRecordSourceGetRecord(int64 requestId, uint cursorId, uint recSourceId, ProfilerStats stats);
1762+
void beforeRecordSourceGetRecord(int64 statementId, int64 requestId, uint cursorId, uint recSourceId);
1763+
void afterRecordSourceGetRecord(int64 statementId, int64 requestId, uint cursorId, uint recSourceId,
1764+
ProfilerStats stats);
17621765
}
17631766

17641767
interface ProfilerStats : Versioned

0 commit comments

Comments
 (0)