forked from huawei/openGauss-server
更合适的动态线程名
This commit is contained in:
parent
8e5bb201bf
commit
cc7f6da94a
|
|
@ -571,6 +571,8 @@ static void ckpt_pagewriter_main_thread_flush_dirty_page()
|
|||
XLogRecPtr CurrBytePos;
|
||||
uint64 dirty_queue_head;
|
||||
|
||||
knl_thread_set_name("PgWriter:flush");
|
||||
|
||||
WritebackContextInit(&wb_context, &t_thrd.pagewriter_cxt.page_writer_after);
|
||||
ResourceOwnerEnlargeBuffers(t_thrd.utils_cxt.CurrentResourceOwner);
|
||||
|
||||
|
|
@ -741,7 +743,7 @@ static void ckpt_pagewriter_main_thread_loop(void)
|
|||
t_thrd.pagewriter_cxt.got_SIGHUP = false;
|
||||
ProcessConfigFile(PGC_SIGHUP);
|
||||
}
|
||||
|
||||
knl_thread_set_name("PageWriterMain");
|
||||
/* main thread should finally exit. */
|
||||
while (t_thrd.pagewriter_cxt.shutdown_requested && g_instance.ckpt_cxt_ctl->page_writer_can_exit) {
|
||||
int i;
|
||||
|
|
@ -810,7 +812,7 @@ static void ckpt_pagewriter_sub_thread_loop()
|
|||
t_thrd.pagewriter_cxt.got_SIGHUP = false;
|
||||
ProcessConfigFile(PGC_SIGHUP);
|
||||
}
|
||||
|
||||
knl_thread_set_name("PageWriterSub");
|
||||
if (t_thrd.pagewriter_cxt.shutdown_requested && g_instance.ckpt_cxt_ctl->page_writer_can_exit) {
|
||||
ereport(LOG,
|
||||
(errmodule(MOD_INCRE_CKPT),
|
||||
|
|
|
|||
|
|
@ -1245,6 +1245,8 @@ void exec_simple_plan(PlannedStmt* plan)
|
|||
*/
|
||||
commandTag = CreateCommandTagForPlan(plan->commandType);
|
||||
|
||||
knl_thread_set_name(commandTag, true);
|
||||
|
||||
set_ps_display(commandTag, false);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
|
@ -2158,6 +2160,8 @@ void exec_simple_query(const char* query_string, MessageType messageType, String
|
|||
*/
|
||||
commandTag = CreateCommandTag(parsetree);
|
||||
|
||||
knl_thread_set_name(commandTag, true);
|
||||
|
||||
set_ps_display(commandTag, false);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
|
@ -2804,6 +2808,8 @@ static void exec_plan_with_params(StringInfo input_message)
|
|||
|
||||
commandTag = "SELECT";
|
||||
|
||||
knl_thread_set_name(commandTag, true);
|
||||
|
||||
set_ps_display(commandTag, false);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
|
@ -4447,6 +4453,8 @@ void exec_execute_message(const char* portal_name, long max_rows)
|
|||
|
||||
pgstat_report_activity(STATE_RUNNING, sourceText);
|
||||
|
||||
knl_thread_set_name(portal->commandTag, true);
|
||||
|
||||
set_ps_display(portal->commandTag, false);
|
||||
|
||||
if (save_log_statement_stats)
|
||||
|
|
@ -6374,6 +6382,8 @@ static void execute_stream_plan(StreamProducer* producer)
|
|||
// we should remove this hard coding and get the tag automatically
|
||||
commandTag = "SELECT";
|
||||
|
||||
knl_thread_set_name(commandTag, true);
|
||||
|
||||
set_ps_display(commandTag, false);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
|
@ -9453,6 +9463,8 @@ void exec_query_for_merge(const char* query_string)
|
|||
*/
|
||||
commandTag = CreateCommandTag(parsetree);
|
||||
|
||||
knl_thread_set_name(commandTag, true);
|
||||
|
||||
set_ps_display(commandTag, false);
|
||||
|
||||
BeginCommand(commandTag, dest);
|
||||
|
|
@ -10279,6 +10291,8 @@ static void exec_batch_bind_execute(StringInfo input_message)
|
|||
t_thrd.postgres_cxt.debug_query_string = psrc->query_string;
|
||||
pgstat_report_activity(STATE_RUNNING, psrc->query_string);
|
||||
|
||||
knl_thread_set_name(psrc->commandTag, true);
|
||||
|
||||
set_ps_display(psrc->commandTag, false);
|
||||
|
||||
if (save_log_statement_stats) {
|
||||
|
|
|
|||
|
|
@ -1540,15 +1540,27 @@ void knl_thread_init(knl_thread_role role)
|
|||
knl_t_msqueue_init(&t_thrd.msqueue_cxt);
|
||||
}
|
||||
|
||||
void knl_thread_set_name(const char* name)
|
||||
void knl_thread_set_name(const char* name, bool isCommandTag)
|
||||
{
|
||||
t_thrd.proc_cxt.MyProgName = (char*)name;
|
||||
/*
|
||||
* The length of thread name is restricted to 16 characters,
|
||||
* including the terminating null byte ('\0').
|
||||
*/
|
||||
Assert(strlen(name) < MAX_THREAD_NAME_LENGTH);
|
||||
pthread_setname_np(pthread_self(), name);
|
||||
char dynamic_tag[MAX_THREAD_NAME_LENGTH];
|
||||
int rc = 0;
|
||||
if(isCommandTag) {
|
||||
dynamic_tag[0] = '>';
|
||||
/*
|
||||
* MAX_THREAD_NAME_LENGTH - 1 means minus the length of '>'
|
||||
* MAX_THREAD_NAME_LENGTH - 2 menas minus the length of '>'+'\0'
|
||||
*/
|
||||
rc = strncpy_s(dynamic_tag + 1, MAX_THREAD_NAME_LENGTH - 1, name, MAX_THREAD_NAME_LENGTH - 2);
|
||||
} else {
|
||||
rc = strncpy_s(dynamic_tag, MAX_THREAD_NAME_LENGTH, name, MAX_THREAD_NAME_LENGTH - 1);
|
||||
}
|
||||
securec_check(rc, "\0", "\0");
|
||||
pthread_setname_np(pthread_self(), dynamic_tag);
|
||||
}
|
||||
|
||||
__attribute__ ((__used__)) knl_thrd_context *get_current_thread()
|
||||
|
|
|
|||
|
|
@ -3970,6 +3970,7 @@ static int XLogFileRead(XLogSegNo segno, int emode, TimeLineID tli, int source,
|
|||
snprintf_s(activitymsg, sizeof(activitymsg), sizeof(activitymsg) - 1, "waiting for %s", xlogfname);
|
||||
securec_check_ss(errorno, "", "");
|
||||
set_ps_display(activitymsg, false);
|
||||
knl_thread_set_name("Xlog from Archive");
|
||||
|
||||
t_thrd.xlog_cxt.restoredFromArchive = RestoreArchivedFile(path, xlogfname, "RECOVERYXLOG", XLogSegSize);
|
||||
if (!t_thrd.xlog_cxt.restoredFromArchive) {
|
||||
|
|
|
|||
|
|
@ -2890,6 +2890,6 @@ typedef struct knl_thrd_context {
|
|||
extern void knl_thread_mot_init();
|
||||
extern void knl_thread_init(knl_thread_role role);
|
||||
extern THR_LOCAL knl_thrd_context t_thrd;
|
||||
extern void knl_thread_set_name(const char* name);
|
||||
extern void knl_thread_set_name(const char* name, bool isCommandTag = false);
|
||||
|
||||
#endif /* SRC_INCLUDE_KNL_KNL_THRD_H_ */
|
||||
|
|
|
|||
Loading…
Reference in New Issue