48
48
#include "postmaster/autovacuum.h"
49
49
#include "postmaster/fork_process.h"
50
50
#include "postmaster/postmaster.h"
51
- #include "storage/proc.h"
52
51
#include "storage/backendid.h"
53
52
#include "storage/dsm.h"
54
53
#include "storage/fd.h"
55
54
#include "storage/ipc.h"
56
55
#include "storage/latch.h"
56
+ #include "storage/lmgr.h"
57
57
#include "storage/pg_shmem.h"
58
58
#include "storage/procsignal.h"
59
59
#include "storage/sinvaladt.h"
@@ -2723,7 +2723,6 @@ pgstat_bestart(void)
2723
2723
#else
2724
2724
beentry -> st_ssl = false;
2725
2725
#endif
2726
- beentry -> st_waiting = false;
2727
2726
beentry -> st_state = STATE_UNDEFINED ;
2728
2727
beentry -> st_appname [0 ] = '\0' ;
2729
2728
beentry -> st_activity [0 ] = '\0' ;
@@ -2810,6 +2809,8 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2810
2809
{
2811
2810
if (beentry -> st_state != STATE_DISABLED )
2812
2811
{
2812
+ volatile PGPROC * proc = MyProc ;
2813
+
2813
2814
/*
2814
2815
* track_activities is disabled, but we last reported a
2815
2816
* non-disabled state. As our final update, change the state and
@@ -2820,9 +2821,9 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
2820
2821
beentry -> st_state_start_timestamp = 0 ;
2821
2822
beentry -> st_activity [0 ] = '\0' ;
2822
2823
beentry -> st_activity_start_timestamp = 0 ;
2823
- /* st_xact_start_timestamp and st_waiting are also disabled */
2824
+ /* st_xact_start_timestamp and wait_event_info are also disabled */
2824
2825
beentry -> st_xact_start_timestamp = 0 ;
2825
- beentry -> st_waiting = false ;
2826
+ proc -> wait_event_info = 0 ;
2826
2827
pgstat_increment_changecount_after (beentry );
2827
2828
}
2828
2829
return ;
@@ -2978,32 +2979,6 @@ pgstat_report_xact_timestamp(TimestampTz tstamp)
2978
2979
pgstat_increment_changecount_after (beentry );
2979
2980
}
2980
2981
2981
- /* ----------
2982
- * pgstat_report_waiting() -
2983
- *
2984
- * Called from lock manager to report beginning or end of a lock wait.
2985
- *
2986
- * NB: this *must* be able to survive being called before MyBEEntry has been
2987
- * initialized.
2988
- * ----------
2989
- */
2990
- void
2991
- pgstat_report_waiting (bool waiting )
2992
- {
2993
- volatile PgBackendStatus * beentry = MyBEEntry ;
2994
-
2995
- if (!pgstat_track_activities || !beentry )
2996
- return ;
2997
-
2998
- /*
2999
- * Since this is a single-byte field in a struct that only this process
3000
- * may modify, there seems no need to bother with the st_changecount
3001
- * protocol. The update must appear atomic in any case.
3002
- */
3003
- beentry -> st_waiting = waiting ;
3004
- }
3005
-
3006
-
3007
2982
/* ----------
3008
2983
* pgstat_read_current_status() -
3009
2984
*
@@ -3119,6 +3094,87 @@ pgstat_read_current_status(void)
3119
3094
localBackendStatusTable = localtable ;
3120
3095
}
3121
3096
3097
+ /* ----------
3098
+ * pgstat_get_wait_event_type() -
3099
+ *
3100
+ * Return a string representing the current wait event type, backend is
3101
+ * waiting on.
3102
+ */
3103
+ const char *
3104
+ pgstat_get_wait_event_type (uint32 wait_event_info )
3105
+ {
3106
+ uint8 classId ;
3107
+ const char * event_type ;
3108
+
3109
+ /* report process as not waiting. */
3110
+ if (wait_event_info == 0 )
3111
+ return NULL ;
3112
+
3113
+ wait_event_info = wait_event_info >> 24 ;
3114
+ classId = wait_event_info & 0XFF ;
3115
+
3116
+ switch (classId )
3117
+ {
3118
+ case WAIT_LWLOCK_NAMED :
3119
+ event_type = "LWLockNamed" ;
3120
+ break ;
3121
+ case WAIT_LWLOCK_TRANCHE :
3122
+ event_type = "LWLockTranche" ;
3123
+ break ;
3124
+ case WAIT_LOCK :
3125
+ event_type = "Lock" ;
3126
+ break ;
3127
+ case WAIT_BUFFER_PIN :
3128
+ event_type = "BufferPin" ;
3129
+ break ;
3130
+ default :
3131
+ event_type = "???" ;
3132
+ break ;
3133
+ }
3134
+
3135
+ return event_type ;
3136
+ }
3137
+
3138
+ /* ----------
3139
+ * pgstat_get_wait_event() -
3140
+ *
3141
+ * Return a string representing the current wait event, backend is
3142
+ * waiting on.
3143
+ */
3144
+ const char *
3145
+ pgstat_get_wait_event (uint32 wait_event_info )
3146
+ {
3147
+ uint8 classId ;
3148
+ uint16 eventId ;
3149
+ const char * event_name ;
3150
+
3151
+ /* report process as not waiting. */
3152
+ if (wait_event_info == 0 )
3153
+ return NULL ;
3154
+
3155
+ eventId = wait_event_info & ((1 << 24 ) - 1 );
3156
+ wait_event_info = wait_event_info >> 24 ;
3157
+ classId = wait_event_info & 0XFF ;
3158
+
3159
+ switch (classId )
3160
+ {
3161
+ case WAIT_LWLOCK_NAMED :
3162
+ case WAIT_LWLOCK_TRANCHE :
3163
+ event_name = GetLWLockIdentifier (classId , eventId );
3164
+ break ;
3165
+ case WAIT_LOCK :
3166
+ event_name = GetLockNameFromTagType (eventId );
3167
+ break ;
3168
+ case WAIT_BUFFER_PIN :
3169
+ event_name = "BufferPin" ;
3170
+ break ;
3171
+ default :
3172
+ event_name = "unknown wait event" ;
3173
+ break ;
3174
+ }
3175
+
3176
+ return event_name ;
3177
+ }
3122
3178
3123
3179
/* ----------
3124
3180
* pgstat_get_backend_current_activity() -
0 commit comments