카테고리 없음
                
              java 어플리케이션의 RSS(실제 물리) 메모리 사용량 확인용 스크립트
                달사자!
                 2023. 6. 8. 13:31
              
                          
            트러블슈팅할때 가끔 RSS메모리를 주기적으로 관찰해야할 필요가 있습니다.
커맨드 등등으로 했었는데 아래 bash쉘로도 가능합니다.
- 참고: https://poonamparhar.github.io/dynamic_compiler_threads/
#!/bin/bash
pid=$1
smaps_file=/proc/$pid/smaps
output_file=rss_$pid.out
rm rss_$pid.out
echo 'Monitoring RSS of the Process' $pid. Saving output to file $output_file.
while true
do
  # Get the current timestamp
  timestamp=$(date +"%FT%T%z")
  # Get the current RSS value
  rss=$(grep -m 1 "^Rss:" "$smaps_file" | awk '{print $2}')
  # write timestamp and rss to the output file
  echo "$timestamp: $rss" >> "$output_file"
  sleep 5
done
위 스크립트 생성 후 ps -ef | grep java 로 PID 확인해서 스크립트 아큐먼트로 PID를 입력해서 사용하면 파일로 저장됩니다.
P.S. 링크 글 자체의 퀄리티도 꽤 높습니다. 이런 글 볼때마다 커널이나 OS 공부, C공부를 다시 깊게 해보고 싶다는 생각이 드는군요.