prompt> gcc -Wall -pg ProfileThis.c -o ProfileThis prompt> ProfileThis 41 LinearFibonacci(41) = 9227465 QuadraticFibonacci(41) = 9227465 ExponentialFibonacci(41) = 9227465 prompt> gprof -b ProfileThis Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls ms/call ms/call name 94.89 0.82 0.82 1 816.09 816.09 ExponentialFibonacci 3.51 0.85 0.03 1 30.23 30.23 QuadraticFibonacci 2.34 0.87 0.02 main 0.00 0.87 0.00 1 0.00 0.00 LinearFibonacci Call graph granularity: each sample hit covers 2 byte(s) for 1.15% of 0.87 seconds index % time self children called name[1] 100.0 0.02 0.85 main [1] 0.82 0.00 1/1 ExponentialFibonacci [2] 0.03 0.00 1/1 QuadraticFibonacci [3] 0.00 0.00 1/1 LinearFibonacci [4] ----------------------------------------------- 331160280 ExponentialFibonacci [2] 0.82 0.00 1/1 main [1] [2] 94.2 0.82 0.00 1+331160280 ExponentialFibonacci [2] 331160280 ExponentialFibonacci [2] ----------------------------------------------- 0.03 0.00 1/1 main [1] [3] 3.5 0.03 0.00 1 QuadraticFibonacci [3] ----------------------------------------------- 0.00 0.00 1/1 main [1] [4] 0.0 0.00 0.00 1 LinearFibonacci [4] ----------------------------------------------- Index by function name [2] ExponentialFibonacci [3] QuadraticFibonacci [4] LinearFibonacci [1] main
gdb ProfileThis ... (gdb) break LinearFibonacci Breakpoint 1 at 0x11a9: file ProfileThis.c, line 12. (gdb) run 35 Starting program: /fs/bragg/home/graph/geoff/CSC322/MyCode.CTools/ProfileThis 35 Breakpoint 1, LinearFibonacci (Number=21845) at ProfileThis.c:12 12 long LinearFibonacci(int Number) { (gdb) print Number $1 = 21845 (gdb) step 14 long Previous = 0; (gdb) print Number $2 = 35 (gdb) c Continuing. LinearFibonacci(35) = 5702887 QuadraticFibonacci(35) = 93824992254624 ExponentialFibonacci(35) = 5702887 [Inferior 1 (process 2320434) exited normally] (gdb) quit
gcc -g -O0 -Wall -o ProfileThis ProfileThis.c valgrind --leak-check=yes ProfileThis 41 ==7930== Memcheck, a memory error detector ==7930== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al. ==7930== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info ==7930== Command: ProfileThis 41 ==7930== LinearFibonacci(41) = 102334155 QuadraticFibonacci(41) = 102334155 ExponentialFibonacci(41) = 102334155 ==7930== ==7930== HEAP SUMMARY: ==7930== in use at exit: 16 bytes in 1 blocks ==7930== total heap usage: 41 allocs, 40 frees, 656 bytes allocated ==7930== ==7930== 16 bytes in 1 blocks are definitely lost in loss record 1 of 1 ==7930== at 0x4C29F73: malloc (vg_replace_malloc.c:309) ==7930== by 0x4006F4: QuadraticFibonacci (ProfileThis.c:50) ==7930== by 0x400805: main (ProfileThis.c:79) ==7930== ==7930== LEAK SUMMARY: ==7930== definitely lost: 16 bytes in 1 blocks ==7930== indirectly lost: 0 bytes in 0 blocks ==7930== possibly lost: 0 bytes in 0 blocks ==7930== still reachable: 0 bytes in 0 blocks ==7930== suppressed: 0 bytes in 0 blocks ==7930== ==7930== For lists of detected and suppressed errors, rerun with: -s ==7930== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)