Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
Project 5: Profiling an Assembly Program
Goal
Task 0: Download the initial sources and start tsearch_asm6.s
To start your project clone the project5 repository:
git clone /homes/cs250/sourcecontrol/work/$USER/project5-src.git
cd project5-src
|
The implementation of binary tree search in C is similar to the one from project4. You will copy your implementation from tsearch_asm5.s into tsearch_asm6.s
To test the implementation type
data 149 $ ./run_bench.sh
================== Running TreeSearch Iterative in C benchmark ================
Total CPU time: 4.125084397 seconds
real 0m7.960s
user 0m7.830s
sys
0m0.124s
================== Running ASM 6 benchmark ================
…
|
It will also try to run the tsearch_asm6.s but it will fail if it is not implemented yet.
Task 1:Insert profiling code in the benchmark
void start_histogram();
void print_histogram();
|
Open the file tsearch_bench_better.c and find the main(). Then above main, you will insert the external prototypes of start_histogram() and print_histogram(): as follows. Also call start_histogram() at the beginning of main() and print_histogram() at the end.
extern void start_histogram();
extern void print_histogram();
/*
* Main program function. Runs the benchmark.
*/
__attribute__ (( visibility("default") ))
int
main(int argc, char **argv)
start_histogram();
…..
print_histogram();
}
|
Modify run_bench, so both gcc compilation commands link profil.c
echo ================== Running TreeSearch Iterative in C benchmark ================
gcc -g -static -o tsearch_bench_iterative_c tsearch_bench_better.c tsearch.c AVLTree.c tsearch_iterative.c profil.c || exit 1
…
gcc -g -static -o tsearch_bench_asm6 tsearch_bench_better.c tsearch.c AVLTree.c tsearch_asm6.s profil.c || exit 1
… |
Now type run_bench.
Open this file, and you will observe that it contains the program counters in the histogram that are larger than 0. The counter is multiplied by 1ms, so the counters are displayed in ms. Identify the program counter where the program is spent most of its time:
Then run the command "nm -v tsearch_bench_iterative_c | less"that prints all the functions in the program sorted by address, and finds the function that includes this program counter. Use the up/down arrow keys to navigate "less".
Now to find the assembly instruction type "objdump -d tsearch_bench_iterative_c | less" that prints the assembly instructions that make the program and their address in the program. Find the assembly instruction that includes the counter 45b870, that is 45b86c . This is because 0x45b870 is larger than 45b86c but smaller than 45b873.
The program will open prog.hist, and store the entries in an array of structs with the program counter and the time in ms. Then it will call system("nm -v prog > nm.out") using the system() function (see man system) that executes a command inside a C program, and redirect it into a file nm.out. Myprof will read nm.out, and it will also store the entries in an array of structs with program counters and function names. Then for every pc in the histogram, it will increment the time in ms of the corresponding function. After this is done, it will sort the functions by time, andidentify the 10 top functions where the execution spends most of the time. Finally, it will also print the assembly code of these functions using objdump, and print the time spend in each assembly instruction. Only the instructions with a time greater than 0 are printed.