mirror of
https://github.com/postgres/postgres.git
synced 2026-02-14 08:13:27 -05:00
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
47 lines
1.1 KiB
C
47 lines
1.1 KiB
C
/*-------------------------------------------------------------------------
|
|
*
|
|
* ps_status.h
|
|
*
|
|
* Declarations for backend/utils/misc/ps_status.c
|
|
*
|
|
* src/include/utils/ps_status.h
|
|
*
|
|
*-------------------------------------------------------------------------
|
|
*/
|
|
|
|
#ifndef PS_STATUS_H
|
|
#define PS_STATUS_H
|
|
|
|
/* disabled on Windows as the performance overhead can be significant */
|
|
#ifdef WIN32
|
|
#define DEFAULT_UPDATE_PROCESS_TITLE false
|
|
#else
|
|
#define DEFAULT_UPDATE_PROCESS_TITLE true
|
|
#endif
|
|
|
|
extern PGDLLIMPORT bool update_process_title;
|
|
|
|
extern char **save_ps_display_args(int argc, char **argv);
|
|
|
|
extern void init_ps_display(const char *fixed_part);
|
|
|
|
extern void set_ps_display_suffix(const char *suffix);
|
|
|
|
extern void set_ps_display_remove_suffix(void);
|
|
|
|
extern void set_ps_display_with_len(const char *activity, size_t len);
|
|
|
|
/*
|
|
* set_ps_display
|
|
* inlined to allow strlen to be evaluated during compilation when
|
|
* passing string constants.
|
|
*/
|
|
static inline void
|
|
set_ps_display(const char *activity)
|
|
{
|
|
set_ps_display_with_len(activity, strlen(activity));
|
|
}
|
|
|
|
extern const char *get_ps_display(int *displen);
|
|
|
|
#endif /* PS_STATUS_H */
|