Skip to content

Instantly share code, notes, and snippets.

@jamesob
Created May 7, 2018 17:03
Show Gist options
  • Save jamesob/5604eb4586f8eb3401659566e17632f8 to your computer and use it in GitHub Desktop.
Save jamesob/5604eb4586f8eb3401659566e17632f8 to your computer and use it in GitHub Desktop.
diff -uw <(git diff master..threadnames2.4) <(git diff master..threadnames2.5)
--- /proc/self/fd/15 2018-05-07 13:03:23.738720427 -0400
+++ /proc/self/fd/16 2018-05-07 13:03:23.738720427 -0400
@@ -172,7 +172,7 @@
strStamped.pop_back();
strStamped += strprintf(".%06dZ", nTimeMicros%1000000);
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
-index 57fe455..b2a1249 100644
+index 57fe455..af2baa0 100644
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -29,6 +29,7 @@
@@ -183,7 +183,15 @@
#include <rpc/server.h>
#include <ui_interface.h>
#include <uint256.h>
-@@ -535,6 +536,7 @@ WId BitcoinApplication::getMainWinId() const
+@@ -277,6 +278,7 @@ void BitcoinCore::initialize()
+ try
+ {
+ qDebug() << __func__ << ": Running initialization in thread";
++ thread_util::Rename("bitcoin-qt");
+ bool rv = m_node.appInitMain();
+ Q_EMIT initializeResult(rv);
+ } catch (const std::exception& e) {
+@@ -535,6 +537,7 @@ WId BitcoinApplication::getMainWinId() const
int main(int argc, char *argv[])
{
SetupEnvironment();
@@ -263,10 +271,10 @@
peerLogic.reset(new PeerLogicValidation(connman, scheduler));
diff --git a/src/test/threadutil_tests.cpp b/src/test/threadutil_tests.cpp
new file mode 100644
-index 0000000..bbeb47d
+index 0000000..a18402e
--- /dev/null
+++ b/src/test/threadutil_tests.cpp
-@@ -0,0 +1,92 @@
+@@ -0,0 +1,89 @@
+// Copyright (c) 2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -290,21 +298,18 @@
+BOOST_AUTO_TEST_CASE(threadutil_test_process_rename_serial)
+{
+ std::string original_process_name = thread_util::GetProcessName();
++#ifndef CAN_READ_PROCESS_NAME
++ BOOST_CHECK_EQUAL(thread_util::GetProcessName(), "");
++#endif
+
+ thread_util::SetProcessName("bazzz");
+#ifdef CAN_READ_PROCESS_NAME
+ BOOST_CHECK_EQUAL(thread_util::GetProcessName(), "bazzz");
-+#else
-+ // Special case for platforms which don't support reading of process name.
-+ BOOST_CHECK_EQUAL(thread_util::GetProcessName(), "");
+#endif
+
+ thread_util::SetProcessName("barrr");
+#ifdef CAN_READ_PROCESS_NAME
+ BOOST_CHECK_EQUAL(thread_util::GetProcessName(), "barrr");
-+#else
-+ // Special case for platforms which don't support reading of process name.
-+ BOOST_CHECK_EQUAL(thread_util::GetProcessName(), "");
+#endif
+
+ thread_util::SetProcessName(original_process_name.c_str());
@@ -361,10 +366,10 @@
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/threadutil.cpp b/src/threadutil.cpp
new file mode 100644
-index 0000000..721d177
+index 0000000..6ad720c
--- /dev/null
+++ b/src/threadutil.cpp
-@@ -0,0 +1,213 @@
+@@ -0,0 +1,212 @@
+// Copyright (c) 2018 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
@@ -439,14 +444,13 @@
+#endif
+
+ char threadname_buff[16];
-+ char* pthreadname_buff = (char*)(&threadname_buff);
+
+#if defined(PR_GET_NAME)
-+ ::prctl(PR_GET_NAME, pthreadname_buff);
++ ::prctl(PR_GET_NAME, threadname_buff);
+#elif defined(MAC_OSX)
-+ pthread_getname_np(pthread_self(), pthreadname_buff, sizeof(threadname_buff));
++ pthread_getname_np(pthread_self(), threadname_buff, sizeof(threadname_buff));
+#endif
-+ return std::string(pthreadname_buff);
++ return std::string(threadname_buff);
+}
+
+void thread_util::Rename(std::string name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment