Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

README.md 16 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. # pprof
  2. pprof is a tool for visualization and analysis of profiling data.
  3. pprof reads a collection of profiling samples in profile.proto format and
  4. generates reports to visualize and help analyze the data. It can generate both
  5. text and graphical reports (through the use of the dot visualization package).
  6. profile.proto is a protocol buffer that describes a set of callstacks
  7. and symbolization information. A common usage is to represent a set of
  8. sampled callstacks from statistical profiling. The format is
  9. described on the src/proto/profile.proto file. For details on protocol
  10. buffers, see https://developers.google.com/protocol-buffers
  11. Profiles can be read from a local file, or over http. Multiple
  12. profiles of the same type can be aggregated or compared.
  13. If the profile samples contain machine addresses, pprof can symbolize
  14. them through the use of the native binutils tools (addr2line and nm).
  15. # pprof profiles
  16. pprof operates on data in the profile.proto format. Each profile is a collection
  17. of samples, where each sample is associated to a point in a location hierarchy,
  18. one or more numeric values, and a set of labels. Often these profiles represents
  19. data collected through statistical sampling of a program, so each sample
  20. describes a program call stack and a number or weight of samples collected at a
  21. location. pprof is agnostic to the profile semantics, so other uses are
  22. possible. The interpretation of the reports generated by pprof depends on the
  23. semantics defined by the source of the profile.
  24. # Usage Modes
  25. There are few different ways of using `pprof`.
  26. ## Report generation
  27. If a report format is requested on the command line:
  28. pprof <format> [options] source
  29. pprof will generate a report in the specified format and exit.
  30. Formats can be either text, or graphical. See below for details about
  31. supported formats, options, and sources.
  32. ## Interactive terminal use
  33. Without a format specifier:
  34. pprof [options] source
  35. pprof will start an interactive shell in which the user can type
  36. commands. Type `help` to get online help.
  37. ## Web interface
  38. If a host:port is specified on the command line:
  39. pprof -http=[host]:[port] [options] source
  40. pprof will start serving HTTP requests on the specified port. Visit
  41. the HTTP url corresponding to the port (typically `http://<host>:<port>/`)
  42. in a browser to see the interface.
  43. # Details
  44. The objective of pprof is to generate a report for a profile. The report is
  45. generated from a location hierarchy, which is reconstructed from the profile
  46. samples. Each location contains two values: *flat* is the value of the location
  47. itself, while *cum* is the value of the location plus all its
  48. descendants. Samples that include a location multiple times (eg for recursive
  49. functions) are counted only once per location.
  50. ## Options
  51. *options* configure the contents of a report. Each option has a value,
  52. which can be boolean, numeric, or strings. While only one format can
  53. be specified, most options can be selected independently of each
  54. other.
  55. Some common pprof options are:
  56. * **-flat** [default], **-cum**: Sort entries based on their flat or cumulative
  57. weight respectively, on text reports.
  58. * **-functions** [default], **-filefunctions**, **-files**, **-lines**,
  59. **-addresses**: Generate the report using the specified granularity.
  60. * **-noinlines**: Attribute inlined functions to their first out-of-line caller.
  61. For example, a command like `pprof -list foo -noinlines profile.pb.gz` can be
  62. used to produce the annotated source listing attributing the metrics in the
  63. inlined functions to the out-of-line calling line.
  64. * **-nodecount= _int_:** Maximum number of entries in the report. pprof will only print
  65. this many entries and will use heuristics to select which entries to trim.
  66. * **-focus= _regex_:** Only include samples that include a report entry matching
  67. *regex*.
  68. * **-ignore= _regex_:** Do not include samples that include a report entry matching
  69. *regex*.
  70. * **-show\_from= _regex_:** Do not show entries above the first one that
  71. matches *regex*.
  72. * **-show= _regex_:** Only show entries that match *regex*.
  73. * **-hide= _regex_:** Do not show entries that match *regex*.
  74. Each sample in a profile may include multiple values, representing different
  75. entities associated to the sample. pprof reports include a single sample value,
  76. which by convention is the last one specified in the report. The `sample_index=`
  77. option selects which value to use, and can be set to a number (from 0 to the
  78. number of values - 1) or the name of the sample value.
  79. Sample values are numeric values associated to a unit. If pprof can recognize
  80. these units, it will attempt to scale the values to a suitable unit for
  81. visualization. The `unit=` option will force the use of a specific unit. For
  82. example, `unit=sec` will force any time values to be reported in
  83. seconds. pprof recognizes most common time and memory size units.
  84. ## Tag filtering
  85. Samples in a profile may have tags. These tags have a name and a value; this
  86. value can be either numeric or a string. pprof can select samples from a
  87. profile based on these tags using the `-tagfocus` and `-tagignore` options.
  88. Generally, these options work as follows:
  89. * **-tagfocus=_regex_** or **-tagfocus=_range_:** Restrict to samples with tags
  90. matched by regexp or in range.
  91. * **-tagignore=_regex_** or **-tagignore=_range_:** Discard samples with tags
  92. matched by regexp or in range.
  93. When using `-tagfocus=regex` and `-tagignore=regex`, the regex will be compared
  94. to each value associated with each tag. If one specifies a value
  95. like `regex1,regex2`, then only samples with a tag value matching `regex1`
  96. and a tag value matching `regex2` will be kept.
  97. In addition to being able to filter on tag values, one can specify the name of
  98. the tag which a certain value must be associated with using the notation
  99. `-tagfocus=tagName=value`. Here, the `tagName` must match the tag's name
  100. exactly, and the value can be either a regex or a range. If one specifies
  101. a value like `regex1,regex2`, then samples with a tag value (paired with the
  102. specified tag name) matching either `regex1` or matching `regex2` will match.
  103. Here are examples explaining how `tagfocus` can be used:
  104. * `-tagfocus 128kb:512kb` accepts a sample iff it has any numeric tag with
  105. memory value in the specified range.
  106. * `-tagfocus mytag=128kb:512kb` accepts a sample iff it has a numeric tag
  107. `mytag` with memory value in the specified range. There isn't a way to say
  108. `-tagfocus mytag=128kb:512kb,16kb:32kb`
  109. or `-tagfocus mytag=128kb:512kb,mytag2=128kb:512kb`. Just single value or
  110. range for numeric tags.
  111. * `-tagfocus someregex` accepts a sample iff it has any string tag with
  112. `tagName:tagValue` string matching specified regexp. In the future, this
  113. will change to accept sample iff it has any string tag with `tagValue` string
  114. matching specified regexp.
  115. * `-tagfocus mytag=myvalue1,myvalue2` matches if either of the two tag values
  116. are present.
  117. `-tagignore` works similarly, except that it discards matching samples, instead
  118. of keeping them.
  119. If both the `-tagignore` and `-tagfocus` expressions (either a regexp or a
  120. range) match a given sample, then the sample will be discarded.
  121. ## Text reports
  122. pprof text reports show the location hierarchy in text format.
  123. * **-text:** Prints the location entries, one per line, including the flat and cum
  124. values.
  125. * **-tree:** Prints each location entry with its predecessors and successors.
  126. * **-peek= _regex_:** Print the location entry with all its predecessors and
  127. successors, without trimming any entries.
  128. * **-traces:** Prints each sample with a location per line.
  129. ## Graphical reports
  130. pprof can generate graphical reports on the DOT format, and convert them to
  131. multiple formats using the graphviz package.
  132. These reports represent the location hierarchy as a graph, with a report entry
  133. represented as a node. Solid edges represent a direct connection between
  134. entries, while dotted edges represent a connection where some intermediate nodes
  135. have been removed. Nodes are removed using heuristics to limit the size of
  136. the graph, controlled by the *nodecount* option.
  137. The size of each node represents the flat weight of the node, and the width of
  138. each edge represents the cumulative weight of all samples going through
  139. it. Nodes are colored according to their cumulative weight, highlighting the
  140. paths with the highest cum weight.
  141. * **-dot:** Generates a report in .dot format. All other formats are generated from
  142. this one.
  143. * **-svg:** Generates a report in SVG format.
  144. * **-web:** Generates a report in SVG format on a temp file, and starts a web
  145. browser to view it.
  146. * **-png, -jpg, -gif, -pdf:** Generates a report in these formats,
  147. ## Annotated code
  148. pprof can also generate reports of annotated source with samples associated to
  149. them. For these, the source or binaries must be locally available, and the
  150. profile must contain data with the appropriate level of detail.
  151. pprof will look for source files on its current working directory and all its
  152. ancestors. pprof will look for binaries on the directories specified in the
  153. `$PPROF_BINARY_PATH` environment variable, by default `$HOME/pprof/binaries`
  154. (`%USERPROFILE%\pprof\binaries` on Windows). It will look binaries up by name,
  155. and if the profile includes linker build ids, it will also search for them in
  156. a directory named as the build id.
  157. pprof uses the binutils tools to examine and disassemble the binaries. By
  158. default it will search for those tools in the current path, but it can also
  159. search for them in a directory pointed to by the environment variable
  160. `$PPROF_TOOLS`.
  161. * **-list= _regex_:** Generates an annotated source listing for functions
  162. matching *regex*, with flat/cum weights for each source line.
  163. * **-disasm= _regex_:** Generates an annotated disassembly listing for
  164. functions matching *regex*.
  165. * **-weblist= _regex_:** Generates a source/assembly combined annotated listing
  166. for functions matching *regex*, and starts a web browser to display it.
  167. ## Comparing profiles
  168. pprof can subtract one profile from another, provided the profiles are of
  169. compatible types (i.e. two heap profiles). pprof has two options which can be
  170. used to specify the filename or URL for a profile to be subtracted from the
  171. source profile:
  172. * **-diff_base= _profile_:** useful for comparing two profiles. Percentages in
  173. the output are relative to the total of samples in the diff base profile.
  174. * **-base= _profile_:** useful for subtracting a cumulative profile, like a
  175. [golang block profile](https://golang.org/doc/diagnostics.html#profiling),
  176. from another cumulative profile collected from the same program at a later time.
  177. When comparing cumulative profiles collected on the same program, percentages in
  178. the output are relative to the difference between the total for the source
  179. profile and the total for the base profile.
  180. The **-normalize** flag can be used when a base profile is specified with either
  181. the `-diff_base` or the `-base` option. This flag scales the source profile so
  182. that the total of samples in the source profile is equal to the total of samples
  183. in the base profile prior to subtracting the base profile from the source
  184. profile. Useful for determining the relative differences between profiles, for
  185. example, which profile has a larger percentage of CPU time used in a particular
  186. function.
  187. When using the **-diff_base** option, some report entries may have negative
  188. values. If the merged profile is output as a protocol buffer, all samples in the
  189. diff base profile will have a label with the key "pprof::base" and a value of
  190. "true". If pprof is then used to look at the merged profile, it will behave as
  191. if separate source and base profiles were passed in.
  192. When using the **-base** option to subtract one cumulative profile from another
  193. collected on the same program at a later time, percentages will be relative to
  194. the difference between the total for the source profile and the total for
  195. the base profile, and all values will be positive. In the general case, some
  196. report entries may have negative values and percentages will be relative to the
  197. total of the absolute value of all samples when aggregated at the address level.
  198. # Fetching profiles
  199. pprof can read profiles from a file or directly from a URL over http or https.
  200. Its native format is a gzipped profile.proto file, but it can
  201. also accept some legacy formats generated by
  202. [gperftools](https://github.com/gperftools/gperftools).
  203. When fetching from a URL handler, pprof accepts options to indicate how much to
  204. wait for the profile.
  205. * **-seconds= _int_:** Makes pprof request for a profile with the specified duration
  206. in seconds. Only makes sense for profiles based on elapsed time, such as CPU
  207. profiles.
  208. * **-timeout= _int_:** Makes pprof wait for the specified timeout when retrieving a
  209. profile over http. If not specified, pprof will use heuristics to determine a
  210. reasonable timeout.
  211. pprof also accepts options which allow a user to specify TLS certificates to
  212. use when fetching or symbolizing a profile from a protected endpoint. For more
  213. information about generating these certificates, see
  214. https://docs.docker.com/engine/security/https/.
  215. * **-tls\_cert= _/path/to/cert_:** File containing the TLS client certificate
  216. to be used when fetching and symbolizing profiles.
  217. * **-tls\_key= _/path/to/key_:** File containing the TLS private key to be used
  218. when fetching and symbolizing profiles.
  219. * **-tls\_ca= _/path/to/ca_:** File containing the certificate authority to be
  220. used when fetching and symbolizing profiles.
  221. pprof also supports skipping verification of the server's certificate chain and
  222. host name when collecting or symbolizing a profile. To skip this verification,
  223. use "https+insecure" in place of "https" in the URL.
  224. If multiple profiles are specified, pprof will fetch them all and merge
  225. them. This is useful to combine profiles from multiple processes of a
  226. distributed job. The profiles may be from different programs but must be
  227. compatible (for example, CPU profiles cannot be combined with heap profiles).
  228. ## Symbolization
  229. pprof can add symbol information to a profile that was collected only with
  230. address information. This is useful for profiles for compiled languages, where
  231. it may not be easy or even possible for the profile source to include function
  232. names or source coordinates.
  233. pprof can extract the symbol information locally by examining the binaries using
  234. the binutils tools, or it can ask running jobs that provide a symbolization
  235. interface.
  236. pprof will attempt symbolizing profiles by default, and its `-symbolize` option
  237. provides some control over symbolization:
  238. * **-symbolize=none:** Disables any symbolization from pprof.
  239. * **-symbolize=local:** Only attempts symbolizing the profile from local
  240. binaries using the binutils tools.
  241. * **-symbolize=remote:** Only attempts to symbolize running jobs by contacting
  242. their symbolization handler.
  243. For local symbolization, pprof will look for the binaries on the paths specified
  244. by the profile, and then it will search for them on the path specified by the
  245. environment variable `$PPROF_BINARY_PATH`. Also, the name of the main binary can
  246. be passed directly to pprof as its first parameter, to override the name or
  247. location of the main binary of the profile, like this:
  248. pprof /path/to/binary profile.pb.gz
  249. By default pprof will attempt to demangle and simplify C++ names, to provide
  250. readable names for C++ symbols. It will aggressively discard template and
  251. function parameters. This can be controlled with the `-symbolize=demangle`
  252. option. Note that for remote symbolization mangled names may not be provided by
  253. the symbolization handler.
  254. * **-symbolize=demangle=none:** Do not perform any demangling. Show mangled
  255. names if available.
  256. * **-symbolize=demangle=full:** Demangle, but do not perform any
  257. simplification. Show full demangled names if available.
  258. * **-symbolize=demangle=templates:** Demangle, and trim function parameters, but
  259. not template parameters.