You have your own VM to use throughout this course for your assignments. Specific instructions for accessing your VM are here and will also be given out during the lab period. You can access the console of your VM from any web browser at any time. You can also use NoMachine, ssh, or putty to remotely login to your VM. For many of the assignments and labs, remotely logging into your VM is all that is required.
Because you are the only one using your VM, you may reboot it if it hangs or crashes. You will be writing systems and networking software, so it is not unusual to cause the machine to hang or stop responding. In addition to showing you how to login to/access your VM, we will also show you how to reboot your VM should it encounter problems.
A nice overview of the features and command line options available in gprof can be found at http://web.eecs.umich.edu/~sugih/pointers/gprof_quick.html.
Your goal in this exercise is to use the gcc, gprof, and valgrind programs to analyze the performance of the program below. You should follow the steps below and should save your session in a file called mysession.txt. You should then upload your mysession.txt file to the CS Portal: https://www.cs.uky.edu/csportal.
The set of steps you need to perform are:
* YOU MUST PERFORM THIS EXERCISE ON YOUR VM. * * A. Record your session. * 1. Use the script command: script mysession.txt. While it is running, you should never look * at mysession.txt, because that observation is also put into the file, * leading to an unbounded file. If you accidentally exit from the script * program, you can restart it in append mode: script -a mysession.txt * * B. Read through the test program to see what it is doing. * 1. Use one of less, vim, emacs, gedit, or some other program * to display the program. * * C. Compile with varying levels of optimizations and time the runtime * 1. Compile with no optimizations using the -O0 option (gcc -Wall -O0 -o test test.c) * 2. Run and time the program (time ./test 1000) * 3. Compile with max optimizations using the -O3 option (gcc -Wall -O3 -o test test.c) * 4. Run and time the program (time ./test 1000) * 5. Say which is faster (echo "The FILL_IN_THE_BLANK was faster. It took FILL_IN_THE_BLANK time.") * The echo program simply outputs what you tell it, but that output also * appears in mysession.txt. * * D. Profile both versions of the program using gprof. * (Do the following steps twice: first with a test program * with no optimizations (-O0), and then with a test program * with max optimizations (-O3). * Steps to use gprof: * 1. compile with profiling and debugging options (-p and -g) * and with the appropriate optimization. For * example, with no optimization it would be gcc -Wall -p -g -O0 -o test test.c * 2. run the program (./test 1000) * 3. print a "flat profile" (gprof -p -b ./test) * 4. print a "call stack profile" (gprof -q -b ./test) * * (Remember to repeat the above steps using max optimizations) * * E. Now profile both versions of the program using valgrind. * (Do the following steps twice: first with a test program * with no optimizations (-O0), and then with a test program * with max optimizations (-O3). * Steps to use valgrind/kcachegrind: * 1. run valgrind to create a callgrind.out profile file * (valgrind --tool=callgrind ./test 1000) * This step will take about a minute. * 2. run kcachegrind to view the profile (kcachegrind) * This command builds a new window and does not produce output in your mysession.txt file. * * F. Stop recording your session. * 1. Type exit. This command causes script to terminate. * * G. Now open a web browser on your VM and upload mysession.txt to https://www.cs.uky.edu/csportal. */