From 5facc0c07f8a3f6fd0f39229044fe120501162a7 Mon Sep 17 00:00:00 2001 From: Ac_K Date: Mon, 13 Jan 2020 01:21:54 +0100 Subject: [PATCH] Name all threads (#886) * Name all threads Close #874 * use ThreadName instead of ThreadId in Logging --- ARMeilleure/Translation/Translator.cs | 7 +++-- .../Renderers/OpenAL/OpenALAudioOut.cs | 5 +++- .../Logging/Formatters/DefaultLogFormatter.cs | 9 ++++-- Ryujinx.Common/Logging/LogEventArgs.cs | 28 +++++++++---------- Ryujinx.Common/Logging/Logger.cs | 4 +-- .../Logging/Targets/AsyncLogTargetWrapper.cs | 1 + Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs | 5 +++- .../HOS/Kernel/Threading/HleScheduler.cs | 5 +++- Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs | 4 +-- Ryujinx.Profiler/InternalProfile.cs | 5 +++- Ryujinx.Profiler/UI/ProfileWindowManager.cs | 10 +++++-- Ryujinx/Ui/GLScreen.cs | 5 +++- Ryujinx/Ui/MainWindow.cs | 1 + 13 files changed, 60 insertions(+), 29 deletions(-) diff --git a/ARMeilleure/Translation/Translator.cs b/ARMeilleure/Translation/Translator.cs index 6531e9f0f7..4725ca59d8 100644 --- a/ARMeilleure/Translation/Translator.cs +++ b/ARMeilleure/Translation/Translator.cs @@ -58,9 +58,12 @@ namespace ARMeilleure.Translation { if (Interlocked.Increment(ref _threadCount) == 1) { - Thread backgroundTranslatorThread = new Thread(TranslateQueuedSubs); + Thread backgroundTranslatorThread = new Thread(TranslateQueuedSubs) + { + Name = "CPU.BackgroundTranslatorThread", + Priority = ThreadPriority.Lowest + }; - backgroundTranslatorThread.Priority = ThreadPriority.Lowest; backgroundTranslatorThread.Start(); } diff --git a/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioOut.cs b/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioOut.cs index 69f36a4daf..30b325a51a 100644 --- a/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioOut.cs +++ b/Ryujinx.Audio/Renderers/OpenAL/OpenALAudioOut.cs @@ -70,7 +70,10 @@ namespace Ryujinx.Audio _context = new AudioContext(); _tracks = new ConcurrentDictionary(); _keepPolling = true; - _audioPollerThread = new Thread(AudioPollerWork); + _audioPollerThread = new Thread(AudioPollerWork) + { + Name = "Audio.PollerThread" + }; _audioPollerThread.Start(); } diff --git a/Ryujinx.Common/Logging/Formatters/DefaultLogFormatter.cs b/Ryujinx.Common/Logging/Formatters/DefaultLogFormatter.cs index c6605e0e0e..73b0e2b6ac 100644 --- a/Ryujinx.Common/Logging/Formatters/DefaultLogFormatter.cs +++ b/Ryujinx.Common/Logging/Formatters/DefaultLogFormatter.cs @@ -18,8 +18,13 @@ namespace Ryujinx.Common.Logging sb.AppendFormat(@"{0:hh\:mm\:ss\.fff}", args.Time); sb.Append(" | "); - sb.AppendFormat("{0:d4}", args.ThreadId); - sb.Append(' '); + + if (args.ThreadName != null) + { + sb.Append(args.ThreadName); + sb.Append(' '); + } + sb.Append(args.Message); if (args.Data != null) diff --git a/Ryujinx.Common/Logging/LogEventArgs.cs b/Ryujinx.Common/Logging/LogEventArgs.cs index 2330dedd36..af33463240 100644 --- a/Ryujinx.Common/Logging/LogEventArgs.cs +++ b/Ryujinx.Common/Logging/LogEventArgs.cs @@ -4,28 +4,28 @@ namespace Ryujinx.Common.Logging { public class LogEventArgs : EventArgs { - public LogLevel Level { get; private set; } - public TimeSpan Time { get; private set; } - public int ThreadId { get; private set; } + public LogLevel Level { get; private set; } + public TimeSpan Time { get; private set; } + public string ThreadName { get; private set; } public string Message { get; private set; } public object Data { get; private set; } - public LogEventArgs(LogLevel level, TimeSpan time, int threadId, string message) + public LogEventArgs(LogLevel level, TimeSpan time, string threadName, string message) { - Level = level; - Time = time; - ThreadId = threadId; - Message = message; + Level = level; + Time = time; + ThreadName = threadName; + Message = message; } - public LogEventArgs(LogLevel level, TimeSpan time, int threadId, string message, object data) + public LogEventArgs(LogLevel level, TimeSpan time, string threadName, string message, object data) { - Level = level; - Time = time; - ThreadId = threadId; - Message = message; - Data = data; + Level = level; + Time = time; + ThreadName = threadName; + Message = message; + Data = data; } } } \ No newline at end of file diff --git a/Ryujinx.Common/Logging/Logger.cs b/Ryujinx.Common/Logging/Logger.cs index 83af97b122..e3d82201d4 100644 --- a/Ryujinx.Common/Logging/Logger.cs +++ b/Ryujinx.Common/Logging/Logger.cs @@ -155,7 +155,7 @@ namespace Ryujinx.Common.Logging { if (m_EnabledLevels[(int)logLevel] && m_EnabledClasses[(int)logClass]) { - Updated?.Invoke(null, new LogEventArgs(logLevel, m_Time.Elapsed, Thread.CurrentThread.ManagedThreadId, message)); + Updated?.Invoke(null, new LogEventArgs(logLevel, m_Time.Elapsed, Thread.CurrentThread.Name, message)); } } @@ -163,7 +163,7 @@ namespace Ryujinx.Common.Logging { if (m_EnabledLevels[(int)logLevel] && m_EnabledClasses[(int)logClass]) { - Updated?.Invoke(null, new LogEventArgs(logLevel, m_Time.Elapsed, Thread.CurrentThread.ManagedThreadId, message, data)); + Updated?.Invoke(null, new LogEventArgs(logLevel, m_Time.Elapsed, Thread.CurrentThread.Name, message, data)); } } diff --git a/Ryujinx.Common/Logging/Targets/AsyncLogTargetWrapper.cs b/Ryujinx.Common/Logging/Targets/AsyncLogTargetWrapper.cs index c946b67880..43c62d319c 100644 --- a/Ryujinx.Common/Logging/Targets/AsyncLogTargetWrapper.cs +++ b/Ryujinx.Common/Logging/Targets/AsyncLogTargetWrapper.cs @@ -57,6 +57,7 @@ namespace Ryujinx.Common.Logging } }); + _messageThread.Name = "Logger.MessageThread"; _messageThread.IsBackground = true; _messageThread.Start(); } diff --git a/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs b/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs index f6a9e6f9d1..8273520fd1 100644 --- a/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs +++ b/Ryujinx.HLE/HOS/Kernel/Common/KTimeManager.cs @@ -33,7 +33,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Common _keepRunning = true; - Thread work = new Thread(WaitAndCheckScheduledObjects); + Thread work = new Thread(WaitAndCheckScheduledObjects) + { + Name = "HLE.TimeManager" + }; work.Start(); } diff --git a/Ryujinx.HLE/HOS/Kernel/Threading/HleScheduler.cs b/Ryujinx.HLE/HOS/Kernel/Threading/HleScheduler.cs index 0b95113481..1a213b924f 100644 --- a/Ryujinx.HLE/HOS/Kernel/Threading/HleScheduler.cs +++ b/Ryujinx.HLE/HOS/Kernel/Threading/HleScheduler.cs @@ -17,7 +17,10 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading public void StartAutoPreemptionThread() { - Thread preemptionThread = new Thread(PreemptCurrentThread); + Thread preemptionThread = new Thread(PreemptCurrentThread) + { + Name = "HLE.PreemptionThread" + }; _keepPreempting = true; diff --git a/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs b/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs index e1a49a561a..c4bd781d4e 100644 --- a/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs +++ b/Ryujinx.HLE/HOS/Kernel/Threading/KThread.cs @@ -159,7 +159,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading is64Bits = true; } - HostThread = new Thread(customHostThreadStart == null ? () => ThreadStart(entrypoint) : customHostThreadStart); + HostThread = new Thread(customHostThreadStart ?? (() => ThreadStart(entrypoint))); Context = new ARMeilleure.State.ExecutionContext(); @@ -185,7 +185,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading ThreadUid = System.GetThreadUid(); - HostThread.Name = $"Host Thread (thread id {ThreadUid})"; + HostThread.Name = $"HLE.HostThread.{ThreadUid}"; _hasBeenInitialized = true; diff --git a/Ryujinx.Profiler/InternalProfile.cs b/Ryujinx.Profiler/InternalProfile.cs index 46984601b5..0346244423 100644 --- a/Ryujinx.Profiler/InternalProfile.cs +++ b/Ryujinx.Profiler/InternalProfile.cs @@ -55,7 +55,10 @@ namespace Ryujinx.Profiler _cleanupRunning = true; // Create cleanup thread. - _cleanupThread = new Thread(CleanupLoop); + _cleanupThread = new Thread(CleanupLoop) + { + Name = "Profiler.CleanupThread" + }; _cleanupThread.Start(); } diff --git a/Ryujinx.Profiler/UI/ProfileWindowManager.cs b/Ryujinx.Profiler/UI/ProfileWindowManager.cs index c6a65a317c..1360302933 100644 --- a/Ryujinx.Profiler/UI/ProfileWindowManager.cs +++ b/Ryujinx.Profiler/UI/ProfileWindowManager.cs @@ -21,7 +21,10 @@ namespace Ryujinx.Profiler.UI { _profilerRunning = true; _prevTime = 0; - _profileThread = new Thread(ProfileLoop); + _profileThread = new Thread(ProfileLoop) + { + Name = "Profiler.ProfileThread" + }; _profileThread.Start(); } } @@ -60,7 +63,10 @@ namespace Ryujinx.Profiler.UI using (_window = new ProfileWindow()) { // Create thread for render loop - _renderThread = new Thread(RenderLoop); + _renderThread = new Thread(RenderLoop) + { + Name = "Profiler.RenderThread" + }; _renderThread.Start(); while (_profilerRunning) diff --git a/Ryujinx/Ui/GLScreen.cs b/Ryujinx/Ui/GLScreen.cs index 8e39126224..d32ddb5ca5 100644 --- a/Ryujinx/Ui/GLScreen.cs +++ b/Ryujinx/Ui/GLScreen.cs @@ -120,7 +120,10 @@ namespace Ryujinx.Ui Context.MakeCurrent(null); // OpenTK doesn't like sleeps in its thread, to avoid this a renderer thread is created - _renderThread = new Thread(RenderLoop); + _renderThread = new Thread(RenderLoop) + { + Name = "GUI.RenderThread" + }; _renderThread.Start(); diff --git a/Ryujinx/Ui/MainWindow.cs b/Ryujinx/Ui/MainWindow.cs index af7dd524ab..451df2fd95 100644 --- a/Ryujinx/Ui/MainWindow.cs +++ b/Ryujinx/Ui/MainWindow.cs @@ -653,6 +653,7 @@ namespace Ryujinx.Ui } }); + thread.Name = "GUI.FirmwareInstallerThread"; thread.Start(); } else