@@ -235,51 +235,6 @@ fill_dimensions(SamplingDimensions *dimensions, PGPROC *proc,
235235}
236236}
237237
238- static void
239- copy_dimensions (SamplingDimensions * dst ,SamplingDimensions * src ,
240- int dst_dimensions_mask )
241- {
242- if (dst_dimensions_mask & PGWS_DIMENSIONS_PID )
243- dst -> pid = src -> pid ;
244-
245- if (dst_dimensions_mask & PGWS_DIMENSIONS_WAIT_EVENT_TYPE ||
246- dst_dimensions_mask & PGWS_DIMENSIONS_WAIT_EVENT )
247- dst -> wait_event_info = src -> wait_event_info ;
248-
249- if (dst_dimensions_mask & PGWD_DIMENSIONS_QUERY_ID )
250- dst -> queryId = src -> queryId ;
251-
252- if (dst_dimensions_mask & PGWS_DIMENSIONS_ROLE_ID )
253- dst -> role_id = src -> role_id ;
254-
255- if (dst_dimensions_mask & PGWS_DIMENSIONS_DB_ID )
256- dst -> database_id = src -> database_id ;
257-
258- if (dst_dimensions_mask & PGWS_DIMENSIONS_PARALLEL_LEADER_PID )
259- dst -> parallel_leader_pid = src -> parallel_leader_pid ;
260-
261- if (dst_dimensions_mask & PGWS_DIMENSIONS_IS_REGULAR_BE )
262- dst -> is_regular_backend = src -> is_regular_backend ;
263-
264- if (dst_dimensions_mask & PGWS_DIMENSIONS_BE_TYPE )
265- dst -> backend_type = src -> backend_type ;
266-
267- if (dst_dimensions_mask & PGWS_DIMENSIONS_BE_STATE )
268- dst -> backend_state = src -> backend_state ;
269-
270- if (dst_dimensions_mask & PGWS_DIMENSIONS_BE_START_TIME )
271- dst -> backend_start = src -> backend_start ;
272-
273- if (dst_dimensions_mask & PGWS_DIMENSIONS_CLIENT_ADDR )
274- dst -> client_addr = src -> client_addr ;
275-
276- if (dst_dimensions_mask & PGWS_DIMENSIONS_CLIENT_HOSTNAME )
277- strcpy (dst -> client_hostname ,src -> client_hostname );
278-
279- if (dst_dimensions_mask & PGWS_DIMENSIONS_APPNAME )
280- strcpy (dst -> appname ,src -> appname );
281- }
282-
283238int
284239get_serialized_size (int dimensions_mask ,bool need_last_field )
285240{
@@ -321,10 +276,10 @@ get_serialized_size(int dimensions_mask, bool need_last_field)
321276
322277static void
323278serialize_item (SamplingDimensions dimensions ,int dimensions_mask ,
324- char * * serialized_item ,char * * serialized_key , int * serialized_size ,
279+ char * * serialized_item ,int * serialized_size ,
325280TimestampTz ts ,uint64 count ,bool is_history )
326281{
327- char dummy_array [sizeof (SamplingDimensions )+ sizeof (uint64 )+ 1 ];
282+ char dummy_array [sizeof (SamplingDimensions )+ sizeof (uint64 )];
328283
329284memset (dummy_array ,0 ,sizeof (dummy_array ));
330285
@@ -420,10 +375,6 @@ serialize_item(SamplingDimensions dimensions, int dimensions_mask,
420375* serialized_size += sizeof (dimensions .appname );
421376}
422377
423- /* copy all the fields without ts/count */
424- * serialized_key = palloc0 (* serialized_size );
425- memcpy (* serialized_key ,dummy_array ,* serialized_size );
426-
427378if (is_history )
428379{
429380memcpy (dummy_array + * serialized_size ,& ts ,
@@ -444,7 +395,7 @@ serialize_item(SamplingDimensions dimensions, int dimensions_mask,
444395
445396void
446397deserialize_item (SamplingDimensions * dimensions ,char * serialized_item ,
447- int dimensions_mask ,TimestampTz * ts ,uint64 * count )
398+ int dimensions_mask ,TimestampTz * ts ,uint64 * count , bool is_history )
448399{
449400int idx = 0 ;
450401
@@ -542,14 +493,13 @@ deserialize_item(SamplingDimensions *dimensions, char *serialized_item,
542493idx += sizeof (dimensions -> appname );
543494}
544495
545- if (ts )
496+ if (is_history )
546497{
547498memcpy (ts ,serialized_item + idx ,
548499sizeof (TimestampTz ));
549500idx += sizeof (TimestampTz );
550501}
551-
552- if (count )
502+ else
553503{
554504memcpy (count ,serialized_item + idx ,
555505sizeof (uint64 ));
@@ -581,9 +531,7 @@ probe_waits(History *observations, HTAB *profile_hash,
581531PGPROC * proc = & ProcGlobal -> allProcs [i ];
582532int pid ;
583533uint32 wait_event_info ;
584- SamplingDimensions common_dimensions ,
585- history_dimensions ,
586- profile_dimensions ;
534+ SamplingDimensions common_dimensions ;
587535int dimensions_mask_common = saved_history_dimensions |
588536saved_profile_dimensions ;
589537
@@ -594,33 +542,25 @@ probe_waits(History *observations, HTAB *profile_hash,
594542/*
595543 * We zero dimensions with memset to avoid doing it field-by-field
596544 */
597- memset (& history_dimensions ,0 ,sizeof (SamplingDimensions ));
598- memset (& profile_dimensions ,0 ,sizeof (SamplingDimensions ));
599545memset (& common_dimensions ,0 ,sizeof (SamplingDimensions ));
600546
601547fill_dimensions (& common_dimensions ,proc ,pid ,wait_event_info ,
602548pgws_proc_queryids [i ],dimensions_mask_common );
603549
604- copy_dimensions (& history_dimensions ,
605- & common_dimensions ,
606- saved_history_dimensions );
607- copy_dimensions (& profile_dimensions ,
608- & common_dimensions ,
609- saved_profile_dimensions );
610-
611550/* Write to the history if needed */
612551if (write_history )
613552{
614- char * serialized_key ,
615- * serialized_item ,
553+ char * serialized_item ,
616554* observation ;
617555int serialized_size = 0 ;
618556
619557observation = get_next_observation (observations );
620- serialize_item (history_dimensions ,saved_history_dimensions ,
621- & serialized_item ,& serialized_key , & serialized_size ,
558+ serialize_item (common_dimensions ,saved_history_dimensions ,
559+ & serialized_item ,& serialized_size ,
622560ts , (uint64 )0 , true);
623561memcpy (observation ,serialized_item ,serialized_size );
562+
563+ pfree (serialized_item );
624564}
625565
626566/* Write to the profile if needed */
@@ -629,30 +569,29 @@ probe_waits(History *observations, HTAB *profile_hash,
629569bool found ;
630570int serialized_size = 0 ;
631571uint64 count = 1 ;
632- char * serialized_key ,
633- * serialized_item ,
572+ char * serialized_item ,
634573* stored_item ;
635574
636575if (!profile_pid )
637- profile_dimensions .pid = 0 ;
576+ common_dimensions .pid = 0 ;
638577
639- serialize_item (profile_dimensions ,saved_profile_dimensions ,
640- & serialized_item ,& serialized_key , & serialized_size ,
578+ serialize_item (common_dimensions ,saved_profile_dimensions ,
579+ & serialized_item ,& serialized_size ,
641580 (TimestampTz )0 ,count , false);
642581
643- stored_item = (char * )hash_search (profile_hash ,serialized_key ,
582+ stored_item = (char * )hash_search (profile_hash ,serialized_item ,
644583HASH_ENTER ,& found );
645584
646585if (found )
647586{
648587memcpy (& count , (stored_item + serialized_size - sizeof (uint64 )),
649588sizeof (uint64 ));
650589count ++ ;
651- memcpy ((stored_item + serialized_size - sizeof (uint64 )),& count ,
652- sizeof (uint64 ));
653590}
654- else
655- memcpy (stored_item ,serialized_item ,serialized_size );
591+ /* Copy new or incremented count to hash table */
592+ memcpy ((stored_item + serialized_size - sizeof (uint64 )),& count ,sizeof (uint64 ));
593+
594+ pfree (serialized_item );
656595}
657596}
658597LWLockRelease (ProcArrayLock );