Skip to content

Commit 2f2f5fe

Browse files
committed
Design for future extensions with different timings types.
Add ProfilerStats interface and pass it to plugin instead of runTime parameter. Rename *_TIME columns to *_ELAPSED_TIME.
1 parent fb9f5c6 commit 2f2f5fe

File tree

9 files changed

+369
-213
lines changed

9 files changed

+369
-213
lines changed

doc/sql.extensions/README.profiler.md

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Below is the list of tables that stores profile data.
266266
- `CALLER_REQUEST_ID` type `BIGINT` - Caller request ID
267267
- `START_TIMESTAMP` type `TIMESTAMP WITH TIME ZONE` - Moment this request was first gathered profile data
268268
- `FINISH_TIMESTAMP` type `TIMESTAMP WITH TIME ZONE` - Moment this request was finished
269-
- `TOTAL_TIME` type `BIGINT` - Accumulated execution time (in nanoseconds) of the request
269+
- `TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the request
270270
- Primary key: `PROFILE_ID, REQUEST_ID`
271271

272272
## Table `PLG$PROF_PSQL_STATS`
@@ -277,9 +277,9 @@ Below is the list of tables that stores profile data.
277277
- `COLUMN_NUM` type `INTEGER` - Column number of the statement
278278
- `STATEMENT_ID` type `BIGINT` - Statement ID
279279
- `COUNTER` type `BIGINT` - Number of executed times of the line/column
280-
- `MIN_TIME` type `BIGINT` - Minimal time (in nanoseconds) of a line/column execution
281-
- `MAX_TIME` type `BIGINT` - Maximum time (in nanoseconds) of a line/column execution
282-
- `TOTAL_TIME` type `BIGINT` - Accumulated execution time (in nanoseconds) of the line/column
280+
- `MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a line/column execution
281+
- `MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a line/column execution
282+
- `TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the line/column executions
283283
- Primary key: `PROFILE_ID, REQUEST_ID, LINE_NUM, COLUMN_NUM`
284284

285285
## Table `PLG$PROF_RECORD_SOURCE_STATS`
@@ -290,13 +290,13 @@ Below is the list of tables that stores profile data.
290290
- `RECORD_SOURCE_ID` type `BIGINT` - Record source ID
291291
- `STATEMENT_ID` type `BIGINT` - Statement ID
292292
- `OPEN_COUNTER` type `BIGINT` - Number of open times of the record source
293-
- `OPEN_MIN_TIME` type `BIGINT` - Minimal time (in nanoseconds) of a record source open
294-
- `OPEN_MAX_TIME` type `BIGINT` - Maximum time (in nanoseconds) of a record source open
295-
- `OPEN_TOTAL_TIME` type `BIGINT` - Accumulated open time (in nanoseconds) of the record source
293+
- `OPEN_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source open
294+
- `OPEN_MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a record source open
295+
- `OPEN_TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the record source openings
296296
- `FETCH_COUNTER` type `BIGINT` - Number of fetch times of the record source
297-
- `FETCH_MIN_TIME` type `BIGINT` - Minimal time (in nanoseconds) of a record source fetch
298-
- `FETCH_MAX_TIME` type `BIGINT` - Maximum time (in nanoseconds) of a record source fetch
299-
- `FETCH_TOTAL_TIME` type `BIGINT` - Accumulated fetch time (in nanoseconds) of the record source
297+
- `FETCH_MIN_ELAPSED_TIME` type `BIGINT` - Minimal elapsed time (in nanoseconds) of a record source fetch
298+
- `FETCH_MAX_ELAPSED_TIME` type `BIGINT` - Maximum elapsed time (in nanoseconds) of a record source fetch
299+
- `FETCH_TOTAL_ELAPSED_TIME` type `BIGINT` - Accumulated elapsed time (in nanoseconds) of the record source fetches
300300
- Primary key: `PROFILE_ID, REQUEST_ID, CURSOR_ID, RECORD_SOURCE_ID`
301301

302302
# Auxiliary views
@@ -323,10 +323,10 @@ select req.profile_id,
323323
statement_id = coalesce(sta.parent_statement_id, req.statement_id)
324324
) sql_text,
325325
count(*) counter,
326-
min(req.total_time) min_time,
327-
max(req.total_time) max_time,
328-
cast(sum(req.total_time) as bigint) total_time,
329-
cast(sum(req.total_time) / count(*) as bigint) avg_time
326+
min(req.total_elapsed_time) min_elapsed_time,
327+
max(req.total_elapsed_time) max_elapsed_time,
328+
cast(sum(req.total_elapsed_time) as bigint) total_elapsed_time,
329+
cast(sum(req.total_elapsed_time) / count(*) as bigint) avg_elapsed_time
330330
from plg$prof_requests req
331331
join plg$prof_statements sta
332332
on sta.profile_id = req.profile_id and
@@ -342,7 +342,7 @@ select req.profile_id,
342342
sta.parent_statement_id,
343343
sta_parent.statement_type,
344344
sta_parent.routine_name
345-
order by sum(req.total_time) desc
345+
order by sum(req.total_elapsed_time) desc
346346
```
347347

348348
## View `PLG$PROF_PSQL_STATS_VIEW`
@@ -363,10 +363,10 @@ select pstat.profile_id,
363363
pstat.line_num,
364364
pstat.column_num,
365365
cast(sum(pstat.counter) as bigint) counter,
366-
min(pstat.min_time) min_time,
367-
max(pstat.max_time) max_time,
368-
cast(sum(pstat.total_time) as bigint) total_time,
369-
cast(sum(pstat.total_time) / nullif(sum(pstat.counter), 0) as bigint) avg_time
366+
min(pstat.min_elapsed_time) min_elapsed_time,
367+
max(pstat.max_elapsed_time) max_elapsed_time,
368+
cast(sum(pstat.total_elapsed_time) as bigint) total_elapsed_time,
369+
cast(sum(pstat.total_elapsed_time) / nullif(sum(pstat.counter), 0) as bigint) avg_elapsed_time
370370
from plg$prof_psql_stats pstat
371371
join plg$prof_statements sta
372372
on sta.profile_id = pstat.profile_id and
@@ -384,7 +384,7 @@ select pstat.profile_id,
384384
sta_parent.routine_name,
385385
pstat.line_num,
386386
pstat.column_num
387-
order by sum(pstat.total_time) desc
387+
order by sum(pstat.total_elapsed_time) desc
388388
```
389389

390390
## View `PLG$PROF_RECORD_SOURCE_STATS_VIEW`
@@ -407,16 +407,16 @@ select rstat.profile_id,
407407
recsrc.parent_record_source_id,
408408
recsrc.access_path,
409409
cast(sum(rstat.open_counter) as bigint) open_counter,
410-
min(rstat.open_min_time) open_min_time,
411-
max(rstat.open_max_time) open_max_time,
412-
cast(sum(rstat.open_total_time) as bigint) open_total_time,
413-
cast(sum(rstat.open_total_time) / nullif(sum(rstat.open_counter), 0) as bigint) open_avg_time,
410+
min(rstat.open_min_elapsed_time) open_min_elapsed_time,
411+
max(rstat.open_max_elapsed_time) open_max_elapsed_time,
412+
cast(sum(rstat.open_total_elapsed_time) as bigint) open_total_elapsed_time,
413+
cast(sum(rstat.open_total_elapsed_time) / nullif(sum(rstat.open_counter), 0) as bigint) open_avg_elapsed_time,
414414
cast(sum(rstat.fetch_counter) as bigint) fetch_counter,
415-
min(rstat.fetch_min_time) fetch_min_time,
416-
max(rstat.fetch_max_time) fetch_max_time,
417-
cast(sum(rstat.fetch_total_time) as bigint) fetch_total_time,
418-
cast(sum(rstat.fetch_total_time) / nullif(sum(rstat.fetch_counter), 0) as bigint) fetch_avg_time,
419-
cast(coalesce(sum(rstat.open_total_time), 0) + coalesce(sum(rstat.fetch_total_time), 0) as bigint) open_fetch_total_time
415+
min(rstat.fetch_min_elapsed_time) fetch_min_elapsed_time,
416+
max(rstat.fetch_max_elapsed_time) fetch_max_elapsed_time,
417+
cast(sum(rstat.fetch_total_elapsed_time) as bigint) fetch_total_elapsed_time,
418+
cast(sum(rstat.fetch_total_elapsed_time) / nullif(sum(rstat.fetch_counter), 0) as bigint) fetch_avg_elapsed_time,
419+
cast(coalesce(sum(rstat.open_total_elapsed_time), 0) + coalesce(sum(rstat.fetch_total_elapsed_time), 0) as bigint) open_fetch_total_elapsed_time
420420
from plg$prof_record_source_stats rstat
421421
join plg$prof_record_sources recsrc
422422
on recsrc.profile_id = rstat.profile_id and
@@ -441,5 +441,5 @@ select rstat.profile_id,
441441
rstat.record_source_id,
442442
recsrc.parent_record_source_id,
443443
recsrc.access_path
444-
order by coalesce(sum(rstat.open_total_time), 0) + coalesce(sum(rstat.fetch_total_time), 0) desc
444+
order by coalesce(sum(rstat.open_total_elapsed_time), 0) + coalesce(sum(rstat.fetch_total_elapsed_time), 0) desc
445445
```

src/include/firebird/FirebirdInterface.idl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,8 +1721,6 @@ interface ProfilerSession : Disposable
17211721

17221722
void finish(Status status, ISC_TIMESTAMP_TZ timestamp);
17231723

1724-
//// FIXME: Add memory stats
1725-
17261724
void defineStatement(Status status, int64 statementId, int64 parentStatementId,
17271725
const string type, const string packageName, const string routineName, const string sqlText);
17281726

@@ -1734,14 +1732,19 @@ interface ProfilerSession : Disposable
17341732
void onRequestStart(Status status, int64 requestId, int64 statementId, int64 callerRequestId,
17351733
ISC_TIMESTAMP_TZ timestamp);
17361734

1737-
void onRequestFinish(Status status, int64 requestId, ISC_TIMESTAMP_TZ timestamp, uint64 runTime);
1735+
void onRequestFinish(Status status, int64 requestId, ISC_TIMESTAMP_TZ timestamp, ProfilerStats stats);
17381736

17391737
void beforePsqlLineColumn(int64 requestId, uint line, uint column);
1740-
void afterPsqlLineColumn(int64 requestId, uint line, uint column, uint64 runTime);
1738+
void afterPsqlLineColumn(int64 requestId, uint line, uint column, ProfilerStats stats);
17411739

17421740
void beforeRecordSourceOpen(int64 requestId, uint cursorId, uint recSourceId);
1743-
void afterRecordSourceOpen(int64 requestId, uint cursorId, uint recSourceId, uint64 runTime);
1741+
void afterRecordSourceOpen(int64 requestId, uint cursorId, uint recSourceId, ProfilerStats stats);
17441742

17451743
void beforeRecordSourceGetRecord(int64 requestId, uint cursorId, uint recSourceId);
1746-
void afterRecordSourceGetRecord(int64 requestId, uint cursorId, uint recSourceId, uint64 runTime);
1744+
void afterRecordSourceGetRecord(int64 requestId, uint cursorId, uint recSourceId, ProfilerStats stats);
1745+
}
1746+
1747+
interface ProfilerStats : Versioned
1748+
{
1749+
uint64 getElapsedTime();
17471750
}

0 commit comments

Comments
 (0)