This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 918b211
Showing
21 changed files
with
534 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
bin/ | ||
obj/ | ||
/packages/ | ||
riderModule.iml | ||
/_ReSharper.Caches/ | ||
.idea/* | ||
.vs/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{05260BE2-EF5A-46FC-8E63-3CE2E236543B}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hitomi", "src\Hitomi\Hitomi.csproj", "{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Hitomi.Core", "src\Hitomi.Core\Hitomi.Core.fsproj", "{7EE329FF-F874-40E4-A518-5928FA405BDB}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{D29B0512-37B7-4880-82F6-6248560F0F6D}" | ||
EndProject | ||
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Hitomi.Tests", "tests\Hitomi.Tests\Hitomi.Tests.fsproj", "{006A13CD-55FE-4AED-8E97-AE76B4A72717}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Debug|x86 = Debug|x86 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|x64.Build.0 = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Debug|x86.Build.0 = Debug|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|x64.ActiveCfg = Release|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|x64.Build.0 = Release|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|x86.ActiveCfg = Release|Any CPU | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8}.Release|x86.Build.0 = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|x64.Build.0 = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Debug|x86.Build.0 = Debug|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|x64.ActiveCfg = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|x64.Build.0 = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|x86.ActiveCfg = Release|Any CPU | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB}.Release|x86.Build.0 = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Debug|x64.Build.0 = Debug|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Debug|x86.ActiveCfg = Debug|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Debug|x86.Build.0 = Debug|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|x64.ActiveCfg = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|x64.Build.0 = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|x86.ActiveCfg = Release|Any CPU | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717}.Release|x86.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{35E9828C-E2D6-46D2-BDED-C06A7459BBD8} = {05260BE2-EF5A-46FC-8E63-3CE2E236543B} | ||
{7EE329FF-F874-40E4-A518-5928FA405BDB} = {05260BE2-EF5A-46FC-8E63-3CE2E236543B} | ||
{006A13CD-55FE-4AED-8E97-AE76B4A72717} = {D29B0512-37B7-4880-82F6-6248560F0F6D} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=05687d43_002Dceba_002D403c_002D8c5d_002Df938ce8a61e8/@EntryIndexedValue"><SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from Solution" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session">
 | ||
<Solution />
 | ||
</SessionState></s:String></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 s-cerevisiae | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Hitomi | ||
|
||
Hitomi is a small windows GUI utility which displays the most CPU consuming process in real time. | ||
|
||
> Fans shall spin for a reason. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0-windows</TargetFramework> | ||
<PublishTrimmed>true</PublishTrimmed> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="Process.fs" /> | ||
<Compile Include="View.fs" /> | ||
<Compile Include="Program.fs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Elmish.WPF" Version="3.5.8" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module Hitomi.Core.Process | ||
|
||
open System | ||
open System.ComponentModel | ||
open System.Diagnostics | ||
|
||
let processorCount = Environment.ProcessorCount | ||
|
||
let updateInterval = TimeSpan.FromSeconds 1.0 | ||
|
||
[<Struct>] | ||
type ProcessInterval = | ||
{ Name: string | ||
Interval: TimeSpan } | ||
member this.cpuPercentage(elapsed: TimeSpan) = | ||
float this.Interval.Ticks / float elapsed.Ticks | ||
* 100.0 | ||
/ float processorCount | ||
|> int | ||
|
||
/// Represents a process and its total cpu time | ||
[<Struct>] | ||
type ProcessorTime = | ||
{ Name: string | ||
ProcessorTime: TimeSpan } | ||
/// Extracts fields from a Process object. | ||
static member extract(p: Process) = | ||
let id = p.Id | ||
let name = p.ProcessName | ||
|
||
try | ||
Some(id, { Name = name; ProcessorTime = p.TotalProcessorTime }) | ||
with | ||
// Needs admin privilege | ||
| :? Win32Exception | ||
// Process already stopped | ||
| :? InvalidOperationException as e -> | ||
eprintfn $"{id}, {name}, {e.Message}" | ||
None | ||
|
||
static member (-)(p1, p0) = | ||
{ Name = p1.Name | ||
Interval = p1.ProcessorTime - p0.ProcessorTime } | ||
|
||
type ProcessEntry = | ||
{ Name: string | ||
Percentage: int } | ||
static member ofProcessInterval elapsed (t: ProcessInterval) = | ||
{ Name = t.Name; Percentage = t.cpuPercentage(elapsed) } | ||
|
||
/// Records processes and their total cpu time, indexed by process id. | ||
type ProcessMap = Map<int, ProcessorTime> | ||
|
||
module ProcessMap = | ||
/// Gets all running processes which are available. | ||
let getAll () = | ||
Process.GetProcesses() | ||
|> Array.choose ProcessorTime.extract | ||
|> Map.ofArray | ||
|
||
/// Get a list of time intervals from | ||
let listIntervals (m0: ProcessMap) (m1: ProcessMap) = | ||
m1 | ||
|> Seq.choose (fun p -> m0.TryFind p.Key |> Option.map ((-) p.Value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Hitomi.Core.Program | ||
|
||
open Elmish | ||
open Elmish.WPF | ||
|
||
open Hitomi.Core.View | ||
|
||
let designVm = ViewModel.designInstance (init ()) (bindings ()) | ||
|
||
let main window = | ||
Program.mkSimpleWpf init update bindings | ||
|> Program.withSubscription timer | ||
|> Program.startElmishLoop ElmConfig.Default window |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Hitomi.Core.View | ||
|
||
open Hitomi.Core.Process | ||
|
||
open System | ||
open System.Diagnostics | ||
open Elmish | ||
open Elmish.WPF | ||
|
||
type Model = | ||
{ LastMap: ProcessMap | ||
Watch: Stopwatch | ||
LastTime: TimeSpan | ||
Entry: ProcessEntry } | ||
|
||
let init () = | ||
{ LastMap = ProcessMap.getAll () | ||
Watch = Stopwatch.StartNew() | ||
LastTime = TimeSpan.Zero | ||
Entry = { Name = "null"; Percentage = 0 } } | ||
|
||
type Msg = Tick | ||
|
||
let update Tick model = | ||
let currentTime = model.Watch.Elapsed | ||
let currentMap = ProcessMap.getAll () | ||
|
||
let entry = | ||
ProcessMap.listIntervals model.LastMap currentMap | ||
|> Seq.maxBy (fun t -> t.Interval) | ||
|> ProcessEntry.ofProcessInterval (currentTime - model.LastTime) | ||
|
||
{ model with | ||
LastMap = currentMap | ||
Entry = entry | ||
LastTime = currentTime } | ||
|
||
|
||
let bindings () : Binding<Model, Msg> list = | ||
[ "ProcessName" | ||
|> Binding.oneWay (fun m -> m.Entry.Name) | ||
"Percentage" | ||
|> Binding.oneWay (fun m -> m.Entry.Percentage) ] | ||
|
||
let timer _ = | ||
let timer = new Timers.Timer(float updateInterval.TotalMilliseconds) | ||
timer.Start() | ||
let sub dispatch = timer.Elapsed.Add(fun _ -> dispatch Tick) | ||
Cmd.ofSub sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Application x:Class="Hitomi.App" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
StartupUri="MainWindow.xaml"> | ||
<Application.Resources> | ||
<ImageSource x:Key="Icon">pack://application:,,,/hitomi.ico</ImageSource> | ||
<ContextMenu x:Key="Menu"> | ||
<MenuItem Header="Exit" Click="Exit_OnClick"/> | ||
</ContextMenu> | ||
</Application.Resources> | ||
</Application> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Windows; | ||
using Hitomi.Core; | ||
|
||
namespace Hitomi | ||
{ | ||
/// <summary> | ||
/// Interaction logic for App.xaml | ||
/// </summary> | ||
public partial class App | ||
{ | ||
public App() | ||
{ | ||
Activated += StartElmish; | ||
} | ||
|
||
private void StartElmish(object sender, EventArgs e) | ||
{ | ||
Activated -= StartElmish; | ||
Program.main(MainWindow); | ||
} | ||
|
||
private void Exit_OnClick(object sender, RoutedEventArgs e) | ||
{ | ||
Current.Shutdown(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System.Windows; | ||
|
||
[assembly: ThemeInfo( | ||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located | ||
//(used if a resource is not found in the page, | ||
// or application resource dictionaries) | ||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located | ||
//(used if a resource is not found in the page, | ||
// app, or any theme specific resource dictionaries) | ||
)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<!-- <OutputType>WinExe</OutputType>--> | ||
<TargetFramework>net5.0-windows</TargetFramework> | ||
<UseWPF>true</UseWPF> | ||
<ApplicationIcon>hitomi.ico</ApplicationIcon> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Hitomi.Core\Hitomi.Core.fsproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Hardcodet.NotifyIcon.Wpf" Version="1.1.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Resource Include="hitomi.ico" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<Window x:Class="Hitomi.MainWindow" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:local="clr-namespace:Hitomi" | ||
xmlns:core="clr-namespace:Hitomi.Core;assembly=Hitomi.Core" | ||
mc:Ignorable="d" | ||
Title="Hitomi" | ||
WindowStyle="None" ResizeMode="NoResize" | ||
AllowsTransparency="True" | ||
Background="Transparent" | ||
ShowInTaskbar="False" | ||
SizeToContent="WidthAndHeight" | ||
d:DataContext="{x:Static core:Program.designVm}" | ||
MouseDown="MainWindow_OnMouseDown" | ||
Deactivated="MainWindow_OnDeactivated"> | ||
<Grid> | ||
<local:NotifyIcon /> | ||
<Border> | ||
<Border.Effect> | ||
<DropShadowEffect Direction="-75" ShadowDepth="2" BlurRadius="5" /> | ||
</Border.Effect> | ||
<Grid Background="White" Margin="5" ContextMenu="{StaticResource Menu}"> | ||
<StackPanel Orientation="Horizontal" Margin="5"> | ||
<TextBlock Text="{Binding ProcessName}" Margin="0,0,5,0" /> | ||
<TextBlock Text="{Binding Percentage}" /> | ||
<TextBlock Text="%" /> | ||
</StackPanel> | ||
</Grid> | ||
</Border> | ||
</Grid> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System; | ||
using System.Windows; | ||
using System.Windows.Input; | ||
|
||
namespace Hitomi | ||
{ | ||
/// <summary> | ||
/// Interaction logic for MainWindow.xaml | ||
/// </summary> | ||
public partial class MainWindow | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void MainWindow_OnMouseDown(object sender, MouseButtonEventArgs e) | ||
{ | ||
if (Mouse.LeftButton == MouseButtonState.Pressed) | ||
{ | ||
DragMove(); | ||
} | ||
} | ||
|
||
private void MainWindow_OnDeactivated(object sender, EventArgs e) | ||
{ | ||
((Window) sender).Topmost = true; | ||
} | ||
} | ||
} |
Oops, something went wrong.