#!/usr/bin/env python3 """对齐旧启动器和串行队列的实际时间凭据;预约时间不同于kernel活跃时间。""" import json from pathlib import Path import time import sys ROOT=Path(__file__).resolve().parents[1] sys.path.insert(0,str(ROOT/'scripts')) from download_assets import atomic def main(): path=ROOT/'provenance/gpu_cost_live_ledger.json';rows=json.loads(path.read_text()) if not any(r['stage']=='R0_real_input_smoke' for r in rows): smoke=json.loads((ROOT/'provenance/r0_smoke_audit.json').read_text()) rows.append(dict(stage='R0_real_input_smoke',status='completed_input_probe_not_formal_results',questions=20, reserved_GPU_seconds=4*smoke['wall_seconds'], measurement='actual_smoke_function_wall_includes_model_loading_and_video_QA; four_visible_model_parallel_GPUs; pre_function_import_overhead_not_measured')) initial=next(r for r in rows if r['stage']=='R0_formal_OVO');end=ROOT/'coordination/r0_formal.exit' if end.exists(): initial.update(status='process_exited',returncode=int(end.read_text()),end_time_unix=end.stat().st_mtime, reserved_GPU_seconds=4*(end.stat().st_mtime-initial['start_time_unix']), measurement='actual_process_create_time_to_exit_receipt_mtime; wall_GPU_reservation_not_kernel_time') initial.pop('reserved_gpu_seconds_as_of_now',None) else: initial.update(reserved_gpu_seconds_as_of_now=4*(time.time()-initial['start_time_unix']),status='live') events=[];log=ROOT/'logs/r0_queue.log' if log.exists(): for line in log.open(): if line.startswith('{'): try:events.append(json.loads(line)) except json.JSONDecodeError:pass for stage,end_stage in [('R0_ovobench','R0_OVO_full_coverage'),('R0_streamingbench','R0_all_core_questions_answered')]: starts=[r for r in events if r['stage']==stage];ends=[r for r in events if r['stage'] in (end_stage,'requires_infrastructure_repair')] for start in starts: name=stage+'_queue_pid_'+str(start['torchrun_pid']) item=next((r for r in rows if r['stage']==name),None) if item is None:item=dict(stage=name);rows.append(item) finish=next((r for r in ends if r['updated_at']>=start['updated_at']),None) item.update(start_time_unix=start['updated_at'],torchrun_pid=start['torchrun_pid'],authorized_GPUs=[0,1,2,3], measurement='queue_Popen_log_timestamp_to_post_coverage_check_timestamp; small_parent_bookkeeping_overhead_included') if finish: item.update(end_time_unix=finish['updated_at'],reserved_GPU_seconds=4*(finish['updated_at']-start['updated_at']), status='process_exited_and_coverage_checked' if finish['stage']==end_stage else 'failed_attempt',end_event=finish) else:item.update(status='live_or_interrupted_requires_process_audit',reserved_gpu_seconds_as_of_now=4*(time.time()-start['updated_at'])) atomic(path,rows) print(json.dumps(dict(stages=len(rows),unfinished=[r['stage'] for r in rows if r['status'].startswith('live')]))) if __name__=='__main__':main()