How to use pprof to monitor the number of goroutines in a Go program?

Patricia Arquette
Release: 2024-10-26 04:43:02
Original
202 people have browsed it

How to use pprof to monitor the number of goroutines in a Go program?

How to monitor the number of goroutines in a Go program using pprof

Profiling the number of goroutines can help identify potential goroutine leaks. pprof, a Go profiling tool, provides insights into the current state of a running Go program, including the number of active goroutines.

Approach:

To monitor goroutine count using pprof:

  • Enable profiling server: Start your Go program with the -cpuprofile flag.

    go run main.go -cpuprofile=cpu.pprof
    Copy after login
  • Open pprof dashboard: Visit localhost:8888/debug/pprof/ in a web browser.
  • Select relevant links: The dashboard includes two links for goroutine profiling:

    • "goroutine" (http://localhost:8888/debug/pprof/goroutine?debug=1)
    • "full goroutine stack dump" (http://localhost:8888/debug/pprof/goroutine?debug=2)
  • Analyze goroutine count: The "goroutine" link displays a list of all active goroutines, grouped by their shared code base. Each goroutine entry includes the number of instances of that goroutine.
  • Inspect individual goroutines: The "full goroutine stack dump" link provides detailed information about each individual goroutine, including its stack trace and current state (e.g., receiving from a channel).

The above is the detailed content of How to use pprof to monitor the number of goroutines in a Go program?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!