From 043c8b5db6976d4e0e6770c3b5677bc6fbd057d0 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 10 Jul 2023 11:10:39 -0300 Subject: [PATCH 1/3] fix debugger performance --- .../debugger/BrowserDebugProxy/DebugStore.cs | 73 +++++++++---------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index a79dc376d7506c..2afef613538a46 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1475,62 +1475,55 @@ public IEnumerable Add(SessionId id, string name, byte[] assembly_da } } - public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, ExecutionContext context, bool useDebuggerProtocol, [EnumeratorCancellation] CancellationToken token) + public async IAsyncEnumerable Load(SessionId id, string[] loaded_files, ExecutionContext context, bool tryUseDebuggerProtocol, [EnumeratorCancellation] CancellationToken token) { var asm_files = new List(); List steps = new List(); - if (!useDebuggerProtocol) + var pdb_files = new List(); + foreach (string file_name in loaded_files) { - var pdb_files = new List(); - foreach (string file_name in loaded_files) - { - if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) - pdb_files.Add(file_name); - else - asm_files.Add(file_name); - } + if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) + pdb_files.Add(file_name); + else + asm_files.Add(file_name); + } - foreach (string url in asm_files) + foreach (string url in asm_files) + { + try { - try - { - string candidate_pdb = Path.ChangeExtension(url, "pdb"); - string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); + string candidate_pdb = Path.ChangeExtension(url, "pdb"); + string pdb = pdb_files.FirstOrDefault(n => n == candidate_pdb); - steps.Add( - new DebugItem - { - Url = url, - Data = Task.WhenAll(MonoProxy.HttpClient.GetByteArrayAsync(url, token), pdb != null ? MonoProxy.HttpClient.GetByteArrayAsync(pdb, token) : Task.FromResult(null)) - }); - } - catch (Exception e) - { - logger.LogDebug($"Failed to read {url} ({e.Message})"); - } + steps.Add( + new DebugItem + { + Url = url, + Data = Task.WhenAll(MonoProxy.HttpClient.GetByteArrayAsync(url, token), pdb != null ? MonoProxy.HttpClient.GetByteArrayAsync(pdb, token) : Task.FromResult(null)) + }); } - } - else - { - foreach (string file_name in loaded_files) + catch (Exception e) { - if (file_name.EndsWith(".pdb", StringComparison.OrdinalIgnoreCase)) - continue; - try + if (tryUseDebuggerProtocol) { - string unescapedFileName = Uri.UnescapeDataString(file_name); - steps.Add( + try + { + string unescapedFileName = Uri.UnescapeDataString(url); + steps.Add( new DebugItem { - Url = file_name, + Url = url, Data = context.SdbAgent.GetBytesFromAssemblyAndPdb(Path.GetFileName(unescapedFileName), token) }); + } + catch (Exception ex) + { + logger.LogDebug($"Failed to read {url} ({ex.Message})"); + } } - catch (Exception e) - { - logger.LogDebug($"Failed to read {file_name} ({e.Message})"); - } + else + logger.LogDebug($"Failed to read {url} ({e.Message})"); } } From f87c76b1d2cb6eb5480edcaed35454f6caae9a3b Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 10 Jul 2023 14:10:42 -0300 Subject: [PATCH 2/3] Update src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs Co-authored-by: Ankit Jain --- src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 2afef613538a46..3b14ec7bb6e422 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1523,7 +1523,9 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil } } else + { logger.LogDebug($"Failed to read {url} ({e.Message})"); + } } } From 6a14109e48f00c1c54aa331ae93f0bc418414710 Mon Sep 17 00:00:00 2001 From: Thays Grazia Date: Mon, 10 Jul 2023 14:15:31 -0300 Subject: [PATCH 3/3] addressing @radical comments --- src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs index 3b14ec7bb6e422..5a2b3d2577f469 100644 --- a/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs +++ b/src/mono/wasm/debugger/BrowserDebugProxy/DebugStore.cs @@ -1519,7 +1519,7 @@ public async IAsyncEnumerable Load(SessionId id, string[] loaded_fil } catch (Exception ex) { - logger.LogDebug($"Failed to read {url} ({ex.Message})"); + logger.LogDebug($"Failed to get bytes using debugger protocol {url} ({ex.Message})"); } } else