-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Resources.vala
92 lines (79 loc) · 2.92 KB
/
Resources.vala
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
[DBus (name = "org.gnome.SessionManager")]
public interface SessionManager : Object {
[DBus (name = "Renderer")]
public abstract string renderer { owned get;}
}
public class Monitor.Resources : Object {
public CPU cpu;
public Memory memory;
public Swap swap;
public Network network;
public Storage storage;
public IGPU gpu;
private HwmonPathParser hwmon_path_parser;
construct {
hwmon_path_parser = new HwmonPathParser ();
memory = new Memory ();
cpu = new CPU ();
swap = new Swap ();
network = new Network ();
storage = new Storage ();
SessionManager session_manager = get_sessman ();
string gpu_name = session_manager.renderer.down ();
if (gpu_name.contains ("intel")) {
} else if (gpu_name.contains ("nvidia") || gpu_name.contains ("geforce")) {
gpu = new GPUNvidia ();
gpu.session_manager = session_manager;
} else if (gpu_name.contains ("amd")) {
gpu = new GPUAmd ();
gpu.session_manager = session_manager;
gpu.hwmon_temperatures = hwmon_path_parser.gpu_paths_parser.temperatures;
} else {
warning ("GPU: Unknown: %s", gpu_name);
}
cpu.temperatures = hwmon_path_parser.cpu_paths_parser.temperatures;
update ();
}
public void update () {
Timeout.add_seconds (MonitorApp.settings.get_int ("update-time"), () => {
new Thread<void> ("update-resources", () => {
cpu.update ();
memory.update ();
network.update ();
storage.update ();
if (gpu != null) gpu.update ();
});
return true;
});
}
public SessionManager? get_sessman () {
try {
SessionManager session_manager = Bus.get_proxy_sync (
BusType.SESSION,
"org.gnome.SessionManager",
"/org/gnome/SessionManager"
);
debug ("GPU: %s", session_manager.renderer);
return session_manager;
} catch (IOError e) {
warning (e.message);
return null;
}
}
public ResourcesSerialized serialize () {
return ResourcesSerialized () {
cpu_percentage = cpu.percentage,
cpu_frequency = cpu.frequency,
cpu_temperature = cpu.temperature_mean,
memory_percentage = memory.used_percentage,
memory_used = memory.used,
memory_total = memory.total,
swap_percentage = swap.percentage,
swap_used = swap.used,
swap_total = swap.total,
network_up = network.bytes_out,
network_down = network.bytes_in,
gpu_percentage = gpu != null ? gpu.percentage : 0
};
}
}