OSDN Git Service

Complete several pages
[linuxjm/LDP_man-pages.git] / draft / man1 / sprof.1
diff --git a/draft/man1/sprof.1 b/draft/man1/sprof.1
new file mode 100644 (file)
index 0000000..80b042c
--- /dev/null
@@ -0,0 +1,264 @@
+.\" Copyright (C) 2014 Michael Kerrisk <mtk.manpages@gmail.com>
+.\"
+.\" %%%LICENSE_START(VERBATIM)
+.\" Permission is granted to make and distribute verbatim copies of this
+.\" manual provided the copyright notice and this permission notice are
+.\" preserved on all copies.
+.\"
+.\" Permission is granted to copy and distribute modified versions of this
+.\" manual under the conditions for verbatim copying, provided that the
+.\" entire resulting derived work is distributed under the terms of a
+.\" permission notice identical to this one.
+.\"
+.\" Since the Linux kernel and libraries are constantly changing, this
+.\" manual page may be incorrect or out-of-date.  The author(s) assume no
+.\" responsibility for errors or omissions, or for damages resulting from
+.\" the use of the information contained herein.  The author(s) may not
+.\" have taken the same level of care in the production of this manual,
+.\" which is licensed free of charge, as they might when working
+.\" professionally.
+.\"
+.\" Formatted or processed versions of this manual, if unaccompanied by
+.\" the source, must acknowledge the copyright and authors of this work.
+.\" %%%LICENSE_END
+.\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.TH SPROF 1 2014\-06\-24 Linux "Linux User Manual"
+.SH 名前
+sprof \- 共有オブジェクトのプロファイルデータを読み出して表示する
+.SH 書式
+.nf
+\fBsprof\fP [\fIoption\fP]... \fIshared\-object\-path\fP [\fIprofile\-data\-path\fP]
+.fi
+.SH 説明
+\fBsprof\fP コマンドは、 最初のコマンドライン引き数で指定された共有オブジェクトのプロファイルの概要を表示する。 2 番目のコマンドライン引き数
+(省略可能) で指定された生成済みのプロファイルデータを使って、 プロファイルの概要が生成される。 プロファイルデータのパス名が省略された場合、
+\fBsprof\fP は、 共有オブジェクトの soname を使ってパス名を元に、 カレントディレクトリに
+\fI<soname>.profile\fP という名前のファイルを探して、 プロファイルデータを特定しようとする。
+.SH オプション
+以下のコマンドラインオプションは生成されるプロファイリング出力を指定する。
+.TP 
+\fB\-c\fP, \fB\-\-call\-pairs\fP
+共有オブジェクトで公開されているインターフェースに対して呼び出し経路のペアのリストを表示する。 各経路が使用された回数も表示される。
+.TP 
+\fB\-p\fP, \fB\-\-flat\-profile\fP
+監視対象のオブジェクトの全関数の、 回数と tick が入った flat profile を生成する。
+.TP 
+\fB\-q\fP, \fB\-\-graph\fP
+コールグラフを生成する。
+.PP
+上記のオプションがどれも指定されなかった場合のデフォルトの動作は、 flat profile とコールグラフが表示される。
+.PP
+以下のコマンドラインオプションも使用できる。
+.TP 
+\fB\-?\fP, \fB\-\-help\fP
+コマンドラインオプションと引き数の概要を表示し終了する。
+.TP 
+\fB\-\-usage\fP
+使用方法の簡潔な概要を表示し終了する。
+.TP 
+\fB\-V\fP, \fB\-\-version\fP
+プログラムのバージョンを表示し終了する。
+.SH 準拠
+\fBsprof\fP コマンドは GNU 拡張であり、 POSIX.1 には存在しない。
+.SH 例
+以下は \fBsprof\fP の使用例を示したものである。 この例では、メインプログラムで共有ライブラリ内の 2 つの関数を呼び出している。 最初に、
+メインプログラムのコードは以下の通りである。
+
+.in +4n
+.nf
+$ \fBcat prog.c\fP
+#include <stdlib.h>
+
+void x1(void);
+void x2(void);
+
+int
+main(int argc, char *argv[])
+{
+    x1();
+    x2();
+    exit(EXIT_SUCCESS);
+}
+.fi
+.in
+.PP
+関数 \fIx1()\fP と \fIx2()\fP は以下のソースファイルで定義されており、 このファイルから共有ライブラリが構成される。
+
+.in +4n
+.nf
+$ \fBcat libdemo.c\fP
+#include <unistd.h>
+
+void
+consumeCpu1(int lim)
+{
+    int j;
+
+    for (j = 0; j < lim; j++)
+       getppid();
+}
+
+void
+x1(void) {
+    int j;
+
+    for (j = 0; j < 100; j++)
+       consumeCpu1(200000);
+}
+
+void
+consumeCpu2(int lim)
+{
+    int j;
+
+    for (j = 0; j < lim; j++)
+       getppid();
+}
+
+void
+x2(void)
+{
+    int j;
+
+    for (j = 0; j < 1000; j++)
+       consumeCpu2(10000);
+}
+.fi
+.in
+.PP
+ここで、 実際の名前は \fIlibdemo.so.1.0.1\fP で soname は \fIlibdemo.so.1\fP で共有ライブラリを構成する。
+
+.in +4n
+.nf
+$ \fBcc \-g \-fPIC \-shared \-Wl,\-soname,libdemo.so.1 \e\fP
+        \fB\-o libdemo.so.1.0.1 libdemo.c\fP
+.fi
+.in
+.PP
+次に、 ライブラリ soname とライブラリのリンカー名へのシンボリックリンクを作成する。
+
+.in +4n
+.nf
+$ \fBln \-sf libdemo.so.1.0.1 libdemo.so.1\fP
+$ \fBln \-sf libdemo.so.1 libdemo.so\fP
+.fi
+.in
+.PP
+続けて、 共有ライブラリとリンクしてメインプログラムをコンパイルし、 プログラムが依存する共有ライブラリの一覧を表示する。
+
+.in +4n
+.nf
+$ \fBcc \-g \-o prog prog.c \-L. \-ldemo\fP
+$ \fBldd prog\fP
+       linux\-vdso.so.1 =>  (0x00007fff86d66000)
+       libdemo.so.1 => not found
+       libc.so.6 => /lib64/libc.so.6 (0x00007fd4dc138000)
+       /lib64/ld\-linux\-x86\-64.so.2 (0x00007fd4dc51f000)
+.fi
+.in
+.PP
+共有ライブラリのプロファイル情報を取得するために、 環境変数 \fBLD_PROFILE\fP にこのライブラリの soname を設定する。
+
+.in +4n
+.nf
+$ \fBexport LD_PROFILE=libdemo.so.1\fP
+.fi
+.in
+.PP
+環境変数 \fBLD_PROFILE_OUTPUT\fP にプロファイル情報を出力するディレクトリのパス名を設定し、
+このディレクトリが存在しない場合は作成する。
+
+.in +4n
+.nf
+$ \fBexport LD_PROFILE_OUTPUT=$(pwd)/prof_data\fP
+$ \fBmkdir \-p $LD_PROFILE_OUTPUT\fP
+.fi
+.in
+.PP
+\fBLD_PROFILE\fP を設定すると、 プロファイルの出力は出力ファイルがすでに存在する場合は「追記」されるので、
+既存のプロファイルデータが存在しないようにしておく。
+
+.in +4n
+.nf
+$ \fBrm \-f $LD_PROFILE_OUTPUT/$LD_PROFILE.profile\fP
+.fi
+.in
+.PP
+次にプログラムを実行し、 プロファイリング出力を生成させる。 プロファイリング出力は \fBLD_PROFILE_OUTPUT\fP
+で指定されたディレクトリにファイルが書き込まれる。
+
+.in +4n
+.nf
+$ \fBLD_LIBRARY_PATH=. ./prog\fP
+$ \fBls prof_data\fP
+libdemo.so.1.profile
+.fi
+.in
+.PP
+\fBsprof \-p\fP オプションを使って、 呼び出し回数と tick 数が含まれる flat プロファイルを生成する。
+
+.in +4n
+.nf
+$ \fBsprof \-p libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
+Flat profile:
+
+Each sample counts as 0.01 seconds.
+  %   cumulative   self              self     total
+ time   seconds   seconds    calls  us/call  us/call  name
+ 60.00      0.06     0.06      100   600.00           consumeCpu1
+ 40.00      0.10     0.04     1000    40.00           consumeCpu2
+  0.00      0.10     0.00        1     0.00           x1
+  0.00      0.10     0.00        1     0.00           x2
+.fi
+.in
+.PP
+\fBsprof \-q\fP オプションを使うと、 コールグラフが生成される。
+
+.in +4n
+.nf
+$ \fBsprof \-q libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
+
+index % time    self  children    called     name
+
+                0.00    0.00      100/100         x1 [1]
+[0]    100.0    0.00    0.00      100         consumeCpu1 [0]
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+                0.00    0.00        1/1           <UNKNOWN>
+[1]      0.0    0.00    0.00        1         x1 [1]
+                0.00    0.00      100/100         consumeCpu1 [0]
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+                0.00    0.00     1000/1000        x2 [3]
+[2]      0.0    0.00    0.00     1000         consumeCpu2 [2]
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+                0.00    0.00        1/1           <UNKNOWN>
+[3]      0.0    0.00    0.00        1         x2 [3]
+                0.00    0.00     1000/1000        consumeCpu2 [2]
+\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-
+.fi
+.in
+.PP
+上記や以下の例で、 "<UNKNOWN>" の文字列は、 識別子がプロファイルされたオブジェクトの外部にあることを表している
+(この例では "<UNKNOWN>" になっているのは \fImain()\fP 内のオブジェクトである)。
+.PP
+\fBsprof \-c\fP オプションを使うと、 呼び出しの組とその発生回数のリストが生成される。
+
+.in +4n
+.nf
+$ \fBsprof \-c libdemo.so.1 $LD_PROFILE_OUTPUT/libdemo.so.1.profile\fP
+<UNKNOWN>                  x1                                 1
+x1                         consumeCpu1                      100
+<UNKNOWN>                  x2                                 1
+x2                         consumeCpu2                     1000
+.fi
+.in
+.SH 関連項目
+\fBgprof\fP(1), \fBldd\fP(1), \fBld.so\fP(8)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.78 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。