#!/usr/bin/env python3 """Local, read-only Linux telemetry; bounded report + Lua handoff. No driver changes.""" import argparse, json, math, os, platform, shutil, subprocess, time from pathlib import Path def fps_target(value): try: fps=int(str(value)) except (TypeError, ValueError): raise argparse.ArgumentTypeError('FPS must be a whole number from 20 to 240.') if not 20<=fps<=240: raise argparse.ArgumentTypeError('FPS must be a whole number from 20 to 240.') return fps def read(p): try: return Path(p).read_text().strip() except (OSError, ValueError): return '' def throttles(): out={} for p in Path('/sys/devices/system/cpu').glob('cpu*/thermal_throttle/*throttle_count'): try: out[str(p)]=int(read(p)) except ValueError: pass return out def gpu(): exe=shutil.which('nvidia-smi') if not exe: return {} q='name,temperature.gpu,utilization.gpu,clocks_event_reasons.hw_thermal_slowdown,clocks_event_reasons.sw_thermal_slowdown' try: r=subprocess.run([exe,'--query-gpu='+q,'--format=csv,noheader,nounits'],capture_output=True,text=True,timeout=4) rows=[line.split(', ') for line in r.stdout.splitlines() if len(line.split(', '))==5] if not rows: return {} return {'gpuTemp':max(float(row[1]) for row in rows), 'gpuLoad':max(float(row[2]) for row in rows), 'gpuThermal':any(v.strip()=='Active' for row in rows for v in row[3:]), 'gpuNames':[row[0] for row in rows]} except (OSError,ValueError,subprocess.TimeoutExpired): return {} def sample(): temps=[]; hot=False for h in Path('/sys/class/hwmon').glob('*'): name=read(h/'name') if name not in ('coretemp','k10temp','zenpower','cpu_thermal','amdgpu','nouveau'): continue for p in h.glob('temp*_input'): try: value=int(read(p))/1000 if not 0=ceiling except ValueError: pass g=gpu();hot=hot or g.get('gpuTemp',0)>=83 or g.get('gpuThermal',False) return {'time':int(time.time()),'temperatures':temps,'temperaturePressure':hot, **g} def game_running(): names={'wow.exe','wowclassic.exe','wow-64.exe'} for p in Path('/proc').glob('[0-9]*/cmdline'): args=read(p).split('\0')[:2] if any(a.replace('\\','/').rsplit('/',1)[-1].lower() in names for a in args):return True return False def evaluate(seconds=600, interval=5): before=throttles(); start=time.monotonic(); samples=[]; hot_count=0; lastcpu=None; thermal=False while True: s=sample(); raw=read('/proc/stat').splitlines()[0].split()[1:] nums=list(map(int,raw[:8])); total=sum(nums); idle=nums[3]+nums[4] if lastcpu and total>lastcpu[0]: s['cpuLoad']=100*(1-(idle-lastcpu[1])/(total-lastcpu[0])) lastcpu=(total,idle);s['gameRunning']=game_running();samples.append(s) hot_count=hot_count+1 if s['temperaturePressure'] else 0 thermal=thermal or any(value>before.get(key,value) for key,value in throttles().items()) or s.get('gpuThermal',False) age=time.monotonic()-start if age>=seconds or thermal or hot_count>=3: break time.sleep(min(interval,seconds-age)) duration=time.monotonic()-start load=sum(s['gameRunning'] and (s.get('gpuLoad',0)>20 or s.get('cpuLoad',0)>15) for s in samples) loaded=duration>=180 and load>=len(samples)*.6 cpu_seen=bool(before) or any(t['sensor'].split('/')[0] in ('coretemp','k10temp','zenpower','cpu_thermal') for t in samples[-1]['temperatures']) gpu_seen='gpuTemp' in samples[-1] or any(t['sensor'].split('/')[0] in ('amdgpu','nouveau') for t in samples[-1]['temperatures']) coverage='full' if cpu_seen and gpu_seen else 'partial' if cpu_seen or gpu_seen else 'unavailable' evidence='thermal throttling observed' if thermal else 'temperature headroom low' if hot_count>=3 else 'no thermal limit observed in sample' if samples[-1]['temperatures'] or 'gpuTemp' in samples[-1] else 'thermal sensors unavailable' return {'format':1,'platform':platform.platform(),'cpu':next((l.split(':',1)[1].strip() for l in read('/proc/cpuinfo').splitlines() if l.startswith('model name')),''), 'checkedAt':int(time.time()),'duration':round(duration,1),'loaded':loaded,'thermalCoverage':coverage,'thermalPressure':thermal or hot_count>=3,'evidence':evidence, 'cpuThermalCountersAvailable':bool(before),'samples':samples} def write_report(game,report,auto_start,target_fps=60): target_fps=fps_target(target_fps) report=dict(report,targetFPS=target_fps) addon=game/'Interface/AddOns/RuenUI' if not (addon/'RuenUI.toc').is_file(): raise ValueError('Install Ruen UI in this game folder first.') reports=game/'Ruen-UI-Reports';reports.mkdir(exist_ok=True) dest=reports/'hardware.json';old=reports/'hardware.previous.json' if dest.exists(): os.replace(dest,old) dest.write_text(json.dumps(report,indent=2)+'\n') profile={k:report[k] for k in ('checkedAt','loaded','thermalCoverage','thermalPressure','evidence','targetFPS')};profile['autoStart']=auto_start lua='local _, P = ...\nP.hardwareProfile = {\n'+''.join(' '+k+' = '+('true' if v is True else 'false' if v is False else str(v) if isinstance(v,int) else json.dumps(v))+',\n' for k,v in profile.items())+'}\n' tmp=addon/'HardwareProfile.lua.tmp';tmp.write_text(lua);os.replace(tmp,addon/'HardwareProfile.lua') return dest def main(): p=argparse.ArgumentParser();p.add_argument('--wow',required=True,type=Path);p.add_argument('--seconds',type=int,default=600);p.add_argument('--baseline',action='store_true') p.add_argument('--fps',type=fps_target,default=60,help='Requested FPS target (20–240; default: 60).') a=p.parse_args();game=a.wow.expanduser().resolve();game=game if game.name=='_forever_' else game/'_forever_' if not (game/'Wow.exe').is_file():p.error('Expected the Forever game directory containing Wow.exe.') if not 1<=a.seconds<=1800:p.error('--seconds must be 1–1800') print('Play normally in WoW while this window collects thermal evidence. No stress test or driver changes.',flush=True) r=evaluate(a.seconds);print(write_report(game,r,not a.baseline,a.fps));print(r['evidence']) print('Reload WoW to import this machine report'+(' and start world/raid calibration.' if not a.baseline else '.')) if __name__=='__main__': main()