github.com/grafana/pyroscope@v1.18.0/examples/language-sdk-instrumentation/golang-push/migrating-from-standard-pprof/README.md (about) 1 # Migrating from standard pprof to Pyroscope in a Go application 2 3 This README provides a comprehensive guide on migrating from the standard `pprof` library to Pyroscope in a Go application. The example demonstrates the transition within a detective-themed Go application, showcasing how to enhance the profiling process with Pyroscope's advanced capabilities. The actual changes needed to migrate from the standard `pprof` to using [the Pyroscope SDK](https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/go_push/) are very simple. See [the source PR](https://github.com/grafana/pyroscope/pull/2830). 4 5 The Pyroscope Go SDK extends the standard `pprof` library with extra functionality and performance improvements. If you would like to use the standard `pprof` _alongside_ the Pyroscope Go SDK simultaneously, see the [example here](https://github.com/grafana/pyroscope-go/tree/main/example/http). 6 7 <img width="1426" alt="image" src="https://github.com/grafana/pyroscope/assets/23323466/f094399a-4a4d-4b47-9f03-5a15b4085fab"> 8 9 ## Changes made 10 11 ### Pre-Pyroscope setup 12 13 Originally in the pre-pyroscope code, the `main.go` file used the standard `net/http/pprof` package for profiling. This setup is common and straightforward but lacks continuous profiling and real-time analysis capabilities. 14 15 ### Post-Pyroscope migration 16 17 In the post-pyroscope code, to leverage the advanced features of Pyroscope, we made the following changes: 18 19 1. **Removed Standard pprof Import:** The `_ "net/http/pprof"` import was removed, as Pyroscope replaces its functionality. 20 21 22 2. **Added Pyroscope SDK:** We installed the Pyroscope module using the following command and imported it in our `main.go`: 23 24 > go get github.com/grafana/pyroscope-go 25 26 3. **Enabled block and mutex profilers:** This step is only required if you're using mutex or block profiling. Inside the `main()` function, we enabled the block and mutex profilers using the runtime functions: 27 28 ```go 29 runtime.SetMutexProfileFraction(5) 30 runtime.SetBlockProfileRate(5) 31 ``` 32 33 4. **Configured Pyroscope:** Inside the `main()` function, we set up Pyroscope using the `pyroscope.Start()` method with the following configuration: 34 - Application name and server address. 35 - Logger configuration. 36 - Tags for additional metadata. 37 - Profile types to be captured. 38 39 40 5. **Consider using [godeltaprof](https://pkg.go.dev/github.com/grafana/pyroscope-go/godeltaprof):** It provides an optimized way to perform memory, mutex, and block profiling more efficiently. 41 42 ## Benefits of using Pyroscope 43 44 - **Continuous Profiling:** Pyroscope offers continuous, always-on profiling, allowing real-time performance analysis. 45 - **Advanced support:** Support for advanced features such as trace-span profiling, tags/labels, and controlling profiling with code. 46 - **Higher efficiency:** Less ressource consumed by sending delta instead of cumulative profiles. 47 - **Enhanced Insights:** With Pyroscope, you gain deeper insights into your application's performance, helping to identify and resolve issues more effectively. 48 - **Easy Integration:** Migrating to Pyroscope requires minimal changes and provides a more robust profiling solution with little overhead. 49 - **Customizable Profiling:** Pyroscope enables more granular control over what gets profiled, offering a range of profiling types. 50 51 ## Migration guide 52 53 To view the exact changes made during the migration, refer to our [pull request](https://github.com/grafana/pyroscope/pull/2830). This PR clearly illustrates the differences and the necessary steps to transition from the standard `pprof` library to Pyroscope. 54 55 ## Conclusion 56 57 Migrating to the Pyroscope SDK in a Go application is a straightforward process that significantly enhances profiling capabilities. By following the steps outlined in this guide and reviewing the provided PR, developers can easily transition from the standard `pprof` library to Pyroscope, benefiting from real-time, continuous profiling and advanced performance insights.