mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-03 09:45:22 +03:00
Do cpu & gpu work asynchonously
This commit is contained in:
parent
3b3382d6d0
commit
b93eb689fa
@ -1,3 +1,4 @@
|
|||||||
|
import asyncio
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
@ -83,7 +84,15 @@ def get_temperatures() -> dict[str, float]:
|
|||||||
return temps
|
return temps
|
||||||
|
|
||||||
|
|
||||||
def get_gpu_stats(config: FrigateConfig) -> Optional[dict[str, dict]]:
|
def set_cpu_stats(all_stats: dict[str, str]) -> None:
|
||||||
|
"""Set cpu usage from top."""
|
||||||
|
cpu_stats = get_cpu_stats()
|
||||||
|
|
||||||
|
if cpu_stats:
|
||||||
|
all_stats["cpu_usages"] = cpu_stats
|
||||||
|
|
||||||
|
|
||||||
|
def set_gpu_stats(config: FrigateConfig, all_stats: dict[str, str]) -> None:
|
||||||
"""Parse GPUs from hwaccel args and use for stats."""
|
"""Parse GPUs from hwaccel args and use for stats."""
|
||||||
hwaccel_args = []
|
hwaccel_args = []
|
||||||
|
|
||||||
@ -136,9 +145,7 @@ def get_gpu_stats(config: FrigateConfig) -> Optional[dict[str, dict]]:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if stats:
|
if stats:
|
||||||
return stats
|
all_stats["gpu_usages"] = stats
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def stats_snapshot(
|
def stats_snapshot(
|
||||||
@ -181,8 +188,10 @@ def stats_snapshot(
|
|||||||
}
|
}
|
||||||
stats["detection_fps"] = round(total_detection_fps, 2)
|
stats["detection_fps"] = round(total_detection_fps, 2)
|
||||||
|
|
||||||
stats["cpu_usages"] = get_cpu_stats()
|
asyncio.gather(
|
||||||
stats["gpu_usages"] = get_gpu_stats(config)
|
asyncio.create_task(set_gpu_stats(config, stats)),
|
||||||
|
asyncio.create_task(set_cpu_stats(stats)),
|
||||||
|
)
|
||||||
|
|
||||||
stats["service"] = {
|
stats["service"] = {
|
||||||
"uptime": (int(time.time()) - stats_tracking["started"]),
|
"uptime": (int(time.time()) - stats_tracking["started"]),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user