valgrind를 이용한 메모리 체크

valgrind는  프로그램 설능을 프로파일링 후 메모리 할당 / 초기화 되지 않은 메모리 영역 을 검색할 수 있는데, Redhat 문서를 참고하며 다음과 같은 리포트를 받을 수 있다고 합니다.

memcheck로 실행되는 어플리케이션은  메모리 사용량 을 확인해야 하기 때문에 일반적으로 실행하는것보다 10~30배 가량 느리게 실행된다고 합니다.

메모리 누수 프로파일링

  1. 패키지 설치
    $> yum install valgrind -y
  2. valgrind를 이용한 메모리 누수 여부 체크
    /usr/bin/test라는 임의 프로그램을 실행하되 하위 라이브러리들도 같이 실행하도록 합니다.
    $ valgrind --tool=memcheck --leak-check=summary --trace-children=yes /usr/bin/test
    ...
    ==21297== Memcheck, a memory error detector
    ==21297== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
    ==21297== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
    ==21297== Command: /usr/sbin/test
    ==21297==
    ERROR: Please define server type (local and/or TCP).
    ==21298==
    ==21298== HEAP SUMMARY:
    ==21298== in use at exit: 101,185 bytes in 3,410 blocks
    ==21298== total heap usage: 5,613 allocs, 2,203 frees, 286,292 bytes allocated
    ==21298==
    ==21298== LEAK SUMMARY:
    ==21298== definitely lost: 0 bytes in 0 blocks
    ==21298== indirectly lost: 0 bytes in 0 blocks
    ==21298== possibly lost: 0 bytes in 0 blocks
    ==21298== still reachable: 101,185 bytes in 3,410 blocks
    ==21298== suppressed: 0 bytes in 0 blocks
    ==21298== Rerun with --leak-check=full to see details of leaked memory
    ==21298==
    ==21298== For lists of detected and suppressed errors, rerun with: -s
    ==21298== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
    • leak 옵션은 summary(기본값) / full 둘중하나 선택 가능한듯 하고, full로 실행하게 되면 summary보다는 좀 더 자세한 정보가 보이네요

캐시 사용량 프로파일링

  1. 캐시 사용량은 다음 기능을 하고 있다 합니다.
    • 첫번째 레벨 지시 캐시 읽기 / 읽기 미스 /
    • 데이터 캐시 읽기 (메모리 읽기), 읽기 미스,
    • 데이터 캐시 쓰기 (메모리 쓰기), 쓰기 미스
    • 실행 및 잘못 예측된 조건 분기
    • 실행 및 잘못 예측된 간접 분기
    • 패키지 설치
      $ yum install valgrind -y
  1. cache 내용 확인* IL / D / 정보

    • I캐시 읽기 (Ir, 실행된 명령어 수), I1, 캐시 읽기 미스 (I1mr), LL캐시 명령어 읽기 미스 (ILmr)
    • D캐시 읽기 (Dr, 메모리 읽기 수), D1 캐시 읽기 미스 (D1mr), LL 캐시 데이터 읽기 미스 (DLmr)
    • D캐시 쓰기 (Dw, 메모리 쓰기 수), D1 캐시 쓰기 누락 (D1mw), LL 캐시 데이터 쓰기 누락 (Dlmw)
    • 전체 프로그램에 대한 요약 통계
      ——————————————————————————–
      Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw
      ——————————————————————————–
      6,122,264 3,538 2,481 1,725,087 79,539 16,924 655,284 10,140 8,215 PROGRAM TOTALS

    • 기능별 통계
      ——————————————————————————–
      Ir I1mr ILmr Dr D1mr DLmr Dw D1mw DLmw file:function
      ——————————————————————————–
      2,074,204 48 14 699,500 46,437 1,226 284,276 70 12 ???:do_lookup_x


reference

 


Revision #1
Created 7 June 2022 15:12:23 by artop0420
Updated 24 December 2023 00:51:54 by artop0420