add plugin system with plugin/layout managers
- plugin_manager: scans res://plugins/*/plugin.cfg, loads tile definitions - plugin_tile: new base class for plugin tiles, extends ModuleBase - layout_manager: save/restore tile grid positions per named layout - migrate existing cpu/memory/testing tiles into system_monitor plugin - add module_resized signal to DashboardGrid for auto-save - dashboard reads from PluginManager + LayoutManager instead of hardcoded paths - project.godot registers PluginManager and LayoutManager autoloads - AGENTS.md updated with new structure and conventions
This commit is contained in:
parent
63af41ea61
commit
f43676e46c
19 changed files with 528 additions and 39 deletions
51
plugins/system_monitor/tiles/cpu/cpu_collector.gd
Normal file
51
plugins/system_monitor/tiles/cpu/cpu_collector.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
extends RefCounted
|
||||
class_name CpuCollector
|
||||
|
||||
|
||||
var _previous_total: int = 0
|
||||
var _previous_idle: int = 0
|
||||
var _has_previous: bool = false
|
||||
|
||||
|
||||
func collect() -> float:
|
||||
var stats: PackedStringArray = _read_stats()
|
||||
if stats.is_empty():
|
||||
return 0.0
|
||||
|
||||
var total: int = 0
|
||||
var idle: int = 0
|
||||
|
||||
for i in range(1, stats.size()):
|
||||
var val: int = stats[i].to_int()
|
||||
total += val
|
||||
if i == 4: # idle is the 4th token (index 4)
|
||||
idle = val
|
||||
|
||||
if not _has_previous:
|
||||
_previous_total = total
|
||||
_previous_idle = idle
|
||||
_has_previous = true
|
||||
return 0.0
|
||||
|
||||
var total_delta: int = total - _previous_total
|
||||
var idle_delta: int = idle - _previous_idle
|
||||
|
||||
_previous_total = total
|
||||
_previous_idle = idle
|
||||
|
||||
if total_delta == 0:
|
||||
return 0.0
|
||||
|
||||
return 100.0 * (1.0 - float(idle_delta) / float(total_delta))
|
||||
|
||||
|
||||
func _read_stats() -> PackedStringArray:
|
||||
var file := FileAccess.open("/proc/stat", FileAccess.READ)
|
||||
if file == null:
|
||||
return PackedStringArray()
|
||||
|
||||
var line: String = file.get_line()
|
||||
if not line.begins_with("cpu "):
|
||||
return PackedStringArray()
|
||||
|
||||
return line.split(" ", false)
|
||||
Loading…
Add table
Add a link
Reference in a new issue