File: sprof.1

package info (click to toggle)
manpages-ja 0.5.0.0.20210215%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 28,568 kB
  • sloc: perl: 161; makefile: 58
file content (264 lines) | stat: -rw-r--r-- 9,530 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
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.79 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。