Skip to content

Commit 42b4828

Browse files
committed
Fixes after self-review
1 parent 09fc662 commit 42b4828

File tree

7 files changed

+74
-136
lines changed

7 files changed

+74
-136
lines changed

collector.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ realloc_history(History *observations, int count)
9595
j;
9696
int serialized_size;
9797

98-
//saved_history_dimensions = pgws_history_dimensions; // TODO вроде как
9998
serialized_size = get_serialized_size(saved_history_dimensions, true);
10099

101100
/* Allocate new array for history */
@@ -578,9 +577,6 @@ probe_waits(History *observations, HTAB *profile_hash,
578577
LWLockAcquire(ProcArrayLock, LW_SHARED);
579578
for (i = 0; i < ProcGlobal->allProcCount; i++)
580579
{
581-
//HistoryItem item_history,
582-
// *observation;
583-
//ProfileItem item_profile;
584580
PGPROC *proc = &ProcGlobal->allProcs[i];
585581
int pid;
586582
uint32 wait_event_info;
@@ -611,9 +607,6 @@ probe_waits(History *observations, HTAB *profile_hash,
611607
&common_dimensions,
612608
saved_profile_dimensions);
613609

614-
//item_history.ts = ts;
615-
//item_history.dimensions = history_dimensions;
616-
617610
/* Write to the history if needed */
618611
if (write_history)
619612
{
@@ -646,7 +639,7 @@ probe_waits(History *observations, HTAB *profile_hash,
646639
&serialized_item, &serialized_key, &serialized_size,
647640
(TimestampTz) 0, count, false);
648641

649-
stored_item = (char *) hash_search(profile_hash, serialized_key,
642+
stored_item = (char *) hash_search(profile_hash, serialized_key,
650643
HASH_ENTER, &found);
651644

652645
if (found)
@@ -673,7 +666,7 @@ probe_waits(History *observations, HTAB *profile_hash,
673666
* Send waits history to shared memory queue.
674667
*/
675668
static void
676-
send_history(History *observations, shm_mq_handle *mqh) //TODO TODO TODO
669+
send_history(History *observations, shm_mq_handle *mqh)
677670
{
678671
int serialized_size = get_serialized_size(saved_history_dimensions, true);
679672
Size count,

expected/load.out

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
CREATE EXTENSION pg_wait_sampling;
22
\d pg_wait_sampling_current
3-
View "public.pg_wait_sampling_current"
4-
Column | Type | Modifiers
5-
------------+---------+-----------
6-
pid | integer |
7-
event_type | text |
8-
event | text |
9-
queryid | bigint |
3+
View "public.pg_wait_sampling_current"
4+
Column | Type | Collation | Nullable | Default
5+
---------------------+--------------------------+-----------+----------+---------
6+
pid | integer | | |
7+
event_type | text | | |
8+
event | text | | |
9+
queryid | bigint | | |
10+
role_id | bigint | | |
11+
database_id | bigint | | |
12+
parallel_leader_pid | integer | | |
13+
is_regular_backend | boolean | | |
14+
backend_type | text | | |
15+
backend_state | text | | |
16+
proc_start | timestamp with time zone | | |
17+
client_addr | text | | |
18+
client_hostname | text | | |
19+
appname | text | | |
1020

1121
\d pg_wait_sampling_history
12-
View "public.pg_wait_sampling_history"
13-
Column | Type | Modifiers
14-
------------+--------------------------+-----------
15-
pid | integer |
16-
ts | timestamp with time zone |
17-
event_type | text |
18-
event | text |
19-
queryid | bigint |
22+
View "public.pg_wait_sampling_history"
23+
Column | Type | Collation | Nullable | Default
24+
---------------------+--------------------------+-----------+----------+---------
25+
pid | integer | | |
26+
event_type | text | | |
27+
event | text | | |
28+
queryid | bigint | | |
29+
role_id | bigint | | |
30+
database_id | bigint | | |
31+
parallel_leader_pid | integer | | |
32+
is_regular_backend | boolean | | |
33+
backend_type | text | | |
34+
backend_state | text | | |
35+
proc_start | timestamp with time zone | | |
36+
client_addr | text | | |
37+
client_hostname | text | | |
38+
appname | text | | |
39+
ts | timestamp with time zone | | |
2040

2141
\d pg_wait_sampling_profile
22-
View "public.pg_wait_sampling_profile"
23-
Column | Type | Modifiers
24-
------------+---------+-----------
25-
pid | integer |
26-
event_type | text |
27-
event | text |
28-
queryid | bigint |
29-
count | bigint |
42+
View "public.pg_wait_sampling_profile"
43+
Column | Type | Collation | Nullable | Default
44+
---------------------+--------------------------+-----------+----------+---------
45+
pid | integer | | |
46+
event_type | text | | |
47+
event | text | | |
48+
queryid | bigint | | |
49+
role_id | bigint | | |
50+
database_id | bigint | | |
51+
parallel_leader_pid | integer | | |
52+
is_regular_backend | boolean | | |
53+
backend_type | text | | |
54+
backend_state | text | | |
55+
proc_start | timestamp with time zone | | |
56+
client_addr | text | | |
57+
client_hostname | text | | |
58+
appname | text | | |
59+
count | bigint | | |
3060

3161
DROP EXTENSION pg_wait_sampling;

expected/load_1.out

Lines changed: 0 additions & 31 deletions
This file was deleted.

expected/queries.out

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,6 @@ WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile)
2020
0
2121
(1 row)
2222

23-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_current_extended)
24-
SELECT sum(0) FROM generate_series(1, 2), t;
25-
sum
26-
-----
27-
0
28-
(1 row)
29-
30-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_history_extended)
31-
SELECT sum(0) FROM generate_series(1, 2), t;
32-
sum
33-
-----
34-
0
35-
(1 row)
36-
37-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile_extended)
38-
SELECT sum(0) FROM generate_series(1, 2), t;
39-
sum
40-
-----
41-
0
42-
(1 row)
43-
4423
-- Some dummy checks just to be sure that all our functions work and return something.
4524
SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current(pg_backend_pid());
4625
test
@@ -66,28 +45,4 @@ SELECT pg_wait_sampling_reset_profile();
6645

6746
(1 row)
6847

69-
SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current_extended(pg_backend_pid());
70-
test
71-
------
72-
t
73-
(1 row)
74-
75-
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile_extended();
76-
test
77-
------
78-
t
79-
(1 row)
80-
81-
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history_extended();
82-
test
83-
------
84-
t
85-
(1 row)
86-
87-
SELECT pg_wait_sampling_reset_profile();
88-
pg_wait_sampling_reset_profile
89-
--------------------------------
90-
91-
(1 row)
92-
9348
DROP EXTENSION pg_wait_sampling;

pg_wait_sampling.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,9 @@ pgws_general_dimensions_check_hook (char **newvalue, void **extra, GucSource sou
334334
int extrachecks = 0;
335335
int *myextra;
336336

337-
/* Check special cases when we turn all or none dimensions */
337+
/* Check special case when we turn all dimensions */
338338
if (pg_strcasecmp(*newvalue, "all") == 0)
339339
extrachecks = PGWS_DIMENSIONS_ALL;
340-
else if (pg_strcasecmp(*newvalue, "none") == 0)
341-
extrachecks = PGWS_DIMENSIONS_NONE;
342340
else
343341
{
344342
/* Need a modifiable copy of string */
@@ -388,7 +386,7 @@ pgws_general_dimensions_check_hook (char **newvalue, void **extra, GucSource sou
388386
extrachecks |= PGWS_DIMENSIONS_CLIENT_HOSTNAME;
389387
else if (pg_strcasecmp(tok, "appname") == 0)
390388
extrachecks |= PGWS_DIMENSIONS_APPNAME;
391-
else if (pg_strcasecmp(tok, "all") == 0 || pg_strcasecmp(tok, "none") == 0)
389+
else if (pg_strcasecmp(tok, "all") == 0)
392390
{
393391
GUC_check_errdetail("Key word \"%s\" cannot be combined with other key words.", tok);
394392
pfree(rawstring);
@@ -747,8 +745,17 @@ get_beentry_by_procpid(int pid)
747745
/* Here beid is just index in localBackendStatusTable */
748746
local_beentry = pgstat_fetch_stat_local_beentry(cur_be_idx);
749747
#endif
748+
#if defined(PGPRO_EE) || defined(PGPRO_STD) && PG_VERSION_NUM >= 160000
750749
if (local_beentry->backendStatus->st_procpid == pid)
751750
return local_beentry->backendStatus;
751+
#else
752+
if (local_beentry->backendStatus.st_procpid == pid)
753+
{
754+
PgBackendStatus *result = palloc0(sizeof(PgBackendStatus));
755+
*result = local_beentry->backendStatus;
756+
return result;
757+
}
758+
#endif
752759
}
753760
return NULL;
754761
}
@@ -831,12 +838,12 @@ fill_values_and_nulls(Datum *values, bool *nulls, SamplingDimensions dimensions,
831838
values[3] = UInt64GetDatum(dimensions.queryId);
832839
else
833840
values[3] = (Datum) 0;
834-
if (dimensions_mask & PGWS_DIMENSIONS_ROLE_ID)
835-
values[4] = ObjectIdGetDatum(dimensions.role_id);
836-
else
837-
nulls[4] = true;
838841
if (api_version >= PGWS_V1_2)
839842
{
843+
if (dimensions_mask & PGWS_DIMENSIONS_ROLE_ID)
844+
values[4] = ObjectIdGetDatum(dimensions.role_id);
845+
else
846+
nulls[4] = true;
840847
if (dimensions_mask & PGWS_DIMENSIONS_DB_ID)
841848
values[5] = ObjectIdGetDatum(dimensions.database_id);
842849
else
@@ -887,7 +894,7 @@ PG_FUNCTION_INFO_V1(pg_wait_sampling_get_current_1_2);
887894
Datum
888895
pg_wait_sampling_get_current_1_2(PG_FUNCTION_ARGS)
889896
{
890-
return pg_wait_sampling_get_current_internal(fcinfo, PGWS_V1_2);
897+
return pg_wait_sampling_get_current_internal(fcinfo, PGWS_V1_2);
891898
}
892899

893900
Datum
@@ -1187,7 +1194,7 @@ PG_FUNCTION_INFO_V1(pg_wait_sampling_get_profile_1_2);
11871194
Datum
11881195
pg_wait_sampling_get_profile_1_2(PG_FUNCTION_ARGS)
11891196
{
1190-
return pg_wait_sampling_get_profile_internal(fcinfo, PGWS_V1_2);
1197+
return pg_wait_sampling_get_profile_internal(fcinfo, PGWS_V1_2);
11911198
}
11921199

11931200
Datum
@@ -1328,7 +1335,7 @@ pg_wait_sampling_reset_history(PG_FUNCTION_ARGS)
13281335
LockAcquire(&collectorTag, ExclusiveLock, false, false);
13291336
pgws_collector_hdr->request = HISTORY_RESET;
13301337
LockRelease(&collectorTag, ExclusiveLock, false);
1331-
1338+
13321339
if (!pgws_collector_hdr->latch)
13331340
ereport(ERROR, (errcode(ERRCODE_INTERNAL_ERROR),
13341341
errmsg("pg_wait_sampling collector wasn't started")));
@@ -1351,7 +1358,7 @@ PG_FUNCTION_INFO_V1(pg_wait_sampling_get_history_1_2);
13511358
Datum
13521359
pg_wait_sampling_get_history_1_2(PG_FUNCTION_ARGS)
13531360
{
1354-
return pg_wait_sampling_get_history_internal(fcinfo, PGWS_V1_2);
1361+
return pg_wait_sampling_get_history_internal(fcinfo, PGWS_V1_2);
13551362
}
13561363

13571364
Datum

pg_wait_sampling.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828
#define PGWS_COLLECTOR_LOCK 1
2929

3030
/* Values for sampling dimensions */
31-
#define PGWS_DIMENSIONS_NONE 0
32-
3331
#define PGWS_DIMENSIONS_PID (1 << 0)
3432
#define PGWS_DIMENSIONS_WAIT_EVENT_TYPE (1 << 1)
3533
#define PGWS_DIMENSIONS_WAIT_EVENT (1 << 2)

sql/queries.sql

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,10 @@ WITH t as (SELECT sum(0) FROM pg_wait_sampling_history)
99
WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile)
1010
SELECT sum(0) FROM generate_series(1, 2), t;
1111

12-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_current_extended)
13-
SELECT sum(0) FROM generate_series(1, 2), t;
14-
15-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_history_extended)
16-
SELECT sum(0) FROM generate_series(1, 2), t;
17-
18-
WITH t as (SELECT sum(0) FROM pg_wait_sampling_profile_extended)
19-
SELECT sum(0) FROM generate_series(1, 2), t;
20-
2112
-- Some dummy checks just to be sure that all our functions work and return something.
2213
SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current(pg_backend_pid());
2314
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile();
2415
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history();
2516
SELECT pg_wait_sampling_reset_profile();
2617

27-
SELECT count(*) = 1 as test FROM pg_wait_sampling_get_current_extended(pg_backend_pid());
28-
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_profile_extended();
29-
SELECT count(*) >= 0 as test FROM pg_wait_sampling_get_history_extended();
30-
SELECT pg_wait_sampling_reset_profile();
31-
3218
DROP EXTENSION pg_wait_sampling;

0 commit comments

Comments
 (0)