-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add GPU stats to the /stats API and debug screen #3931
Merged
Merged
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
aadc8a8
Add ffprobe endpoint
NickM-27 18b0840
Get ffprobe for multiple inputs
NickM-27 97a56b8
Copy ffprobe in output
NickM-27 ff45b6d
Fix bad if statement
NickM-27 f294ec1
Return full output of ffprobe process
NickM-27 1337c78
Return full output of ffprobe process
NickM-27 2bf706c
Make ffprobe button show dialog with output and option to copy
NickM-27 1dd80f4
Add driver names to consts
NickM-27 fa765da
Add driver env var name
NickM-27 96b9704
Setup general tracking for GPU stats
NickM-27 3180dfd
Catch RPi args as well
NickM-27 497ebf6
Add util to get radeontop results
NickM-27 38317b9
Add real amd GPU stats
NickM-27 17c2522
Fix missed arg
NickM-27 41ac558
pass config
NickM-27 615135d
Use only the values
NickM-27 c97975e
Fix vram
NickM-27 4ffdfe6
Add nvidia gpu stats
NickM-27 cc15014
Use nvidia stats
NickM-27 1b35af4
Add chart for gpu stats
NickM-27 1d7265f
Format AMD with space between percent
NickM-27 987bc05
Get correct nvidia %
NickM-27 2e1958a
Start to add support for intel GPU stats
NickM-27 beb8229
Block out RPi as util is not currently available
NickM-27 447df28
Formatting
NickM-27 250440c
Fix mypy
NickM-27 c7d461c
Strip for float conversion
NickM-27 f1a8a79
Strip for float conversion
NickM-27 fa69851
Fix percent formatting
NickM-27 b0a2822
Remove name from gpu map
NickM-27 9b5516c
Add tests and fix AMD formatting
NickM-27 eb25935
Add nvidia gpu stats test
NickM-27 61cac3c
Formatting
NickM-27 86074e6
Add intel_gpu_top for testing
NickM-27 baeb3dd
Formatting
NickM-27 3be336a
Handle case where hwaccel is not setup
NickM-27 bf06f4d
Formatting
NickM-27 e200718
Check to remove none
NickM-27 412144b
Don't use set
NickM-27 be21a21
Cleanup and fix types
NickM-27 2c38913
Handle case where args is list
NickM-27 1062e26
Fix mypy
NickM-27 c28471a
Cast to str
NickM-27 d6e37a3
Fix type checking
NickM-27 ca2733a
Return none instead of empty
NickM-27 bc205ad
Fix organization
NickM-27 cc7bae6
Make keys consistent
NickM-27 472888c
Make gpu match style
NickM-27 9f1d2b9
Get support for vainfo
NickM-27 82e9b34
Add vainfo endpoint
NickM-27 51fe3dd
Set vainfo output in error correctly
NickM-27 67fd039
Remove duplicate function
NickM-27 3b3382d
Fix errors
NickM-27 b93eb68
Do cpu & gpu work asynchonously
NickM-27 39a5e25
Fix async
NickM-27 65e8b32
Fix event loop
NickM-27 1cedf05
Fix crash
NickM-27 35288ec
Fix naming
NickM-27 f172e3d
Send empty data for gpu if error occurs
NickM-27 35947e2
Show error if gpu stats could not be retrieved
NickM-27 ea63fcd
Fix mypy
NickM-27 8e132eb
Fix test
NickM-27 3cc4ce7
Don't use json for vainfo
NickM-27 5158e5e
Fix cross references
NickM-27 e4c588c
Strip unicode still
NickM-27 b285499
await vainfo response
NickM-27 46bd278
Add gpu deps
NickM-27 e86c23f
Formatting
NickM-27 196b558
remove comments
NickM-27 c6c9e13
Use empty string
NickM-27 98adac4
Add vainfo back in
NickM-27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import unittest | ||
from unittest.mock import MagicMock, patch | ||
|
||
from frigate.util import get_amd_gpu_stats, get_intel_gpu_stats, get_nvidia_gpu_stats | ||
|
||
|
||
class TestGpuStats(unittest.TestCase): | ||
def setUp(self): | ||
self.amd_results = "Unknown Radeon card. <= R500 won't work, new cards might.\nDumping to -, line limit 1.\n1664070990.607556: bus 10, gpu 4.17%, ee 0.00%, vgt 0.00%, ta 0.00%, tc 0.00%, sx 0.00%, sh 0.00%, spi 0.83%, smx 0.00%, cr 0.00%, sc 0.00%, pa 0.00%, db 0.00%, cb 0.00%, vram 60.37% 294.04mb, gtt 0.33% 52.21mb, mclk 100.00% 1.800ghz, sclk 26.65% 0.533ghz\n" | ||
self.intel_results = """{"period":{"duration":1.194033,"unit":"ms"},"frequency":{"requested":0.000000,"actual":0.000000,"unit":"MHz"},"interrupts":{"count":3349.991164,"unit":"irq/s"},"rc6":{"value":47.844741,"unit":"%"},"engines":{"Render/3D/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"Blitter/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"Video/0":{"busy":4.533124,"sema":0.000000,"wait":0.000000,"unit":"%"},"Video/1":{"busy":6.194385,"sema":0.000000,"wait":0.000000,"unit":"%"},"VideoEnhance/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"}}},{"period":{"duration":1.189291,"unit":"ms"},"frequency":{"requested":0.000000,"actual":0.000000,"unit":"MHz"},"interrupts":{"count":0.000000,"unit":"irq/s"},"rc6":{"value":100.000000,"unit":"%"},"engines":{"Render/3D/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"Blitter/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"Video/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"Video/1":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"},"VideoEnhance/0":{"busy":0.000000,"sema":0.000000,"wait":0.000000,"unit":"%"}}}""" | ||
self.nvidia_results = "name, utilization.gpu [%], memory.used [MiB], memory.total [MiB]\nNVIDIA GeForce RTX 3050, 42 %, 5036 MiB, 8192 MiB\n" | ||
|
||
@patch("subprocess.run") | ||
def test_amd_gpu_stats(self, sp): | ||
process = MagicMock() | ||
process.returncode = 0 | ||
process.stdout = self.amd_results | ||
sp.return_value = process | ||
amd_stats = get_amd_gpu_stats() | ||
assert amd_stats == {"gpu": "4.17 %", "mem": "60.37 %"} | ||
|
||
@patch("subprocess.run") | ||
def test_nvidia_gpu_stats(self, sp): | ||
process = MagicMock() | ||
process.returncode = 0 | ||
process.stdout = self.nvidia_results | ||
sp.return_value = process | ||
nvidia_stats = get_nvidia_gpu_stats() | ||
assert nvidia_stats == { | ||
"name": "NVIDIA GeForce RTX 3050", | ||
"gpu": "42 %", | ||
"mem": "61.5 %", | ||
} | ||
|
||
@patch("subprocess.run") | ||
def test_intel_gpu_stats(self, sp): | ||
process = MagicMock() | ||
process.returncode = 0 | ||
process.stdout = self.intel_results | ||
sp.return_value = process | ||
intel_stats = get_intel_gpu_stats() | ||
assert intel_stats == { | ||
"gpu": "10.73 %", | ||
"mem": "- %", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the only reason to introduce asyncio stuff here so we can wait for these to run in parallel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, with the cpu and 2 gpus my production server takes ~ 7-10 seconds and with this it's more like 3-5 seconds. There definitely may be better ways to parallelize it or run the actual checks in the background and cache / average the returned results so when /stats is called it can return without waiting.