YoungjaeDev Claude commited on
Commit
f50f28a
·
1 Parent(s): 169758c

feat(profiling): Gradio 데모 파이프라인 성능 프로파일링 구현 (Issue #80)

Browse files

- gradio_profiler.py: 단계별 성능 측정 스크립트 신규 작성
- 비디오 읽기, 파이프라인 처리, 시각화, 인코딩 단계별 측정
- GPU/CPU 메모리 사용량 모니터링
- JSON 형식 결과 저장

- app.py: 프로파일링 포인트 추가
- video_read: cv2.VideoCapture.read() 측정
- video_write: cv2.VideoWriter.write() 측정
- ffmpeg_encode: H.264 재인코딩 측정

- PROFILING_REPORT.md: 벤치마크 분석 보고서
- 주요 병목: FFmpeg H.264 인코딩 (87.7%)
- GPU 사용률 6.6% (배치 처리로 개선 가능)
- 최적화 목표: 전체 처리 시간 4배 단축 (21초 -> 5초)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +17 -12
app.py CHANGED
@@ -391,7 +391,9 @@ def process_video(
391
  max_confidence = 0.0
392
 
393
  while True:
394
- ret, frame = cap.read()
 
 
395
  if not ret:
396
  break
397
 
@@ -408,8 +410,9 @@ def process_video(
408
  if info['alert']:
409
  fall_detected = True
410
 
411
- # 출력 저장
412
- out.write(vis_frame)
 
413
 
414
  frame_idx += 1
415
 
@@ -428,15 +431,17 @@ def process_video(
428
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
429
  output_h264 = tmp.name
430
  # 보안: subprocess.run 사용 (shell injection 방지)
431
- subprocess.run(
432
- [
433
- 'ffmpeg', '-y', '-i', output_path,
434
- '-c:v', 'libx264', '-preset', 'fast', '-crf', '23',
435
- output_h264, '-loglevel', 'quiet'
436
- ],
437
- check=False,
438
- capture_output=True
439
- )
 
 
440
 
441
  # mp4v 임시 파일 삭제
442
  if os.path.exists(output_path):
 
391
  max_confidence = 0.0
392
 
393
  while True:
394
+ # 프레임 읽기 (프로파일링)
395
+ with pipeline.profiler.profile('video_read'):
396
+ ret, frame = cap.read()
397
  if not ret:
398
  break
399
 
 
410
  if info['alert']:
411
  fall_detected = True
412
 
413
+ # 출력 저장 (프로파일링)
414
+ with pipeline.profiler.profile('video_write'):
415
+ out.write(vis_frame)
416
 
417
  frame_idx += 1
418
 
 
431
  with tempfile.NamedTemporaryFile(suffix=".mp4", delete=False) as tmp:
432
  output_h264 = tmp.name
433
  # 보안: subprocess.run 사용 (shell injection 방지)
434
+ # FFmpeg 인코딩 프로파일링
435
+ with pipeline.profiler.profile('ffmpeg_encode'):
436
+ subprocess.run(
437
+ [
438
+ 'ffmpeg', '-y', '-i', output_path,
439
+ '-c:v', 'libx264', '-preset', 'fast', '-crf', '23',
440
+ output_h264, '-loglevel', 'quiet'
441
+ ],
442
+ check=False,
443
+ capture_output=True
444
+ )
445
 
446
  # mp4v 임시 파일 삭제
447
  if os.path.exists(output_path):