LoginSignup
8
9

More than 5 years have passed since last update.

Oprofileによるボトルネックの調査 メモ

Last updated at Posted at 2015-10-21

インストール

$ yum install oprofile

使い方

$ opcontrol --reset  #プロファイル結果をクリア
$ opcontrol --start  #プロファイル開始
$ opcontrol --stop   #プロファイル終了

結果の確認

$ opreport   # システム全体ののプロファイル結果
$ opreport -l /home/trae/bin/traepktd    #指定プログラムのプロファイル結果(サマリ)
$ opannotate -a /home/trae/bin/traepktd    #指定プログラムのプロファイル結果(詳細)

下記の例だと、"hl_xxxxx"がかなりのボトルネックになっている。
"hl_xxxxx"に性能改善対策がうてれば、実行速度の向上が見込める。

CPU: Intel Architectural Perfmon, speed 3466.91 MHz (estimated)
Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
samples  %        symbol name
1384167  11.0792  hl_xxxxx
755803    6.0496  tcp_mxxxxx
723457    5.7907  http_Pxxxxxxx
637085    5.0994  pkt_xxxxxxxx
566604    4.5352  pkt_xxxxxxxx
453462    3.6296  .plt
415683    3.3272  pkt_ipxxxxxxxxxx
396182    3.1711  pkt_ifxxxxxxxxxx
373027    2.9858  pkt_tcpxxxxxxxxx
364275    2.9157  ut_xxxxxxxxx
342519    2.7416  http_xxxxxxxxxxxx
315162    2.5226  ux_xxxxxxxxxxx
~

ソースの該当箇所を確認。
forループの中のmemcmpをどうにかすればよさげなのが判断できる。

/* 
 * Command line: opannotate -s ./xxxxxxxx
 * 
 * Interpretation of command line:
 * Output annotated source file with samples
 * Output all files
 * 
 * CPU: Intel Architectural Perfmon, speed 3466.91 MHz (estimated)
 * Counted CPU_CLK_UNHALTED events (Clock cycles when not halted) with a unit mask of 0x00 (No unit mask) count 100000
 */
/* 
 * Total samples for file : "/home/xxxxxxxx.c"
 * 
 * 910908 16.8646
 */

               :uint64_t hl_xxxxx(hl_t *hl, void *key)

 64052  1.1859 :    for (ridx = __hl_bkt(hl)[hl_hash(key, db->klen, 1981) % db->bnum];
 87402  1.6182 :        ridx > 0;
     2 3.7e-05 :        ridx = *__hl_rec_syn(hl, ridx)) {

273682  5.0670 :        if (memcmp((void *)__hl_rec(hl, ridx), key, db->klen) == 0) {
               :            dprint("key matched at "REC_FMT"\n", REC_ARG(hl, ridx));

               :    }

  3205  0.0593 :}
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9