4848#include "postmaster/autovacuum.h"
4949#include "postmaster/fork_process.h"
5050#include "postmaster/postmaster.h"
51- #include "storage/proc.h"
5251#include "storage/backendid.h"
5352#include "storage/dsm.h"
5453#include "storage/fd.h"
5554#include "storage/ipc.h"
5655#include "storage/latch.h"
56+ #include "storage/lmgr.h"
5757#include "storage/pg_shmem.h"
5858#include "storage/procsignal.h"
5959#include "storage/sinvaladt.h"
@@ -2723,7 +2723,6 @@ pgstat_bestart(void)
27232723#else
27242724 beentry -> st_ssl = false;
27252725#endif
2726- beentry -> st_waiting = false;
27272726 beentry -> st_state = STATE_UNDEFINED ;
27282727 beentry -> st_appname [0 ] = '\0' ;
27292728 beentry -> st_activity [0 ] = '\0' ;
@@ -2810,6 +2809,8 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
28102809 {
28112810 if (beentry -> st_state != STATE_DISABLED )
28122811 {
2812+ volatile PGPROC * proc = MyProc ;
2813+
28132814 /*
28142815 * track_activities is disabled, but we last reported a
28152816 * non-disabled state. As our final update, change the state and
@@ -2820,9 +2821,9 @@ pgstat_report_activity(BackendState state, const char *cmd_str)
28202821 beentry -> st_state_start_timestamp = 0 ;
28212822 beentry -> st_activity [0 ] = '\0' ;
28222823 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 */
28242825 beentry -> st_xact_start_timestamp = 0 ;
2825- beentry -> st_waiting = false ;
2826+ proc -> wait_event_info = 0 ;
28262827 pgstat_increment_changecount_after (beentry );
28272828 }
28282829 return ;
@@ -2978,32 +2979,6 @@ pgstat_report_xact_timestamp(TimestampTz tstamp)
29782979 pgstat_increment_changecount_after (beentry );
29792980}
29802981
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-
30072982/* ----------
30082983 * pgstat_read_current_status() -
30092984 *
@@ -3119,6 +3094,87 @@ pgstat_read_current_status(void)
31193094 localBackendStatusTable = localtable ;
31203095}
31213096
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+ }
31223178
31233179/* ----------
31243180 * pgstat_get_backend_current_activity() -
0 commit comments