add processor metric

This commit is contained in:
harisreedhar
2026-03-17 14:01:57 +01:00
committed by henryruhs
parent fa82d87302
commit 0bc6a545bf
3 changed files with 60 additions and 3 deletions
+26 -2
View File
@@ -6,7 +6,7 @@ import psutil
from facefusion import state_manager from facefusion import state_manager
from facefusion.execution import detect_execution_devices from facefusion.execution import detect_execution_devices
from facefusion.types import DiskMetrics, MemoryMetrics, Metrics, NetworkMetrics from facefusion.types import DiskMetrics, MemoryMetrics, Metrics, NetworkMetrics, ProcessorMetrics
def get_metrics_set() -> Metrics: def get_metrics_set() -> Metrics:
@@ -17,7 +17,8 @@ def get_metrics_set() -> Metrics:
'execution_devices': detect_execution_devices(), 'execution_devices': detect_execution_devices(),
'disks': detect_disk_metrics([ drive_path ]), 'disks': detect_disk_metrics([ drive_path ]),
'memory': detect_memory_metrics(), 'memory': detect_memory_metrics(),
'network': detect_network_metrics() 'network': detect_network_metrics(),
'processor': detect_processor_metrics()
} }
@@ -88,3 +89,26 @@ def detect_network_metrics() -> NetworkMetrics:
'unit': 'MB' 'unit': 'MB'
} }
} }
def detect_processor_metrics() -> ProcessorMetrics:
cpu_frequency = psutil.cpu_freq()
return\
{
'cores':
{
'value': psutil.cpu_count(logical = True),
'unit': 'cores'
},
'frequency':
{
'value': int(cpu_frequency.current),
'unit': 'MHz'
},
'utilization':
{
'value': int(psutil.cpu_percent(interval = None)),
'unit': '%'
}
}
+8 -1
View File
@@ -315,12 +315,19 @@ NetworkMetrics = TypedDict('NetworkMetrics',
'sent' : ValueAndUnit, 'sent' : ValueAndUnit,
'received' : ValueAndUnit 'received' : ValueAndUnit
}) })
ProcessorMetrics = TypedDict('ProcessorMetrics',
{
'cores' : ValueAndUnit,
'frequency' : ValueAndUnit,
'utilization' : ValueAndUnit
})
Metrics = TypedDict('Metrics', Metrics = TypedDict('Metrics',
{ {
'execution_devices' : List[ExecutionDevice], 'execution_devices' : List[ExecutionDevice],
'disks' : List[DiskMetrics], 'disks' : List[DiskMetrics],
'memory' : MemoryMetrics, 'memory' : MemoryMetrics,
'network' : NetworkMetrics 'network' : NetworkMetrics,
'processor' : ProcessorMetrics
}) })
DownloadProvider = Literal['github', 'huggingface'] DownloadProvider = Literal['github', 'huggingface']
+26
View File
@@ -73,6 +73,24 @@ def mock_detect_execution_devices(mocker : MockerFixture) -> None:
'unit': 'MB' 'unit': 'MB'
} }
}) })
mocker.patch('facefusion.system.detect_processor_metrics', return_value =
{
'cores':
{
'value': 16,
'unit': 'cores'
},
'frequency':
{
'value': 3500,
'unit': 'MHz'
},
'utilization':
{
'value': 25,
'unit': '%'
}
})
mocker.patch('facefusion.system.detect_execution_devices', return_value = mocker.patch('facefusion.system.detect_execution_devices', return_value =
[ [
{ {
@@ -165,6 +183,10 @@ def test_get_metrics(test_client : TestClient) -> None:
assert metrics_body.get('network').get('sent').get('unit') == 'MB' assert metrics_body.get('network').get('sent').get('unit') == 'MB'
assert metrics_body.get('network').get('received').get('value') == 2048 assert metrics_body.get('network').get('received').get('value') == 2048
assert metrics_body.get('processor').get('cores').get('value') == 16
assert metrics_body.get('processor').get('frequency').get('value') == 3500
assert metrics_body.get('processor').get('utilization').get('value') == 25
def test_websocket_metrics(test_client : TestClient) -> None: def test_websocket_metrics(test_client : TestClient) -> None:
create_session_response = test_client.post('/session', json = create_session_response = test_client.post('/session', json =
@@ -194,3 +216,7 @@ def test_websocket_metrics(test_client : TestClient) -> None:
assert metrics_set.get('network').get('sent').get('value') == 1024 assert metrics_set.get('network').get('sent').get('value') == 1024
assert metrics_set.get('network').get('sent').get('unit') == 'MB' assert metrics_set.get('network').get('sent').get('unit') == 'MB'
assert metrics_set.get('network').get('received').get('value') == 2048 assert metrics_set.get('network').get('received').get('value') == 2048
assert metrics_set.get('processor').get('cores').get('value') == 16
assert metrics_set.get('processor').get('frequency').get('value') == 3500
assert metrics_set.get('processor').get('utilization').get('value') == 25