关于postgresql:postgresql-profiling

14次阅读

共计 1804 个字符,预计需要花费 5 分钟才能阅读完成。

场景

剖析 postgresql BE 的性能数据,适应于应用 GCC 编译的场景。

办法

. 编译

关上 profiling 选项

./configure --enable-profiling

. 执行

$ psql
postgres=# create table t1(id int);
postgres=# insert into t1 values(1);
postgres=# insert into t1 values(2);
postgres=# \q

psql 退出后,其对应的 BE 也随之退出。BE 退出后产生相应的 gmon.out 文件,默认在数据目录的 gprof/$PID 目录下

data/dn6/gprof/26516/gmon.out

. 转换

将 gmon.out 转换成可读的格局

gprof ./install/bin/postgres ./data/dn6/gprof/26516/gmon.out > gp.out

格局阐明

. 第一局部

各个函数的耗时排名。

column 意义
% time 本函数耗时所占的比例
self seconds 本函数本身的耗时,循环,零碎调用,零碎库函数调用 (如 memset) 等。留神,不蕴含其调用的子函数的耗时。
Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
 32.34      2.61     2.61    75262     0.00     0.00  handle_sync
 11.15      3.51     0.90   109412     0.00     0.00  base_yyparse
  4.71      3.89     0.38  2083921     0.00     0.00  SearchCatCacheInternal
  4.58      4.26     0.37  2940109     0.00     0.00  core_yylex
  4.21      4.60     0.34 13442073     0.00     0.00  AllocSetAlloc
  2.73      4.82     0.22  1627890     0.00     0.00  hash_search_with_hash_value
  2.60      5.03     0.21  4517373     0.00     0.00  MemoryContextAllocZeroAligned
  1.24      5.13     0.10  1297178     0.00     0.00  hash_bytes

. 第二局部

各个函数的堆栈状况,依照函数耗时排名排列。这里的函数耗时,与第一局部不同,是蕴含其子函数的耗时的。

column 意义
index 排名(蕴含子函数的耗时)
% time 本函数耗时所占的比例
self 同第一局部中的 ’self seconds’。本函数本身的耗时。
children 其调用的子函数的耗时。
called 被调用的次数。

上面例子,为 hgds_handle_sync 的信息。上面是其子函数信息,依照耗时排序。下面是其 caller 的信息。

index % time    self  children    called     name
-----------------------------------------------
                2.61    0.46   75262/75262       PostgresMain [6]
[8]     38.0    2.61    0.46   75262         handle_sync [8]
                0.01    0.33   71509/307849      dist_extended_msg [15]
                0.00    0.06   71509/71509       handle_result [81]
                0.05    0.00   75262/82932       IsTransactionBlock [90]
                0.01    0.00   75262/75262       dlist_is_empty [206]
                0.00    0.00   75262/1496363     errstart [106]
                0.00    0.00    3836/7670        cl_bind_dist_info [526]
-----------------------------------------------

. 第三局部

函数 index 信息。

Index by function name

 [1385] AbortBufferIO        [121] SearchSysCache1         [8] handle_sync
 [726] AbortOutOfAnyTransaction [1010] SearchSysCache2  [1039] hash_combine64

总结

通过 profiling 信息,能够剖析哪些函数奉献了更多的耗时,以便针对性的优化。也能够针对两个版本的数据进行比照,查找新增的性能杀手,进行优化。

参考资料

pgbuild

正文完
 0