mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-12-15 16:46:24 +00:00
Update flask_server.py
This commit is contained in:
@@ -1652,49 +1652,38 @@ def get_detailed_gpu_info(gpu):
|
|||||||
output_lines.append(line)
|
output_lines.append(line)
|
||||||
output = ''.join(output_lines)
|
output = ''.join(output_lines)
|
||||||
|
|
||||||
if len(output_lines) <= 5:
|
if len(output_lines) <= 10:
|
||||||
print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}")
|
print(f"[v0] Received line {len(output_lines)}: {line.strip()[:100]}")
|
||||||
|
|
||||||
# intel_gpu_top -J outputs: [\n{\n...\n},\n{\n...\n}\n]
|
# intel_gpu_top outputs individual JSON objects, not necessarily wrapped in array
|
||||||
# We need to find the first complete object inside the array
|
|
||||||
|
|
||||||
# First, check if we have the array start
|
# Find the first opening brace
|
||||||
if '[' not in output:
|
object_start = output.find('{')
|
||||||
|
if object_start == -1:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
print(f"[v0] Found array start bracket, total output length: {len(output)}")
|
# Count braces to find complete object
|
||||||
|
|
||||||
# Find the start of the array
|
|
||||||
array_start = output.index('[')
|
|
||||||
after_array_start = output[array_start + 1:]
|
|
||||||
|
|
||||||
# Now look for the first complete object inside the array
|
|
||||||
brace_count = 0
|
brace_count = 0
|
||||||
in_object = False
|
|
||||||
object_start = -1
|
|
||||||
object_end = -1
|
object_end = -1
|
||||||
|
|
||||||
for i, char in enumerate(after_array_start):
|
for i in range(object_start, len(output)):
|
||||||
if char == '{':
|
if output[i] == '{':
|
||||||
if brace_count == 0:
|
|
||||||
object_start = i
|
|
||||||
in_object = True
|
|
||||||
brace_count += 1
|
brace_count += 1
|
||||||
elif char == '}':
|
elif output[i] == '}':
|
||||||
brace_count -= 1
|
brace_count -= 1
|
||||||
if brace_count == 0 and in_object:
|
if brace_count == 0:
|
||||||
object_end = i + 1
|
object_end = i + 1
|
||||||
break
|
break
|
||||||
|
|
||||||
print(f"[v0] Object parsing: start={object_start}, end={object_end}, brace_count={brace_count}")
|
if object_end > object_start:
|
||||||
|
|
||||||
if object_start >= 0 and object_end > object_start:
|
|
||||||
# Extract the first complete JSON object
|
# Extract the first complete JSON object
|
||||||
json_str = after_array_start[object_start:object_end]
|
json_str = output[object_start:object_end]
|
||||||
print(f"[v0] Extracted JSON string (first 200 chars): {json_str[:200]}")
|
print(f"[v0] Found complete JSON object ({len(json_str)} chars)")
|
||||||
|
print(f"[v0] JSON preview (first 300 chars): {json_str[:300]}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json_data = json.loads(json_str)
|
json_data = json.loads(json_str)
|
||||||
print(f"[v0] Successfully parsed JSON object from intel_gpu_top array")
|
print(f"[v0] Successfully parsed JSON from intel_gpu_top")
|
||||||
print(f"[v0] JSON keys: {list(json_data.keys())}")
|
print(f"[v0] JSON keys: {list(json_data.keys())}")
|
||||||
|
|
||||||
# Parse frequency data
|
# Parse frequency data
|
||||||
|
|||||||
Reference in New Issue
Block a user