mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-10-11 04:16:17 +00:00
Update flask_server.py
This commit is contained in:
@@ -1596,66 +1596,139 @@ def get_detailed_gpu_info(gpu):
|
|||||||
|
|
||||||
data_retrieved = False
|
data_retrieved = False
|
||||||
try:
|
try:
|
||||||
# Start intel_gpu_top process
|
# Start intel_gpu_top process with JSON output to stdout
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
['intel_gpu_top', '-s', '100'],
|
['intel_gpu_top', '-J', '-s', '1000', '-o', '-'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE,
|
stderr=subprocess.PIPE,
|
||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
# Wait for output with timeout
|
# Wait for output with increased timeout
|
||||||
try:
|
try:
|
||||||
stdout, stderr = process.communicate(timeout=2)
|
stdout, stderr = process.communicate(timeout=15)
|
||||||
|
|
||||||
if stdout:
|
if stdout:
|
||||||
output = stdout
|
output = stdout.strip()
|
||||||
print(f"[v0] intel_gpu_top output received: {output[:200]}...")
|
print(f"[v0] intel_gpu_top output received: {output[:300]}...")
|
||||||
|
|
||||||
# Parse frequency: "0/ 0 MHz"
|
# Try to parse as JSON
|
||||||
freq_match = re.search(r'(\d+)/\s*(\d+)\s*MHz', output)
|
try:
|
||||||
if freq_match:
|
import json
|
||||||
detailed_info['clock_graphics'] = f"{freq_match.group(1)} MHz"
|
# The output may contain multiple JSON objects, get the first one
|
||||||
detailed_info['clock_max'] = f"{freq_match.group(2)} MHz"
|
json_str = output
|
||||||
data_retrieved = True
|
# Find first complete JSON object
|
||||||
|
brace_count = 0
|
||||||
# Parse power: "0.00/ 7.23 W"
|
json_end = -1
|
||||||
power_match = re.search(r'([\d.]+)/\s*([\d.]+)\s*W', output)
|
for i, char in enumerate(output):
|
||||||
if power_match:
|
if char == '{':
|
||||||
detailed_info['power_draw'] = f"{power_match.group(1)} W"
|
brace_count += 1
|
||||||
detailed_info['power_limit'] = f"{power_match.group(2)} W"
|
elif char == '}':
|
||||||
data_retrieved = True
|
brace_count -= 1
|
||||||
|
if brace_count == 0:
|
||||||
# Parse RC6 (power saving state): "100% RC6"
|
json_end = i + 1
|
||||||
rc6_match = re.search(r'(\d+)%\s*RC6', output)
|
break
|
||||||
if rc6_match:
|
|
||||||
detailed_info['power_state'] = f"RC6: {rc6_match.group(1)}%"
|
if json_end > 0:
|
||||||
data_retrieved = True
|
json_str = output[:json_end]
|
||||||
|
|
||||||
# Parse engine utilization
|
json_data = json.loads(json_str)
|
||||||
engines = {
|
|
||||||
'Render/3D': 'engine_render',
|
# Parse frequency data
|
||||||
'Blitter': 'engine_blitter',
|
if 'frequency' in json_data:
|
||||||
'Video': 'engine_video',
|
freq = json_data['frequency']
|
||||||
'VideoEnhance': 'engine_video_enhance'
|
if 'actual' in freq:
|
||||||
}
|
detailed_info['clock_graphics'] = f"{freq['actual']:.0f} MHz"
|
||||||
for engine_name, key in engines.items():
|
data_retrieved = True
|
||||||
pattern = rf'{engine_name}\s+([\d.]+)%'
|
if 'requested' in freq:
|
||||||
match = re.search(pattern, output)
|
detailed_info['clock_max'] = f"{freq['requested']:.0f} MHz"
|
||||||
if match:
|
data_retrieved = True
|
||||||
detailed_info[key] = float(match.group(1))
|
|
||||||
|
# Parse power data
|
||||||
|
if 'power' in json_data:
|
||||||
|
power = json_data['power']
|
||||||
|
if 'GPU' in power:
|
||||||
|
detailed_info['power_draw'] = f"{power['GPU']:.2f} W"
|
||||||
|
data_retrieved = True
|
||||||
|
if 'Package' in power:
|
||||||
|
detailed_info['power_limit'] = f"{power['Package']:.2f} W"
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse RC6 state
|
||||||
|
if 'rc6' in json_data:
|
||||||
|
rc6_value = json_data['rc6'].get('value', 0)
|
||||||
|
detailed_info['power_state'] = f"RC6: {rc6_value:.1f}%"
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse interrupts
|
||||||
|
if 'interrupts' in json_data:
|
||||||
|
irq_count = json_data['interrupts'].get('count', 0)
|
||||||
|
detailed_info['irq_rate'] = int(irq_count)
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse engine utilization
|
||||||
|
if 'engines' in json_data:
|
||||||
|
engines_data = json_data['engines']
|
||||||
|
engine_map = {
|
||||||
|
'Render/3D': 'engine_render',
|
||||||
|
'Blitter': 'engine_blitter',
|
||||||
|
'Video': 'engine_video',
|
||||||
|
'VideoEnhance': 'engine_video_enhance'
|
||||||
|
}
|
||||||
|
for engine_name, key in engine_map.items():
|
||||||
|
if engine_name in engines_data:
|
||||||
|
busy_value = engines_data[engine_name].get('busy', 0)
|
||||||
|
detailed_info[key] = float(busy_value)
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
print(f"[v0] Intel GPU parsed JSON data successfully: {detailed_info}")
|
||||||
|
|
||||||
|
except (json.JSONDecodeError, ValueError) as e:
|
||||||
|
print(f"[v0] JSON parsing failed: {e}, using text parsing")
|
||||||
|
|
||||||
|
# Fallback to text parsing if JSON fails
|
||||||
|
# Parse frequency: "0/ 0 MHz"
|
||||||
|
freq_match = re.search(r'(\d+)/\s*(\d+)\s*MHz', output)
|
||||||
|
if freq_match:
|
||||||
|
detailed_info['clock_graphics'] = f"{freq_match.group(1)} MHz"
|
||||||
|
detailed_info['clock_max'] = f"{freq_match.group(2)} MHz"
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse power: "0.00/ 7.23 W"
|
||||||
|
power_match = re.search(r'([\d.]+)/\s*([\d.]+)\s*W', output)
|
||||||
|
if power_match:
|
||||||
|
detailed_info['power_draw'] = f"{power_match.group(1)} W"
|
||||||
|
detailed_info['power_limit'] = f"{power_match.group(2)} W"
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse RC6 (power saving state): "100% RC6"
|
||||||
|
rc6_match = re.search(r'(\d+)%\s*RC6', output)
|
||||||
|
if rc6_match:
|
||||||
|
detailed_info['power_state'] = f"RC6: {rc6_match.group(1)}%"
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse engine utilization
|
||||||
|
engines = {
|
||||||
|
'Render/3D': 'engine_render',
|
||||||
|
'Blitter': 'engine_blitter',
|
||||||
|
'Video': 'engine_video',
|
||||||
|
'VideoEnhance': 'engine_video_enhance'
|
||||||
|
}
|
||||||
|
for engine_name, key in engines.items():
|
||||||
|
pattern = rf'{engine_name}\s+([\d.]+)%'
|
||||||
|
match = re.search(pattern, output)
|
||||||
|
if match:
|
||||||
|
detailed_info[key] = float(match.group(1))
|
||||||
|
data_retrieved = True
|
||||||
|
|
||||||
|
# Parse IRQ rate
|
||||||
|
irq_match = re.search(r'(\d+)\s*irqs/s', output)
|
||||||
|
if irq_match:
|
||||||
|
detailed_info['irq_rate'] = int(irq_match.group(1))
|
||||||
data_retrieved = True
|
data_retrieved = True
|
||||||
|
|
||||||
# Parse IRQ rate
|
|
||||||
irq_match = re.search(r'(\d+)\s*irqs/s', output)
|
|
||||||
if irq_match:
|
|
||||||
detailed_info['irq_rate'] = int(irq_match.group(1))
|
|
||||||
data_retrieved = True
|
|
||||||
|
|
||||||
print(f"[v0] Intel GPU parsed data: {detailed_info}")
|
|
||||||
|
|
||||||
except subprocess.TimeoutExpired:
|
except subprocess.TimeoutExpired:
|
||||||
print(f"[v0] intel_gpu_top process timed out, terminating...")
|
print(f"[v0] intel_gpu_top process timed out after 15 seconds, terminating...")
|
||||||
process.terminate()
|
process.terminate()
|
||||||
try:
|
try:
|
||||||
process.wait(timeout=1)
|
process.wait(timeout=1)
|
||||||
|
Reference in New Issue
Block a user