# 2016q3 Homework1 (raytracing) ## Gnu gprof學習 ### 練習用phonebook_hash實作分析 ``` Flat profile: Each sample counts as 0.01 seconds. % cumulative self self total time seconds seconds calls ms/call ms/call name 62.72 0.05 0.05 main 25.09 0.07 0.02 1 20.07 20.07 free_hash_table 12.54 0.08 0.01 349903 0.00 0.00 hash2 0.00 0.08 0.00 349900 0.00 0.00 append 0.00 0.08 0.00 3 0.00 0.00 findName 0.00 0.08 0.00 2 0.00 0.00 diff_in_second 0.00 0.08 0.00 1 0.00 0.00 creatHashTable ^L Call graph granularity: each sample hit covers 2 byte(s) for 12.46% of 0.08 seconds index % time self children called name <spontaneous> [1] 100.0 0.05 0.03 main [1] 0.02 0.00 1/1 free_hash_table [2] 0.00 0.01 349900/349900 append [4] 0.00 0.00 3/3 findName [5] 0.00 0.00 2/2 diff_in_second [6] 0.00 0.00 1/1 creatHashTable [7] ----------------------------------------------- 0.02 0.00 1/1 main [1] [2] 25.0 0.02 0.00 1 free_hash_table [2] ----------------------------------------------- 0.00 0.00 3/349903 findName [5] 0.01 0.00 349900/349903 append [4] [3] 12.5 0.01 0.00 349903 hash2 [3] ----------------------------------------------- 0.00 0.01 349900/349900 main [1] [4] 12.5 0.00 0.01 349900 append [4] 0.01 0.00 349900/349903 hash2 [3] ----------------------------------------------- 0.00 0.00 3/3 main [1] [5] 0.0 0.00 0.00 3 findName [5] 0.00 0.00 3/349903 hash2 [3] ----------------------------------------------- 0.00 0.00 2/2 main [1] [6] 0.0 0.00 0.00 2 diff_in_second [6] ----------------------------------------------- 0.00 0.00 1/1 main [1] [7] 0.0 0.00 0.00 1 creatHashTable [7] ----------------------------------------------- ``` 可以看出來function call集中在append跟hash, 字典檔為349900,hash次數 = append + findName次數 # 參考資料 [A02: raytracing](https://hackmd.io/s/B1W5AWza) [使用Gnu gprof进行Linux平台下的程序分析(1)](http://os.51cto.com/art/200703/41426.htm) [GNU gprof](https://sourceware.org/binutils/docs/gprof/)