[root@localhost test]# cat multiply.c
/**
* FileName: multiply.c
* sh# gcc multiply.c -g -o multiply
*/
#include <stdio.h>
int fast_multiply(x, y)
{
return x * y;
}
int slow_multiply(x, y)
{
int i, j, z;
for (i = 0, z = 0; i < x; i++)
z = z + y;
return z;
}
int main(int argc, char *argv[])
{
int i,j;
int x,y;
for (i = 0; i < 200; i ++) {
for (j = 0; j < 30 ; j++) {
x = fast_multiply(i, j);
y = slow_multiply(i, j);
}
}
printf("x=%d, y=%d\n", x, y);
return 0;
}
[root@localhost test]# gcc multiply.c -g -o multiply
[root@localhost test]# opcontrol --init
[root@localhost test]# opcontrol --vmlinux=/usr/src/linux-2.6.37.2/vmlinux
[root@localhost test]# opcontrol --reset
[root@localhost test]# opcontrol --start
Using default event: CPU_CLK_UNHALTED:100000:0:1:1
Using 2.6+ OProfile kernel interface.
Reading module info.
Using log file /var/lib/oprofile/samples/oprofiled.log
Daemon started.
Profiler running.
[root@localhost test]# ./multiply
x=5771, y=5771
[root@localhost test]# opcontrol --dump
[root@localhost test]# opcontrol --stop
Stopping profiling.
[root@localhost test]# opcontrol --shutdown
Killing daemon.
[root@localhost test]# opcontrol --deinit
Unloading oprofile module
[root@localhost test]# opannotate --source ./multiply
/*
* Command line: opannotate --source ./multiply
*
* Interpretation of command line:
* Output annotated source file with samples
* Output all files
*
* CPU: Intel Architectural Perfmon, speed 1867 MHz (estimated)
* Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
*/
/*
* Total samples for file : "/home/lenky/test/multiply.c"
*
* 39 100.000
*/
:#include <stdio.h>
:
:int fast_multiply(x, y)
:{
: return x * y;
:}
:int slow_multiply(x, y)
:{ /* slow_multiply total: 36 92.3077 */
: int i, j, z;
27 69.2308 : for (i = 0, z = 0; i < x; i++)
8 20.5128 : z = z + y;
1 2.5641 : return z;
:}
:int main()
:{ /* main total: 3 7.6923 */
: int i,j;
: int x,y;
: for (i = 0; i < 200; i ++) {
2 5.1282 : for (j = 0; j < 30 ; j++) {
1 2.5641 : x = fast_multiply(i, j);
: y = slow_multiply(i, j);
: }
: }
: printf("x=%d, y=%d\n", x, y);
: return 0;
:}
:
[root@localhost test]# opreport -l ./multiply
CPU: Intel Architectural Perfmon, speed 1867 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
samples % symbol name
36 92.3077 slow_multiply
3 7.6923 main
[root@localhost test]# opreport
CPU: Intel Architectural Perfmon, speed 1867 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
CPU_CLK_UNHALT...|
samples| %|
------------------
438541 99.4447 vmlinux
921 0.2088 oprofiled
630 0.1429 libc-2.5.so
355 0.0805 bash
342 0.0776 oprofile
55 0.0125 ld-2.5.so
39 0.0088 multiply
21 0.0048 igb
16 0.0036 ixgbe
12 0.0027 libpthread-2.5.so
9 0.0020 irqbalance
7 0.0016 gawk
7 0.0016 libglib-2.0.so.0.1200.3
7 0.0016 libpython2.4.so.1.0
6 0.0014 sshd
4 9.1e-04 libcrypto.so.0.9.8e
3 6.8e-04 grep
3 6.8e-04 libusb-0.1.so.4.4.4
2 4.5e-04 ls
2 4.5e-04 sendmail.sendmail
1 2.3e-04 cat
1 2.3e-04 libdbus-1.so.3.4.0
1 2.3e-04 libgthread-2.0.so.0.1200.3
1 2.3e-04 libselinux.so.1
1 2.3e-04 init
1 2.3e-04 libpopt.so.0.0.0
1 2.3e-04 _gobject.so
1 2.3e-04 nmbd
[root@localhost test]#