[UI Thread] Change comm to "UIThread+" 67/273967/1
authorHwankyu Jhun <h.jhun@samsung.com>
Tue, 19 Apr 2022 06:11:29 +0000 (15:11 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 19 Apr 2022 06:11:29 +0000 (15:11 +0900)
This patch writes "UIThread+" to "/proc/<tid>/comm".
After this patch is applied, we can check the thread ID using ps command.

Change-Id: I7819beb65a0ed40267ad3d6f933ccd6c579dbd4d
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
tizen-cpp/app-core-ui-cpp/app_core_ui_base.cc

index f5b0d9bf6d188682b899db921f7f5fa5991e85f3..ab32f25adecd049f41a366f63ad34be5a2f27578 100644 (file)
@@ -21,6 +21,9 @@
 #include <aul_rpc_port.h>
 #include <aul_svc.h>
 #include <bundle_internal.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
 #include <sys/types.h>
 #include <ttrace.h>
 #include <unistd.h>
@@ -44,6 +47,22 @@ namespace tizen_cpp {
 
 constexpr const char K_SERVICE_THREAD[] = "__K_SERVICE_THREAD";
 
+void SetComm(const std::string& name) {
+  pid_t tid = syscall(__NR_gettid);
+  std::string path = "/proc/" + std::to_string(tid) + "/comm";
+  int fd = open(path.c_str(), O_WRONLY);
+  if (fd < 0) {
+    _E("open(%s) is failed. errno(%d)", path.c_str(), errno);
+    return;
+  }
+
+  ssize_t bytes_written = write(fd, name.c_str(), name.length() + 1);
+  if (bytes_written < 0)
+    _E("write(%d) is failed. errno(%d)", fd, errno);
+
+  close(fd);
+}
+
 class AppCoreUiBase::Impl {
  public:
   Impl(AppCoreUiBase* parent, unsigned int hint)
@@ -425,6 +444,7 @@ void AppCoreUiBase::Impl::Run(int argc, char** argv) {
     setenv("TIZEN_GLIB_CONTEXT", env.c_str(), 1);
 
     thread_ = std::thread([&] {
+          SetComm("UIThread+");
           parent_->DoRun(argc, argv);
         });