mirror of
https://github.com/postgres/postgres.git
synced 2025-06-17 17:02:08 +03:00
Speedup and increase usability of set proc title functions
The setting of the process title could be seen on profiles of very fast-to-execute queries. In many locations where we call set_ps_display() we pass along a string constant, the length of which is known during compilation. Here we effectively rename set_ps_display() to set_ps_display_with_len() and then add a static inline function named set_ps_display() which calls strlen() on the given string. This allows the compiler to optimize away the strlen() call when dealing with call sites passing a string constant. We can then also use memcpy() instead of strlcpy() to copy the string into the destination buffer. That's significantly faster than strlcpy's byte-at-a-time way of copying. Here we also take measures to improve some code which was adjusting the process title to add a " waiting" suffix to it. Call sites which require this can now just call set_ps_display_suffix() to add or adjust the suffix and call set_ps_display_remove_suffix() to remove it again. Reviewed-by: Andres Freund Discussion: https://postgr.es/m/CAApHDvocBvvk-0gWNA2Gohe+sv9fMcv+fK_G+siBKJrgDG4O7g@mail.gmail.com
This commit is contained in:
@ -1071,6 +1071,8 @@ exec_simple_query(const char *query_string)
|
||||
Portal portal;
|
||||
DestReceiver *receiver;
|
||||
int16 format;
|
||||
const char *cmdtagname;
|
||||
size_t cmdtaglen;
|
||||
|
||||
pgstat_report_query_id(0, true);
|
||||
|
||||
@ -1081,8 +1083,9 @@ exec_simple_query(const char *query_string)
|
||||
* destination.
|
||||
*/
|
||||
commandTag = CreateCommandTag(parsetree->stmt);
|
||||
cmdtagname = GetCommandTagNameAndLen(commandTag, &cmdtaglen);
|
||||
|
||||
set_ps_display(GetCommandTagName(commandTag));
|
||||
set_ps_display_with_len(cmdtagname, cmdtaglen);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
||||
@ -2064,6 +2067,8 @@ exec_execute_message(const char *portal_name, long max_rows)
|
||||
char msec_str[32];
|
||||
ParamsErrorCbData params_data;
|
||||
ErrorContextCallback params_errcxt;
|
||||
const char *cmdtagname;
|
||||
size_t cmdtaglen;
|
||||
|
||||
/* Adjust destination to tell printtup.c what to do */
|
||||
dest = whereToSendOutput;
|
||||
@ -2110,7 +2115,9 @@ exec_execute_message(const char *portal_name, long max_rows)
|
||||
|
||||
pgstat_report_activity(STATE_RUNNING, sourceText);
|
||||
|
||||
set_ps_display(GetCommandTagName(portal->commandTag));
|
||||
cmdtagname = GetCommandTagNameAndLen(portal->commandTag, &cmdtaglen);
|
||||
|
||||
set_ps_display_with_len(cmdtagname, cmdtaglen);
|
||||
|
||||
if (save_log_statement_stats)
|
||||
ResetUsage();
|
||||
|
Reference in New Issue
Block a user