README 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. README for GPROF
  2. This is the GNU profiler. It is distributed with other "binary
  3. utilities" which should be in ../binutils. See ../binutils/README for
  4. more general notes, including where to send bug reports.
  5. This file documents the changes and new features available with this
  6. version of GNU gprof.
  7. * New Features
  8. o Long options
  9. o Supports generalized file format, without breaking backward compatibility:
  10. new file format supports basic-block execution counts and non-realtime
  11. histograms (see below)
  12. o Supports profiling at the line level: flat profiles, call-graph profiles,
  13. and execution-counts can all be displayed at a level that identifies
  14. individual lines rather than just functions
  15. o Test-coverage support (similar to Sun tcov program): source files
  16. can be annotated with the number of times a function was invoked
  17. or with the number of times each basic-block in a function was
  18. executed
  19. o Generalized histograms: not just execution-time, but arbitrary
  20. histograms are support (for example, performance counter based
  21. profiles)
  22. o Powerful mechanism to select data to be included/excluded from
  23. analysis and/or output
  24. o Support for DEC OSF/1 v3.0
  25. o Full cross-platform profiling support: gprof uses BFD to support
  26. arbitrary, non-native object file formats and non-native byte-orders
  27. (this feature has not been tested yet)
  28. o In the call-graph function index, static function names are now
  29. printed together with the filename in which the function was defined
  30. (required bfd_find_nearest_line() support and symbolic debugging
  31. information to be present in the executable file)
  32. o Major overhaul of source code (compiles cleanly with -Wall, etc.)
  33. * Supported Platforms
  34. The current version is known to work on:
  35. o DEC OSF/1 v3.0
  36. All features supported.
  37. o SunOS 4.1.x
  38. All features supported.
  39. o Solaris 2.3
  40. Line-level profiling unsupported because bfd_find_nearest_line()
  41. is not fully implemented for Elf binaries.
  42. o HP-UX 9.01
  43. Line-level profiling unsupported because bfd_find_nearest_line()
  44. is not fully implemented for SOM binaries.
  45. * Detailed Description
  46. ** User Interface Changes
  47. The command-line interface is backwards compatible with earlier
  48. versions of GNU gprof and Berkeley gprof. The only exception is
  49. the option to delete arcs from the call graph. The old syntax
  50. was:
  51. -k fromname toname
  52. while the new syntax is:
  53. -k fromname/toname
  54. This change was necessary to be compatible with long-option parsing.
  55. Also, "fromname" and "toname" can now be arbitrary symspecs rather
  56. than just function names (see below for an explanation of symspecs).
  57. For example, option "-k gprof.c/" suppresses all arcs due to calls out
  58. of file "gprof.c".
  59. *** Sym Specs
  60. It is often necessary to apply gprof only to specific parts of a
  61. program. GNU gprof has a simple but powerful mechanism to achieve
  62. this. So called {\em symspecs\/} provide the foundation for this
  63. mechanism. A symspec selects the parts of a profiled program to which
  64. an operation should be applied to. The syntax of a symspec is
  65. simple:
  66. filename_containing_a_dot
  67. | funcname_not_containing_a_dot
  68. | linenumber
  69. | ( [ any_filename ] `:' ( any_funcname | linenumber ) )
  70. Here are some examples:
  71. main.c Selects everything in file "main.c"---the
  72. dot in the string tells gprof to interpret
  73. the string as a filename, rather than as
  74. a function name. To select a file whose
  75. name does contain a dot, a trailing colon
  76. should be specified. For example, "odd:" is
  77. interpreted as the file named "odd".
  78. main Selects all functions named "main". Notice
  79. that there may be multiple instances of the
  80. same function name because some of the
  81. definitions may be local (i.e., static).
  82. Unless a function name is unique in a program,
  83. you must use the colon notation explained
  84. below to specify a function from a specific
  85. source file. Sometimes, functionnames contain
  86. dots. In such cases, it is necessary to
  87. add a leading colon to the name. For example,
  88. ":.mul" selects function ".mul".
  89. main.c:main Selects function "main" in file "main.c".
  90. main.c:134 Selects line 134 in file "main.c".
  91. IMPLEMENTATION NOTE: The source code uses the type sym_id for symspecs.
  92. At some point, this probably ought to be changed to "sym_spec" to make
  93. reading the code easier.
  94. *** Long options
  95. GNU gprof now supports long options. The following is a list of all
  96. supported options. Options that are listed without description
  97. operate in the same manner as the corresponding option in older
  98. versions of gprof.
  99. Short Form: Long Form:
  100. ----------- ----------
  101. -l --line
  102. Request profiling at the line-level rather
  103. than just at the function level. Source
  104. lines are identified by symbols of the form:
  105. func (file:line)
  106. where "func" is the function name, "file" is the
  107. file name and "line" is the line-number that
  108. corresponds to the line.
  109. To work properly, the binary must contain symbolic
  110. debugging information. This means that the source
  111. have to be translated with option "-g" specified.
  112. Functions for which there is no symbolic debugging
  113. information available are treated as if "--line"
  114. had not been specified. However, the line number
  115. printed with such symbols is usually incorrect
  116. and should be ignored.
  117. -a --no-static
  118. -A[symspec] --annotated-source[=symspec]
  119. Request output in the form of annotated source
  120. files. If "symspec" is specified, print output only
  121. for symbols selected by "symspec". If the option
  122. is specified multiple times, annotated output is
  123. generated for the union of all symspecs.
  124. Examples:
  125. -A Prints annotated source for all
  126. source files.
  127. -Agprof.c Prints annotated source for file
  128. gprof.c.
  129. -Afoobar Prints annotated source for files
  130. containing a function named "foobar".
  131. The entire file will be printed, but
  132. only the function itself will be
  133. annotated with profile data.
  134. -J[symspec] --no-annotated-source[=symspec]
  135. Suppress annotated source output. If specified
  136. without argument, annotated output is suppressed
  137. completely. With an argument, annotated output
  138. is suppressed only for the symbols selected by
  139. "symspec". If the option is specified multiple
  140. times, annotated output is suppressed for the
  141. union of all symspecs. This option has lower
  142. precedence than --annotated-source
  143. -p[symspec] --flat-profile[=symspec]
  144. Request output in the form of a flat profile
  145. (unless any other output-style option is specified,
  146. this option is turned on by default). If
  147. "symspec" is specified, include only symbols
  148. selected by "symspec" in flat profile. If the
  149. option is specified multiple times, the flat
  150. profile includes symbols selected by the union
  151. of all symspecs.
  152. -P[symspec] --no-flat-profile[=symspec]
  153. Suppress output in the flat profile. If given
  154. without an argument, the flat profile is suppressed
  155. completely. If "symspec" is specified, suppress
  156. the selected symbols in the flat profile. If the
  157. option is specified multiple times, the union of
  158. the selected symbols is suppressed. This option
  159. has lower precedence than --flat-profile.
  160. -q[symspec] --graph[=symspec]
  161. Request output in the form of a call-graph
  162. (unless any other output-style option is specified,
  163. this option is turned on by default). If "symspec"
  164. is specified, include only symbols selected by
  165. "symspec" in the call-graph. If the option is
  166. specified multiple times, the call-graph includes
  167. symbols selected by the union of all symspecs.
  168. -Q[symspec] --no-graph[=symspec]
  169. Suppress output in the call-graph. If given without
  170. an argument, the call-graph is suppressed completely.
  171. With a "symspec", suppress the selected symbols
  172. from the call-graph. If the option is specified
  173. multiple times, the union of the selected symbols
  174. is suppressed. This option has lower precedence
  175. than --graph.
  176. -C[symspec] --exec-counts[=symspec]
  177. Request output in the form of execution counts.
  178. If "symspec" is present, include only symbols
  179. selected by "symspec" in the execution count
  180. listing. If the option is specified multiple
  181. times, the execution count listing includes
  182. symbols selected by the union of all symspecs.
  183. -Z[symspec] --no-exec-counts[=symspec]
  184. Suppress output in the execution count listing.
  185. If given without an argument, the listing is
  186. suppressed completely. With a "symspec", suppress
  187. the selected symbols from the call-graph. If the
  188. option is specified multiple times, the union of
  189. the selected symbols is suppressed. This option
  190. has lower precedence than --exec-counts.
  191. -i --file-info
  192. Print information about the profile files that
  193. are read. The information consists of the
  194. number and types of records present in the
  195. profile file. Currently, a profile file can
  196. contain any number and any combination of histogram,
  197. call-graph, or basic-block count records.
  198. -s --sum
  199. -x --all-lines
  200. This option affects annotated source output only.
  201. By default, only the lines at the beginning of
  202. a basic-block are annotated. If this option is
  203. specified, every line in a basic-block is annotated
  204. by repeating the annotation for the first line.
  205. This option is identical to tcov's "-a".
  206. -I dirs --directory-path=dirs
  207. This option affects annotated source output only.
  208. Specifies the list of directories to be searched
  209. for source files. The argument "dirs" is a colon
  210. separated list of directories. By default, gprof
  211. searches for source files relative to the current
  212. working directory only.
  213. -z --display-unused-functions
  214. -m num --min-count=num
  215. This option affects annotated source and execution
  216. count output only. Symbols that are executed
  217. less than "num" times are suppressed. For annotated
  218. source output, suppressed symbols are marked
  219. by five hash-marks (#####). In an execution count
  220. output, suppressed symbols do not appear at all.
  221. -L --print-path
  222. Normally, source filenames are printed with the path
  223. component suppressed. With this option, gprof
  224. can be forced to print the full pathname of
  225. source filenames. The full pathname is determined
  226. from symbolic debugging information in the image file
  227. and is relative to the directory in which the compiler
  228. was invoked.
  229. -y --separate-files
  230. This option affects annotated source output only.
  231. Normally, gprof prints annotated source files
  232. to standard-output. If this option is specified,
  233. annotated source for a file named "path/filename"
  234. is generated in the file "filename-ann". That is,
  235. annotated output is {\em always\/} generated in
  236. gprof's current working directory. Care has to
  237. be taken if a program consists of files that have
  238. identical filenames, but distinct paths.
  239. -c --static-call-graph
  240. -t num --table-length=num
  241. This option affects annotated source output only.
  242. After annotating a source file, gprof generates
  243. an execution count summary consisting of a table
  244. of lines with the top execution counts. By
  245. default, this table is ten entries long.
  246. This option can be used to change the table length
  247. or, by specifying an argument value of 0, it can be
  248. suppressed completely.
  249. -n symspec --time=symspec
  250. Only symbols selected by "symspec" are considered
  251. in total and percentage time computations.
  252. However, this option does not affect percentage time
  253. computation for the flat profile.
  254. If the option is specified multiple times, the union
  255. of all selected symbols is used in time computations.
  256. -N --no-time=symspec
  257. Exclude the symbols selected by "symspec" from
  258. total and percentage time computations.
  259. However, this option does not affect percentage time
  260. computation for the flat profile.
  261. This option is ignored if any --time options are
  262. specified.
  263. -w num --width=num
  264. Sets the output line width. Currently, this option
  265. affects the printing of the call-graph function index
  266. only.
  267. -e <no long form---for backwards compatibility only>
  268. -E <no long form---for backwards compatibility only>
  269. -f <no long form---for backwards compatibility only>
  270. -F <no long form---for backwards compatibility only>
  271. -k <no long form---for backwards compatibility only>
  272. -b --brief
  273. -dnum --debug[=num]
  274. -h --help
  275. Prints a usage message.
  276. -O name --file-format=name
  277. Selects the format of the profile data files.
  278. Recognized formats are "auto", "bsd", "magic",
  279. and "prof". The last one is not yet supported.
  280. Format "auto" attempts to detect the file format
  281. automatically (this is the default behavior).
  282. It attempts to read the profile data files as
  283. "magic" files and if this fails, falls back to
  284. the "bsd" format. "bsd" forces gprof to read
  285. the data files in the BSD format. "magic" forces
  286. gprof to read the data files in the "magic" format.
  287. -T --traditional
  288. -v --version
  289. ** File Format Changes
  290. The old BSD-derived format used for profile data does not contain a
  291. magic cookie that allows one to check whether a data file really is a
  292. gprof file. Furthermore, it does not provide a version number, thus
  293. rendering changes to the file format almost impossible. GNU gprof
  294. uses a new file format that provides these features. For backward
  295. compatibility, GNU gprof continues to support the old BSD-derived
  296. format, but not all features are supported with it. For example,
  297. basic-block execution counts cannot be accommodated by the old file
  298. format.
  299. The new file format is defined in header file \file{gmon_out.h}. It
  300. consists of a header containing the magic cookie and a version number,
  301. as well as some spare bytes available for future extensions. All data
  302. in a profile data file is in the native format of the host on which
  303. the profile was collected. GNU gprof adapts automatically to the
  304. byte-order in use.
  305. In the new file format, the header is followed by a sequence of
  306. records. Currently, there are three different record types: histogram
  307. records, call-graph arc records, and basic-block execution count
  308. records. Each file can contain any number of each record type. When
  309. reading a file, GNU gprof will ensure records of the same type are
  310. compatible with each other and compute the union of all records. For
  311. example, for basic-block execution counts, the union is simply the sum
  312. of all execution counts for each basic-block.
  313. *** Histogram Records
  314. Histogram records consist of a header that is followed by an array of
  315. bins. The header contains the text-segment range that the histogram
  316. spans, the size of the histogram in bytes (unlike in the old BSD
  317. format, this does not include the size of the header), the rate of the
  318. profiling clock, and the physical dimension that the bin counts
  319. represent after being scaled by the profiling clock rate. The
  320. physical dimension is specified in two parts: a long name of up to 15
  321. characters and a single character abbreviation. For example, a
  322. histogram representing real-time would specify the long name as
  323. "seconds" and the abbreviation as "s". This feature is useful for
  324. architectures that support performance monitor hardware (which,
  325. fortunately, is becoming increasingly common). For example, under DEC
  326. OSF/1, the "uprofile" command can be used to produce a histogram of,
  327. say, instruction cache misses. In this case, the dimension in the
  328. histogram header could be set to "i-cache misses" and the abbreviation
  329. could be set to "1" (because it is simply a count, not a physical
  330. dimension). Also, the profiling rate would have to be set to 1 in
  331. this case.
  332. Histogram bins are 16-bit numbers and each bin represent an equal
  333. amount of text-space. For example, if the text-segment is one
  334. thousand bytes long and if there are ten bins in the histogram, each
  335. bin represents one hundred bytes.
  336. *** Call-Graph Records
  337. Call-graph records have a format that is identical to the one used in
  338. the BSD-derived file format. It consists of an arc in the call graph
  339. and a count indicating the number of times the arc was traversed
  340. during program execution. Arcs are specified by a pair of addresses:
  341. the first must be within caller's function and the second must be
  342. within the callee's function. When performing profiling at the
  343. function level, these addresses can point anywhere within the
  344. respective function. However, when profiling at the line-level, it is
  345. better if the addresses are as close to the call-site/entry-point as
  346. possible. This will ensure that the line-level call-graph is able to
  347. identify exactly which line of source code performed calls to a
  348. function.
  349. *** Basic-Block Execution Count Records
  350. Basic-block execution count records consist of a header followed by a
  351. sequence of address/count pairs. The header simply specifies the
  352. length of the sequence. In an address/count pair, the address
  353. identifies a basic-block and the count specifies the number of times
  354. that basic-block was executed. Any address within the basic-address can
  355. be used.
  356. IMPLEMENTATION NOTE: gcc -a can be used to instrument a program to
  357. record basic-block execution counts. However, the __bb_exit_func()
  358. that is currently present in libgcc2.c does not generate a gmon.out
  359. file in a suitable format. This should be fixed for future releases
  360. of gcc. In the meantime, contact davidm@cs.arizona.edu for a version
  361. of __bb_exit_func() to is appropriate.
  362. Copyright (C) 2012-2022 Free Software Foundation, Inc.
  363. Copying and distribution of this file, with or without modification,
  364. are permitted in any medium without royalty provided the copyright
  365. notice and this notice are preserved.