diff options
author | David Karlaš <david.karlas@xamarin.com> | 2016-07-15 18:01:06 +0300 |
---|---|---|
committer | David Karlaš <david.karlas@xamarin.com> | 2016-07-25 09:24:56 +0300 |
commit | 7aa969f7d1bc491bf9c5761949f77fd31c45703a (patch) | |
tree | 8eebfd1b07b2569938805e5e7e41d10eb610bf54 /main/src/addins | |
parent | 6fe30da58baccf13174c54dfb55cffea1a48f124 (diff) |
Added profile for 5 seconds command
Diffstat (limited to 'main/src/addins')
4 files changed, 60 insertions, 27 deletions
diff --git a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Commands.cs b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Commands.cs index 966de18b6e..f5d059aa3f 100644 --- a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Commands.cs +++ b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Commands.cs @@ -1,5 +1,6 @@ using System; using MonoDevelop.Components.Commands; +using MonoDevelop.Core; namespace PerformanceDiagnosticsAddIn { @@ -15,9 +16,17 @@ namespace PerformanceDiagnosticsAddIn protected override void Update (CommandInfo info) { - info.Text = UIThreadMonitor.Instance.IsListening ? "Stop monitoring UIThread hangs" : "Start monitoring UIThread hangs"; + info.Text = UIThreadMonitor.Instance.IsListening ? GettextCatalog.GetString ("Stop monitoring UIThread hangs") : GettextCatalog.GetString ("Start monitoring UIThread hangs"); base.Update (info); } } + + public class ProfileFor5SecondsHandler : CommandHandler + { + protected override void Run () + { + UIThreadMonitor.Instance.Profile (5); + } + } } diff --git a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/PerformanceDiagnosticsAddIn.csproj b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/PerformanceDiagnosticsAddIn.csproj index a009d994ff..f8871b86b4 100644 --- a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/PerformanceDiagnosticsAddIn.csproj +++ b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/PerformanceDiagnosticsAddIn.csproj @@ -66,7 +66,6 @@ <ProjectReference Include="..\UIThreadMonitorDaemon\UIThreadMonitorDaemon.csproj"> <Project>{3FDB97B5-916E-4817-8098-41659687A8FF}</Project> <Name>UIThreadMonitorDaemon</Name> - <Private>False</Private> </ProjectReference> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> diff --git a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Properties/PerformanceDiagnostics.addin.xml b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Properties/PerformanceDiagnostics.addin.xml index 95f97f32e4..d381127262 100644 --- a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Properties/PerformanceDiagnostics.addin.xml +++ b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/Properties/PerformanceDiagnostics.addin.xml @@ -4,9 +4,13 @@ <Command id="PerformanceDiagnosticsAddIn.StartStopListeningUIThreadMonitorHandler" defaultHandler="PerformanceDiagnosticsAddIn.StartStopListeningUIThreadMonitorHandler" _label="Start monitoring UIThread hangs" /> + <Command id="PerformanceDiagnosticsAddIn.ProfileFor5SecondsHandler" + defaultHandler="PerformanceDiagnosticsAddIn.ProfileFor5SecondsHandler" + _label="Profile for 5 seconds" /> </Extension> <Extension path="/MonoDevelop/Ide/MainMenu/Help/Diagnostics"> <CommandItem id="PerformanceDiagnosticsAddIn.StartStopListeningUIThreadMonitorHandler" /> + <CommandItem id="PerformanceDiagnosticsAddIn.ProfileFor5SecondsHandler" /> </Extension> <Extension path="/MonoDevelop/Ide/GlobalOptionsDialog"> <Section id="PerformanceDiagnostics" diff --git a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/UIThreadMonitor.cs b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/UIThreadMonitor.cs index 995c3af4f5..b245cf9428 100644 --- a/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/UIThreadMonitor.cs +++ b/main/src/addins/PerformanceDiagnostics/PerformanceDiagnostics/UIThreadMonitor.cs @@ -11,10 +11,11 @@ using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Globalization; using System.Collections.Generic; +using System.Threading.Tasks; namespace PerformanceDiagnosticsAddIn { - public class UIThreadMonitor + class UIThreadMonitor { public static UIThreadMonitor Instance { get; } = new UIThreadMonitor (); @@ -46,6 +47,21 @@ namespace PerformanceDiagnosticsAddIn } } + TimeSpan forceProfileTime = TimeSpan.Zero; + + public void Profile (int seconds) + { + var outputFilePath = Path.GetTempFileName (); + var startInfo = new ProcessStartInfo ("sample"); + startInfo.UseShellExecute = false; + startInfo.Arguments = $"{Process.GetCurrentProcess ().Id} {seconds} -file {outputFilePath}"; + var sampleProcess = Process.Start (startInfo); + sampleProcess.EnableRaisingEvents = true; + sampleProcess.Exited += delegate { + ConvertJITAddressesToMethodNames (outputFilePath, "Profile"); + }; + } + public bool IsListening { get; private set; } public void Start () @@ -101,32 +117,9 @@ namespace PerformanceDiagnosticsAddIn void DumpsReader () { - var rx = new Regex (@"\?\?\? \(in <unknown binary>\) \[0x([0-9a-f]+)\]", RegexOptions.Compiled); while (!(process?.HasExited ?? true)) { var fileName = process.StandardOutput.ReadLine (); - if (File.Exists (fileName) && new FileInfo (fileName).Length > 0) { - var outputFilename = Path.Combine (Options.OutputPath, BrandingService.ApplicationName + "_UIThreadHang_" + DateTime.Now.ToString ("yyyy-MM-dd__HH-mm-ss") + ".txt"); - using (var sr = new StreamReader (fileName)) - using (var sw = new StreamWriter (outputFilename)) { - string line; - while ((line = sr.ReadLine ()) != null) { - if (rx.IsMatch (line)) { - var match = rx.Match (line); - var offset = long.Parse (match.Groups [1].Value, NumberStyles.HexNumber); - string pmipMethodName; - if (!methodsCache.TryGetValue (offset, out pmipMethodName)) { - pmipMethodName = mono_pmip (offset)?.TrimStart (); - methodsCache.Add (offset, pmipMethodName); - } - if (pmipMethodName != null) { - line = line.Remove (match.Index, match.Length); - line = line.Insert (match.Index, pmipMethodName); - } - } - sw.WriteLine (line); - } - } - } + ConvertJITAddressesToMethodNames (fileName, "UIThreadHang"); } } @@ -140,6 +133,34 @@ namespace PerformanceDiagnosticsAddIn process.Kill (); process = null; } + + void ConvertJITAddressesToMethodNames (string fileName, string profilingType) + { + var rx = new Regex (@"\?\?\? \(in <unknown binary>\) \[0x([0-9a-f]+)\]", RegexOptions.Compiled); + if (File.Exists (fileName) && new FileInfo (fileName).Length > 0) { + var outputFilename = Path.Combine (Options.OutputPath, $"{BrandingService.ApplicationName}_{profilingType}_{DateTime.Now:yyyy-MM-dd__HH-mm-ss}.txt"); + using (var sr = new StreamReader (fileName)) + using (var sw = new StreamWriter (outputFilename)) { + string line; + while ((line = sr.ReadLine ()) != null) { + if (rx.IsMatch (line)) { + var match = rx.Match (line); + var offset = long.Parse (match.Groups [1].Value, NumberStyles.HexNumber); + string pmipMethodName; + if (!methodsCache.TryGetValue (offset, out pmipMethodName)) { + pmipMethodName = mono_pmip (offset)?.TrimStart (); + methodsCache.Add (offset, pmipMethodName); + } + if (pmipMethodName != null) { + line = line.Remove (match.Index, match.Length); + line = line.Insert (match.Index, pmipMethodName); + } + } + sw.WriteLine (line); + } + } + } + } } } |