现在的位置: 首页 > 综合 > 正文

Nginx 的函数调用关系图 Call Graph

2013年01月01日 ⁄ 综合 ⁄ 共 1291字 ⁄ 字号 评论关闭

话说nginx是用纯c打造的, 代码里面指针满天飞, 想要理解其代码的执行流程着实不易, 单凭肉眼+source insight等工具, 是无法理解其执行轨迹的. 这给想读懂nginx代码制造了不少麻烦.

昨晚用graphviz画了一个nginx的函数调用关系图. 可以帮助理解nginx的代码. 分享给大家. 

nginx代码版本:
     1.0.2

总共T除了如下函数的调用:

 ngx_array_push|ngx_palloc|ngx_strlow|ngx_pnalloc|ngx_pcalloc|ngx_sprintf_num|ngx_array_init|ngx_conf_read_token|ngx_hash_strlow|ngx_hash_key|ngx_hash_add_key|ngx_hash_key_lc|ngx_http_core_type|ngx_http_merge_locations|ngx_cpystrn|ngx_alloc|ngx_strncasecmp|ngx_array_create|ngx_http_merge_servers|ngx_vslprintf|ngx_array_push_n|ngx_hash_init|ngx_sprintf|ngx_conf_handler|ngx_http_add_variable|ngx_conf_merge_path_value|ngx_conf_test_full_name|ngx_conf_full_name|ngx_strcasecmp|ngx_http_upstream_hide_headers_hash|ngx_http_get_indexed_variable|ngx_http_merge_types|ngx_http_log_copy_short|ngx_conf_parse|ngx_memalign|ngx_atoi|ngx_time_update|ngx_strstrn|ngx_list_push|ngx_http_script_variables_count

由于原始数据的函数太多, 会导致生成的图太大, 所以这里剔除了一些不重要的函数的调用.

该图完整的记录了单进程模式的nginx从启动, 到收到 http://127.0.0.1 请求并处理, 再到退出的完整流程.

图比较大, 可以下载到本地看.
http://pan.baidu.com/share/link?shareid=187209&uk=3959729623

完整的.dot文件 以及 裁剪后的.dot文件也可下载:
http://pan.baidu.com/share/link?shareid=188189&uk=3959729623

具体的图形的制作方法参考:
 利用graphviz以及gcc finstrument-functions特性打印进程的动态运行的函数调用关系图
 http://blog.csdn.net/zdl1016/article/details/8498140

制作的过程中也遇到了不少的问题, 以后有时间了再把制作过程附上. 

抱歉!评论已关闭.