Thursday 29 March 2018

SPO 600 - Phase 2 - G Profiling

Phase 2 for the project will be pretty long so I decided to break down evenly in multiple stages. This stage is about G Profiling. What is Profiling? Profiling is he process of determining how a program is using the resources that it is consuming. Profiling produces a clear view of the call graph -- the hierarchy of function/procedure/method calls that takes place during the execution of the program.

Resources consumption that can be analyzed during profiling include:

    Time (both clock time (total real time, user time, and the amount of time the   kernel spent on behalf of the program)
    Memory
    Temporary storage
    Energy (this is a relatively new area of profiling)

 There are several profiling tools available. Open Source options include

    gprof
    perf
    oprofile
    SystemTap
These  tools provide different combinations of profiling capabilities, and may provide additional functions. But here we will be deeply exploring gprof like how we will be using gprof in Aarch64 system with md5deep? and how it could be helpful for bench-marking and optimization?

So our first step would be build the software to be profiled using -pg(profile generation) option to enable profiling during compilation or execution of our md5deep command.In order to do the previous step first we need to modify the makefile or other build instructions, but it can often be done using CFLAGS or CCOPTS variable. We have 2 ways of modifying the make file for enabling profiling by addding -pg option. 

(1) Manually change each and every make file in the folder where it is located after extraction. There can be multiple make files 
find . -name "Makefile" -> Enter this command in that folder to locate all the Makefiles. For me there were 6 Makefiles I had to modify each one of it which was stressful NOTE: Depending on what version of md5deep you have installed makefiles vary from version to version. These are my makefiles

./doc/Makefile
./man/Makefile
./src/Makefile
./tests/testfiles/Makefile
./tests/Makefile
./Makefile


At the end of each Makefile you will see something similar to this  

world:
        @echo meta-build system.
        @echo Making both Linux and Windows distributions
        make distclean
        ./configure CFLAGS="-Wall -W -g -ggdb -O0"
        make dist
        make windist
I have purposely highlighted the configure line change it to

./configure CFLAGS="-Wall -W -g -pg -ggdb -O2"  I added -pg option and changed O2 from O0 for optimization purposes.

(2) Easiest step would be to modify all make files at one shot by entering following command
./configure CFLAGS="-pg -g -O2" CXXFLAGS="-pg -g -O2"
And after this command unluckily I bumped into an error saying configure: error: cannot guess build type; you must specify one it failed and ended unexpectedly. Luckily error wasn't that hard to solve. Basically I did some research on it, I found out that this error is related to demanding an update ./configure is not able to recognize aarch64 anymore cause I am trying to change the makefiles. It is kind of strange cause at first time when I ran ./configure for installation it didn't gave me an error. I think running ./configure must have recognized aarch64 version but by adding some parameters to it must have compromised aarch64 version as per my thinking. 

NOTE: THE EXPLANATION ABOUT THE ./configure ERROR ABOVE IS JUST MY ASSUMPTION THERE COULD BE SOME OTHER REASON FOR THE ERROR TOO I RESEARCHED IT AND FOUND SOME RELEVANT REASONING ABOUT THE SAME SITUATION.

So I found a link to download some config files in error itself   

ftp://ftp.gnu.org/pub/gnu/config/           

While you are on this webpage click on README file there will be 2 links open both the links copy one by one 
 http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
 http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
 

and make a new config file named config.guess and config.sub. As you can see at the end of url the name of the files are given. SCP or SFTP those files to your md5deep folder and run the same command and it worked this time. After executing that command run 

make clean
make

When you look at the output of ./configure and makefile we can see there will be -pg -g -O2 added to g++. It should create file called gmon.out as well

gprof md5deep>123.txt

It will create a readable file where profiling info would be there by viewing my profiling info its confusing cause many functions are getting multiple calls still time taken for it is 0 seconds. Here at the bottom I have shown it

granularity: each sample hit covers 4 byte(s) no time propagated

index % time    self  children    called     name
                0.00    0.00       2/505         MD5Final [4]
                0.00    0.00     503/505         MD5Update [2]
[1]      0.0    0.00    0.00     505         MD5Transform [1]
-----------------------------------------------
                0.00    0.00       4/4           hash_context_obj::multihash_update(unsigned char const*, unsigned int) [48]
[2]      0.0    0.00    0.00       4         MD5Update [2]
                0.00    0.00     503/505       


The file is pretty big and functions are getting calls from several other functions so I ended up with a function 

multihash_update(unsigned char const*, unsigned int)

I think it is not possible to modify it anyhow cause its written perfectly still my next approach would be to try with different compiler flag it might get affected in terms of performance.

No comments:

Post a Comment