-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemInfoGetter.cs
30 lines (29 loc) · 1.06 KB
/
MemInfoGetter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
using System;
namespace gtkfetch
{
class MemInfoGetter
{
public struct MemInfo
{
public decimal total;
public decimal available;
public decimal used;
}
public static MemInfo Mem;
static string totalexpr = @"MemTotal:\s*(\d*)";
static string availableexpr = @"MemAvailable:\s*(\d*)";
/// <summary> Reads memory info from /proc/meminfo and populates MemInfo instance </summary>
public static void GetMemInfo()
{
Mem.total = Decimal.Parse(FileReader.ReadFileAndFindGroup("/proc/meminfo", totalexpr, 1));
Mem.available = Decimal.Parse(FileReader.ReadFileAndFindGroup("/proc/meminfo", availableexpr, 1));
Mem.used = Mem.total - Mem.available;
}
/// <summary> Updates memory information </summary>
public static void RefreshMemInfo()
{
Mem.available = Decimal.Parse(FileReader.ReadFileAndFindGroup("/proc/meminfo", availableexpr, 1));
Mem.used = Mem.total - Mem.available;
}
}
}