메뉴 닫기

CPU 프로파일링.

CPU 프로파일링.

Oprofile

• 실행중인 프로세스의 CPU Usage를 프로파일링
• 실행중인 프로세스의 어떤 함수가 CPU 자원을 많이 사용하는지를 식별
• 특정 함수가 많은 자원을 사용할 경우, 프로그램은 그 함수 콜을 줄일 수 있는 방법으로 재설계될 수 있음
• 이느 CPU 사용률이 낮은 장비에서는 별로 쓸모가 없음

참고) ubuntu에서는 vmlinux 파일이 /boot에 존재하지 않기에 아래와 같이 만들어서 진행할 수 있다.

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package
sudo apt-get build-dep –no-install-recommends linux-image-$(uname -r)
mkdir ~/src
cd ~/src
apt-get source linux-image-$(uname -r)
cd linux-*/
make oldconfig
make vmlinux
sudo opcontrol –vmlinux=vmlinux
sudo opcontrol –start

——————————- install ———————————————-

Source installing

(* 설치 파일은 http://oprofile.sourceforge.net/news/ 에서 다운로드 가능.)

# wget http://prdownloads.sourceforge.net/oprofile/oprofile-0.9.8.tar.gz
# tar xvfz oprofile-0.9.8.tar.gz
# cd oprofile-0.9.8

*참고 XenOprofile 설치시 다음을 진행

># tar -xzvf oprofile-0.9.5.tar.gz; cd oprofile-0.9.5
># wget http://xenoprof.sourceforge.net/oprofile-0.9.5-xen.patch
># patch -p1 # ./configure –with-kernel-support
configure: error: liberty library not found
># apt-get install binutils-dev

# sudo ./configure –with-kernel-support
# sudo make
# sudo make install

*참고

make 도중에 다음과 같은 에러 메시지가 나온다면,

libtool:link: gcc -shared .libs/libopagent_la-opagent.o /usr/lib/libbfd.a
-liberty -ldl -Wl,–version- script=../libopagent/opagent_symbols.ver
-Wl,-soname -Wl,libopagent.so.1 -o.libs/libopagent.so.1.0.0 /usr/lib/gcc/x86
_64-unknown-linux-gnu/4.6.4/../../../../x86_64-unknown-linux-gnu/bin/ld:
/usr/lib/libbfd.a(archures.o): relocation R_X86_64_32S against `_sch_istable’can
not be used when making a shared object; recompile with -fPIC
/usr/lib/libbfd.a:could not read symbols: Bad value

binutils를 다시 컴파일해서 설치해야 한다. 아래에서 빨간색 부분을 반드시 포함시켜서!

binutils-2.22# ./configure –prefix=/usr CFLAGS=”-fPIC”
$ make
$ sudomake install

그 후에 다시 컴파일.

apt-get Installation

># sudo apt-get install oprofile

Check for profile support in the kernel
># cat /boot/config-`uname -r` | grep PROFILE

The following command tells OProfile that we don’t have an uncompressed kernel and it assign all kernel
samples to a black-box called “no-vmlinux”. With the uncompressesd kernel,
it’s possible to get a breakdown of what is happening inside of your kernel in more detail.
># opcontrol –no-vmlinux
–no-vmlinux : indicates that we are not interested in recording samples for the kernel.

——————————- usage ———————————————-

Basic Usage
To clean previous samples
># opcontrol –reset

To configure and start OProfile
># opcontrol –setup –no-vmlinux –event=CPU_CLK_UNHALTED:6000
Measuring CPU_CLK_UNHALTED events with a sample recorded for every 6000 events.

># opcontrol –start

Run my benchmark
># ./cpu -a 15 -n 1

># opcontrol –shutdown
># opreport -lt1
-t1: sets a threshold at 1% so that we don’t see every symbol.
-l: shows you side each process

—————————————————————————————————-

bfd가 필요하다고 하면
# sudo apt-get install libbfd-dev
popt가 필요하다고 하면
# sudo apt-get install libpopt-dev
liberty가 필요하다고 하면
# sudo apt-get install binutils-dev
를 해주면 된다.
‘dl’도 필요하다는데… 난 이미 설치되어 있었음. (libgdl-dev쯤 되지 않을까?)

Uncompressed kernel image가 필요함. 이걸 얻으려면..
# sudo apt-get install linux-image-debug-`uname -r`

혹은

# sudo apt-get install linux-image-`uname -r`-dbg

# sudo opcontrol –vmlinux=/boot/vmlinux-debug-`uname -r`

시작
# sudo opcontrol –start

# sudo opcontrol –shutdown

$ opcontrol –no-vmlinux (커널 자체에 대한 프로파일을 할 필요가 없을 때 해줌) 혹은
$ opcontrol –vmlinux=/boot/vmlinux-`uname -r` (커널을 프로파일에 포함시킬 때)
$ opcontrol –reset
$ ophelp (프로파일링 가능한 사건을 알아볼 때)
$ opcontrol –event=:
(각 카운터에 사용될 사건인 event-name은 이렇게 혹은 GUI를 사용하여 설정할 수 있다.
만일 cpu_type이 timer가 아니라면, 각 사건마다 sampling rate를 설정가능, 아래처럼)
($ opcontrol –event=CPU_CLK_UNHALTED:90000)

$ opcontrol –start (혹은 -s)

./newBind (프로파일링할 프로그램 수행)

$ opcontrol –dump

$ opcontrol –shutdown (혹은 -h)

$ opreport -l -t 0.1 (0.1% 이상의 수행시간을 차지한 함수들을 나열)
$ opreport -l ./newBind
$ opannotate –source ./newBind (gcc할 때 -g 옵션 필요)

http://oprofile.sourceforge.net/doc/index.html : oprofile 매뉴얼

http://blog.naver.com/PostView.nhn?blogId=cubebridge&logNo=20066214877&redirect=Dlog&widgetTypeCall=true

http://kalstein.tistory.com/79
========================================
[vmware에서 oprofile사용]

Ubuntu라면 Synaptic Package Manager에서 oprofile을 설치함

원래 vmware에서는 oprofile을 사용할 수 없으므로 workaround로 2.4 kernel에서는
RTC mode로 2.6 kernel에서는 timer interrupt mode로 놓고 사용한다.

$ opcontrol –deinit
$ modprobe oprofile timer=1

then remove /etc/oprofile/daemonrc

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x