diff --git a/src/gausskernel/process/postmaster/pagewriter.cpp b/src/gausskernel/process/postmaster/pagewriter.cpp index 234dd42a4..b70241fc9 100644 --- a/src/gausskernel/process/postmaster/pagewriter.cpp +++ b/src/gausskernel/process/postmaster/pagewriter.cpp @@ -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), diff --git a/src/gausskernel/process/tcop/postgres.cpp b/src/gausskernel/process/tcop/postgres.cpp index f5416e19b..bd2985585 100755 --- a/src/gausskernel/process/tcop/postgres.cpp +++ b/src/gausskernel/process/tcop/postgres.cpp @@ -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) { diff --git a/src/gausskernel/process/threadpool/knl_thread.cpp b/src/gausskernel/process/threadpool/knl_thread.cpp index b9f92c310..217482a40 100755 --- a/src/gausskernel/process/threadpool/knl_thread.cpp +++ b/src/gausskernel/process/threadpool/knl_thread.cpp @@ -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() diff --git a/src/gausskernel/storage/access/transam/xlog.cpp b/src/gausskernel/storage/access/transam/xlog.cpp index 502b9fabe..add8661d6 100755 --- a/src/gausskernel/storage/access/transam/xlog.cpp +++ b/src/gausskernel/storage/access/transam/xlog.cpp @@ -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) { diff --git a/src/include/knl/knl_thread.h b/src/include/knl/knl_thread.h index 8851b11c8..236c4d649 100644 --- a/src/include/knl/knl_thread.h +++ b/src/include/knl/knl_thread.h @@ -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_ */