PageSourceSearch

https://www.parca.dev/docs/assets/js/8805f9d9.74cef067.js

js parca.dev collected 2026-10-03 21:34:17 UTC 5,320 bytes, 1 lines download raw bytes

1"use strict";(globalThis.webpackChunkparca_dev=globalThis.webpackChunkparca_dev||[]).push([[6996],{5680(e,n,t){t.d(n,{xA:()=>c,yg:()=>m});var r=t(6540);function o(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e}function a(e,n){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);n&&(r=r.filter(function(n){return Object.getOwnPropertyDescriptor(e,n).enumerable})),t.push.apply(t,r)}return t}function p(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{};n%2?a(Object(t),!0).forEach(function(n){o(e,n,t[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):a(Object(t)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(t,n))})}return e}function l(e,n){if(null==e)return{};var t,r,o=function(e,n){if(null==e)return{};var t,r,o={},a=Object.keys(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||(o[t]=e[t]);return o}(e,n);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)t=a[r],n.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(o[t]=e[t])}return o}var i=r.createContext({}),u=function(e){var n=r.useContext(i),t=n;return e&&(t="function"==typeof e?e(n):p(p({},n),e)),t},c=function(e){var n=u(e.components);return r.createElement(i.Provider,{value:n},e.children)},s={inlineCode:"code",wrapper:function(e){var n=e.children;return r.createElement(r.Fragment,{},n)}},g=r.forwardRef(function(e,n){var t=e.components,o=e.mdxType,a=e.originalType,i=e.parentName,c=l(e,["components","mdxType","originalType","parentName"]),g=u(t),m=o,f=g["".concat(i,".").concat(m)]||g[m]||s[m]||a;return t?r.createElement(f,p(p({ref:n},c),{},{components:t})):r.createElement(f,p({ref:n},c))});function m(e,n){var t=arguments,o=n&&n.mdxType;if("string"==typeof e||o){var a=t.length,p=new Array(a);p[0]=g;var l={};for(var i in n)hasOwnProperty.call(n,i)&&(l[i]=n[i]);l.originalType=e,l.mdxType="string"==typeof e?e:o,p[1]=l;for(var u=2;u<a;u++)p[u]=t[u];return r.createElement.apply(null,p)}return r.createElement.apply(null,t)}g.displayName="MDXCreateElement"},6264(e,n,t){t.r(n),t.d(n,{assets:()=>i,contentTitle:()=>p,default:()=>s,frontMatter:()=>a,metadata:()=>l,toc:()=>u});var r=t(8168),o=(t(6540),t(5680));const a={},p="Instrument your Go app with pprof",l={unversionedId:"instrumenting-go",id:"instrumenting-go",title:"Instrument your Go app with pprof",description:"Go supports profiling in pprof format via the standard library. This guide features two approaches: Global and non-Global.",source:"@site/docs/instrumenting-go.md",sourceDirName:".",slug:"/instrumenting-go",permalink:"/docs/instrumenting-go",draft:!1,editUrl:"https://github.com/parca-dev/parca.dev/edit/main/docs/instrumenting-go.md",tags:[],version:"current",frontMatter:{},sidebar:"tutorialSidebar",previous:{title:"CPU Profiling",permalink:"/docs/profiling-101"},next:{title:"Demo",permalink:"/docs/demo"}},i={},u=[{value:"Global",id:"global",level:2},{value:"Non-global",id:"non-global",level:2}],c={toc:u};function s({components:e,...n}){return(0,o.yg)("wrapper",(0,r.A)({},c,n,{components:e,mdxType:"MDXLayout"}),(0,o.yg)("h1",{id:"instrument-your-go-app-with-pprof"},"Instrument your Go app with pprof"),(0,o.yg)("p",null,"Go supports profiling in ",(0,o.yg)("inlineCode",{parentName:"p"},"pprof")," format via the standard library. This guide features two approaches: Global and non-Global."),(0,o.yg)("p",null,"The ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/polarsignals/pprof-example-app-go"},(0,o.yg)("inlineCode",{parentName:"a"},"pprof-example-app-go"))," repository also demonstrates both of these approaches."),(0,o.yg)("h2",{id:"global"},"Global"),(0,o.yg)("p",null,"While we do not recommend it, using the global http server uses the least lines of code to get any Go app to expose pprof profiling endpoints."),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-go"},'import _ "net/http/pprof"\n\nfunc main() {\n    go func() {\n        log.Println(http.ListenAndServe("localhost:6060", nil))\n    }()\n\n    // Your application code...\n}\n')),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"A full example with some code that produces some activity can be found ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/polarsignals/pprof-example-app-go/blob/main/global/main.go"},"here"),".")),(0,o.yg)("h2",{id:"non-global"},"Non-global"),(0,o.yg)("p",null,"Where ever it makes sense in your program"),(0,o.yg)("pre",null,(0,o.yg)("code",{parentName:"pre",className:"language-go"},'mux := http.NewServeMux()\nmux.HandleFunc("/debug/pprof/", pprof.Index)\nmux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)\nmux.HandleFunc("/debug/pprof/profile", pprof.Profile)\nmux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)\nmux.HandleFunc("/debug/pprof/trace", pprof.Trace)\ngo func() { log.Fatal(http.ListenAndServe("localhost:6060", mux)) }()\n')),(0,o.yg)("blockquote",null,(0,o.yg)("p",{parentName:"blockquote"},"A full example with some code that produces some activity can be found ",(0,o.yg)("a",{parentName:"p",href:"https://github.com/polarsignals/pprof-example-app-go/blob/main/main.go"},"here"),".")))}s.isMDXComponent=!0}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.