Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOSに対応 #962

Merged
merged 15 commits into from
Mar 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
MacOSでmemory_pressureコマンドを使用してメモリ容量を取得するようにした
  • Loading branch information
yuto-trd committed Mar 28, 2024
commit bb99b6ded3562670c9407efacaf867e30885b8a3
29 changes: 27 additions & 2 deletions src/Beutl.Configuration/EditorConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using System.Runtime.Loader;
using System.Runtime.Versioning;

using System.Text.RegularExpressions;
using Beutl.Collections;
using Beutl.Serialization;

Expand Down Expand Up @@ -34,7 +34,7 @@ public enum FrameCacheConfigColorType
YUV
}

public sealed class EditorConfig : ConfigurationBase
public sealed partial class EditorConfig : ConfigurationBase
{
public static readonly CoreProperty<bool> AutoAdjustSceneDurationProperty;
public static readonly CoreProperty<bool> EnablePointerLockInPropertyProperty;
Expand Down Expand Up @@ -67,6 +67,7 @@ static EditorConfig()

ulong memSize = OperatingSystem.IsWindows() ? GetWindowsMemoryCapacity()
: OperatingSystem.IsLinux() ? GetLinuxMemoryCapacity()
: OperatingSystem.IsMacOS() ? GetMacMemoryCapacity()
: 1024 * 1024 * 1024;
double memSizeInMG = memSize / (1024d * 1024d);

Expand Down Expand Up @@ -248,4 +249,28 @@ private static ulong GetLinuxMemoryCapacity()
// https://help.ubuntu.com/community/Installation/SystemRequirements
return 4L * 1024 * 1024 * 1024;
}

private static ulong GetMacMemoryCapacity()
{
var startInfo = new ProcessStartInfo("/usr/bin/memory_pressure", "-Q")
{
RedirectStandardOutput = true
};
var proc = Process.Start(startInfo);
if (proc != null)
{
proc.WaitForExit();
string? str = proc.StandardOutput.ReadLine();
Regex regex = NumberRegex();
if (str != null && regex.Match(str) is { Success: true } match)
{
return ulong.Parse(match.Value);
}
}

return 4L * 1024 * 1024 * 1024;
}

[GeneratedRegex(@"(\d+)")]
private static partial Regex NumberRegex();
}