You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

356 lines
11 KiB

8 years ago
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <meta name="theme-color" content="#375EAB">
  7. <title>pprof - The Go Programming Language</title>
  8. <link type="text/css" rel="stylesheet" href="../../../../lib/godoc/style.css">
  9. <link rel="stylesheet" href="../../../../lib/godoc/jquery.treeview.css">
  10. <script type="text/javascript">window.initFuncs = [];</script>
  11. </head>
  12. <body>
  13. <div id='lowframe' style="position: fixed; bottom: 0; left: 0; height: 0; width: 100%; border-top: thin solid grey; background-color: white; overflow: auto;">
  14. ...
  15. </div><!-- #lowframe -->
  16. <div id="topbar" class="wide"><div class="container">
  17. <div class="top-heading" id="heading-wide"><a href="http://localhost:6060/">The Go Programming Language</a></div>
  18. <div class="top-heading" id="heading-narrow"><a href="http://localhost:6060/">Go</a></div>
  19. <a href="index.html#" id="menu-button"><span id="menu-button-arrow">&#9661;</span></a>
  20. <form method="GET" action="http://localhost:6060/search">
  21. <div id="menu">
  22. <a href="http://localhost:6060/doc/">Documents</a>
  23. <a href="http://localhost:6060/pkg/">Packages</a>
  24. <a href="http://localhost:6060/project/">The Project</a>
  25. <a href="http://localhost:6060/help/">Help</a>
  26. <a href="http://localhost:6060/blog/">Blog</a>
  27. <input type="text" id="search" name="q" class="inactive" value="Search" placeholder="Search">
  28. </div>
  29. </form>
  30. </div></div>
  31. <div id="page" class="wide">
  32. <div class="container">
  33. <h1>Package pprof</h1>
  34. <div id="nav"></div>
  35. <!--
  36. Copyright 2009 The Go Authors. All rights reserved.
  37. Use of this source code is governed by a BSD-style
  38. license that can be found in the LICENSE file.
  39. -->
  40. <!--
  41. Note: Static (i.e., not template-generated) href and id
  42. attributes start with "pkg-" to make it impossible for
  43. them to conflict with generated attributes (some of which
  44. correspond to Go identifiers).
  45. -->
  46. <script type='text/javascript'>
  47. document.ANALYSIS_DATA = null;
  48. document.CALLGRAPH = null;
  49. </script>
  50. <div id="short-nav">
  51. <dl>
  52. <dd><code>import "net/http/pprof"</code></dd>
  53. </dl>
  54. <dl>
  55. <dd><a href="index.html#pkg-overview" class="overviewLink">Overview</a></dd>
  56. <dd><a href="index.html#pkg-index" class="indexLink">Index</a></dd>
  57. </dl>
  58. </div>
  59. <!-- The package's Name is printed as title by the top-level template -->
  60. <div id="pkg-overview" class="toggleVisible">
  61. <div class="collapsed">
  62. <h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
  63. </div>
  64. <div class="expanded">
  65. <h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
  66. <p>
  67. Package pprof serves via its HTTP server runtime profiling data
  68. in the format expected by the pprof visualization tool.
  69. For more information about pprof, see
  70. <a href="http://code.google.com/p/google-perftools/">http://code.google.com/p/google-perftools/</a>.
  71. </p>
  72. <p>
  73. The package is typically only imported for the side effect of
  74. registering its HTTP handlers.
  75. The handled paths all begin with /debug/pprof/.
  76. </p>
  77. <p>
  78. To use pprof, link this package into your program:
  79. </p>
  80. <pre>import _ &#34;net/http/pprof&#34;
  81. </pre>
  82. <p>
  83. If your application is not already running an http server, you
  84. need to start one. Add &#34;net/http&#34; and &#34;log&#34; to your imports and
  85. the following code to your main function:
  86. </p>
  87. <pre>go func() {
  88. log.Println(http.ListenAndServe(&#34;localhost:6060&#34;, nil))
  89. }()
  90. </pre>
  91. <p>
  92. Then use the pprof tool to look at the heap profile:
  93. </p>
  94. <pre>go tool pprof <a href="http://localhost:6060/debug/pprof/heap">http://localhost:6060/debug/pprof/heap</a>
  95. </pre>
  96. <p>
  97. Or to look at a 30-second CPU profile:
  98. </p>
  99. <pre>go tool pprof <a href="http://localhost:6060/debug/pprof/profile">http://localhost:6060/debug/pprof/profile</a>
  100. </pre>
  101. <p>
  102. Or to look at the goroutine blocking profile:
  103. </p>
  104. <pre>go tool pprof <a href="http://localhost:6060/debug/pprof/block">http://localhost:6060/debug/pprof/block</a>
  105. </pre>
  106. <p>
  107. Or to collect a 5-second execution trace:
  108. </p>
  109. <pre>wget <a href="http://localhost:6060/debug/pprof/trace?seconds=5">http://localhost:6060/debug/pprof/trace?seconds=5</a>
  110. </pre>
  111. <p>
  112. To view all available profiles, open <a href="http://localhost:6060/debug/pprof/">http://localhost:6060/debug/pprof/</a>
  113. in your browser.
  114. </p>
  115. <p>
  116. For a study of the facility in action, visit
  117. </p>
  118. <pre><a href="https://blog.golang.org/2011/06/profiling-go-programs.html">https://blog.golang.org/2011/06/profiling-go-programs.html</a>
  119. </pre>
  120. </div>
  121. </div>
  122. <div id="pkg-index" class="toggleVisible">
  123. <div class="collapsed">
  124. <h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
  125. </div>
  126. <div class="expanded">
  127. <h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>
  128. <!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
  129. <div id="manual-nav">
  130. <dl>
  131. <dd><a href="index.html#Cmdline">func Cmdline(w http.ResponseWriter, r *http.Request)</a></dd>
  132. <dd><a href="index.html#Handler">func Handler(name string) http.Handler</a></dd>
  133. <dd><a href="index.html#Index">func Index(w http.ResponseWriter, r *http.Request)</a></dd>
  134. <dd><a href="index.html#Profile">func Profile(w http.ResponseWriter, r *http.Request)</a></dd>
  135. <dd><a href="index.html#Symbol">func Symbol(w http.ResponseWriter, r *http.Request)</a></dd>
  136. <dd><a href="index.html#Trace">func Trace(w http.ResponseWriter, r *http.Request)</a></dd>
  137. </dl>
  138. </div><!-- #manual-nav -->
  139. <h4>Package files</h4>
  140. <p>
  141. <span style="font-size:90%">
  142. <a href="http://localhost:6060/src/net/http/pprof/pprof.go">pprof.go</a>
  143. </span>
  144. </p>
  145. </div><!-- .expanded -->
  146. </div><!-- #pkg-index -->
  147. <div id="pkg-callgraph" class="toggle" style="display: none">
  148. <div class="collapsed">
  149. <h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
  150. </div> <!-- .expanded -->
  151. <div class="expanded">
  152. <h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
  153. <p>
  154. In the call graph viewer below, each node
  155. is a function belonging to this package
  156. and its children are the functions it
  157. calls&mdash;perhaps dynamically.
  158. </p>
  159. <p>
  160. The root nodes are the entry points of the
  161. package: functions that may be called from
  162. outside the package.
  163. There may be non-exported or anonymous
  164. functions among them if they are called
  165. dynamically from another package.
  166. </p>
  167. <p>
  168. Click a node to visit that function's source code.
  169. From there you can visit its callers by
  170. clicking its declaring <code>func</code>
  171. token.
  172. </p>
  173. <p>
  174. Functions may be omitted if they were
  175. determined to be unreachable in the
  176. particular programs or tests that were
  177. analyzed.
  178. </p>
  179. <!-- Zero means show all package entry points. -->
  180. <ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
  181. </div>
  182. </div> <!-- #pkg-callgraph -->
  183. <h2 id="Cmdline">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=2215:2267#L68">Cmdline</a></h2>
  184. <pre>func Cmdline(w <a href="../index.html">http</a>.<a href="../index.html#ResponseWriter">ResponseWriter</a>, r *<a href="../index.html">http</a>.<a href="../index.html#Request">Request</a>)</pre>
  185. <p>
  186. Cmdline responds with the running program&#39;s
  187. command line, with arguments separated by NUL bytes.
  188. The package initialization registers it as /debug/pprof/cmdline.
  189. </p>
  190. <h2 id="Handler">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=5733:5771#L181">Handler</a></h2>
  191. <pre>func Handler(name <a href="../../../builtin/index.html#string">string</a>) <a href="../index.html">http</a>.<a href="../index.html#Handler">Handler</a></pre>
  192. <p>
  193. Handler returns an HTTP handler that serves the named profile.
  194. </p>
  195. <h2 id="Index">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=6493:6543#L208">Index</a></h2>
  196. <pre>func Index(w <a href="../index.html">http</a>.<a href="../index.html#ResponseWriter">ResponseWriter</a>, r *<a href="../index.html">http</a>.<a href="../index.html#Request">Request</a>)</pre>
  197. <p>
  198. Index responds with the pprof-formatted profile named by the request.
  199. For example, &#34;/debug/pprof/heap&#34; serves the &#34;heap&#34; profile.
  200. Index responds to a request for &#34;/debug/pprof/&#34; with an HTML page
  201. listing the available profiles.
  202. </p>
  203. <h2 id="Profile">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=2725:2777#L86">Profile</a></h2>
  204. <pre>func Profile(w <a href="../index.html">http</a>.<a href="../index.html#ResponseWriter">ResponseWriter</a>, r *<a href="../index.html">http</a>.<a href="../index.html#Request">Request</a>)</pre>
  205. <p>
  206. Profile responds with the pprof-formatted cpu profile.
  207. The package initialization registers it as /debug/pprof/profile.
  208. </p>
  209. <h2 id="Symbol">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=4557:4608#L135">Symbol</a></h2>
  210. <pre>func Symbol(w <a href="../index.html">http</a>.<a href="../index.html#ResponseWriter">ResponseWriter</a>, r *<a href="../index.html">http</a>.<a href="../index.html#Request">Request</a>)</pre>
  211. <p>
  212. Symbol looks up the program counters listed in the request,
  213. responding with a table mapping program counters to function names.
  214. The package initialization registers it as /debug/pprof/symbol.
  215. </p>
  216. <h2 id="Trace">func <a href="http://localhost:6060/src/net/http/pprof/pprof.go?s=3674:3724#L111">Trace</a></h2>
  217. <pre>func Trace(w <a href="../index.html">http</a>.<a href="../index.html#ResponseWriter">ResponseWriter</a>, r *<a href="../index.html">http</a>.<a href="../index.html#Request">Request</a>)</pre>
  218. <p>
  219. Trace responds with the execution trace in binary form.
  220. Tracing lasts for duration specified in seconds GET parameter, or for 1 second if not specified.
  221. The package initialization registers it as /debug/pprof/trace.
  222. </p>
  223. <div id="footer">
  224. Build version go1.6.<br>
  225. Except as <a href="https://developers.google.com/site-policies#restrictions">noted</a>,
  226. the content of this page is licensed under the
  227. Creative Commons Attribution 3.0 License,
  228. and code is licensed under a <a href="http://localhost:6060/LICENSE">BSD license</a>.<br>
  229. <a href="http://localhost:6060/doc/tos.html">Terms of Service</a> |
  230. <a href="http://www.google.com/intl/en/policies/privacy/">Privacy Policy</a>
  231. </div>
  232. </div><!-- .container -->
  233. </div><!-- #page -->
  234. <!-- TODO(adonovan): load these from <head> using "defer" attribute? -->
  235. <script type="text/javascript" src="../../../../lib/godoc/jquery.js"></script>
  236. <script type="text/javascript" src="../../../../lib/godoc/jquery.treeview.js"></script>
  237. <script type="text/javascript" src="../../../../lib/godoc/jquery.treeview.edit.js"></script>
  238. <script type="text/javascript" src="../../../../lib/godoc/godocs.js"></script>
  239. </body>
  240. </html>