Skip to content

Commit

Permalink
Added method monitoring for finding slow methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Janner Acero committed Sep 20, 2018
1 parent 06f0ec2 commit 41921dd
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Sprung/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using MethodTimer;

namespace Sprung
{
Expand Down Expand Up @@ -41,6 +42,7 @@ public static Settings GetInstance()
}

// TODO constants
[Time]
public void LoadFromFile()
{
try
Expand Down
5 changes: 4 additions & 1 deletion Sprung/Sprung.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading;
using Nancy.Hosting.Self;
using System.Collections.Concurrent;
using MethodTimer;

namespace Sprung
{
Expand Down Expand Up @@ -65,6 +66,7 @@ public Sprung()
// StartTabService();
}

[Time]
private void StartTabService()
{
Debug.WriteLine("StartTabService");
Expand Down Expand Up @@ -141,6 +143,7 @@ private void InputChangedCallback(object sender, EventArgs e)
ShowProcesses(windowMatcher.match(pattern, cachedWindows));
}

[Time]
private void ShowProcesses(List<Window> windows)
{
windowListBox.BeginUpdate();
Expand Down Expand Up @@ -304,6 +307,7 @@ private void ShowBox()
this.Opacity = 100;
}

[Time]
public void CloseSelectedWindow()
{
Window selectedWindow = GetSelectedWindow();
Expand Down Expand Up @@ -384,7 +388,6 @@ private void DeactivateCallback(object sender, EventArgs e)
return;
}

Debug.WriteLine("lost focus");
this.HideBox();
}

Expand Down
14 changes: 14 additions & 0 deletions Sprung/Sprung.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
<ApplicationVersion>2.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -71,6 +73,9 @@
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="MethodTimer, Version=2.2.0.0, Culture=neutral, PublicKeyToken=cb1364609f40a1dc, processorArchitecture=MSIL">
<HintPath>..\packages\MethodTimer.Fody.2.2.0\lib\net452\MethodTimer.dll</HintPath>
</Reference>
<Reference Include="Nancy, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.1.4.4\lib\net40\Nancy.dll</HintPath>
</Reference>
Expand All @@ -93,6 +98,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MethodTimerLogger.cs" />
<Compile Include="Properties\Resources1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down Expand Up @@ -156,6 +162,7 @@
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="FodyWeavers.xml" />
<Content Include="Properties\spring.png" />
<Content Include="settings.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -171,6 +178,13 @@
<Folder Include="Resources\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.3.1.3\build\Fody.targets" Condition="Exists('..\packages\Fody.3.1.3\build\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.3.1.3\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.3.1.3\build\Fody.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
6 changes: 6 additions & 0 deletions Sprung/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Windows.Forms;
using System.Drawing;
using Newtonsoft.Json;
using MethodTimer;

namespace Sprung
{
Expand Down Expand Up @@ -40,6 +41,7 @@ public Window()
{
}

[Time]
public Window(IntPtr handle)
{
if (handle.Equals(IntPtr.Zero))
Expand Down Expand Up @@ -68,6 +70,7 @@ public Window(IntPtr handle)
}
}

[Time]
public virtual void SendToFront()
{
uint foreThread = GetWindowThreadProcessId(GetForegroundWindow(), IntPtr.Zero);
Expand All @@ -90,6 +93,7 @@ public void Close()
SendMessage(Handle, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}

[Time]
public Int32 GetWindowProcessId(Int32 handle)
{
Int32 pointer = 1;
Expand All @@ -108,6 +112,7 @@ public int CompareTo(Window other)
: (MatchingGroups > other.MatchingGroups) ? 1 : 0;
}

[Time]
public Image GetIconImage()
{
Icon icon = GetIcon();
Expand All @@ -120,6 +125,7 @@ public Image GetIconImage()
return (iconImage = (Image)new Bitmap(icon.ToBitmap(), new Size(IconSize, IconSize)));
}

[Time]
public Icon GetIcon()
{
if (icon != null)
Expand Down
5 changes: 5 additions & 0 deletions Sprung/WindowManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sprung.Tabs;
using System.Collections;
using System.Diagnostics;
using MethodTimer;

namespace Sprung
{
Expand All @@ -27,6 +28,7 @@ public static WindowManager GetInstance()

public object TabsLock { get; set; } = new object();

[Time]
public List<Window> GetWindowsWithTabs()
{
lock (TabsLock)
Expand All @@ -50,6 +52,7 @@ public List<Window> GetWindowsWithTabs()
}
}

[Time]
public List<Window> GetWindows()
{
windows.Clear();
Expand All @@ -65,6 +68,7 @@ public List<Window> GetWindows()
return windows;
}

[Time]
private List<Window> FilterWindows10ApplicationFrameHostWindows(List<Window> windows)
{
List<Window> filteredList = new List<Window>();
Expand Down Expand Up @@ -95,6 +99,7 @@ private List<Window> FilterWindows10ApplicationFrameHostWindows(List<Window> win
return filteredList;
}

[Time]
private bool EnumWindowsProc(IntPtr hWnd, int lParam)
{
if (IsWindowVisible(hWnd)) {
Expand Down
3 changes: 3 additions & 0 deletions Sprung/WindowMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MethodTimer;

namespace Sprung
{
Expand All @@ -14,6 +15,7 @@ public WindowMatcher(WindowManager windowManager)
this.windowManager = windowManager;
}

[Time]
public List<Window> match(String pattern)
{
// TODO getWIndows oder getWindow with Tabs?
Expand All @@ -22,6 +24,7 @@ public List<Window> match(String pattern)
return match(pattern, windowManager.GetWindows());
}

[Time]
public List<Window> match(String pattern, List<Window> windows)
{
if (pattern.Length == 0) return windows;
Expand Down
2 changes: 2 additions & 0 deletions Sprung/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Fody" version="3.1.3" targetFramework="net461" developmentDependency="true" />
<package id="MethodTimer.Fody" version="2.2.0" targetFramework="net461" />
<package id="Nancy" version="1.4.4" targetFramework="net45" />
<package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net45" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net45" />
Expand Down

0 comments on commit 41921dd

Please sign in to comment.