{"id":7888,"library":"zprofile","title":"zprofile: Statistical CPU and Wall-Clock Profilers for Python","description":"zprofile provides statistical (sampling) CPU and wall-clock profilers for Python applications. Derived from the `google-cloud-profiler`, it allows users to collect profiling data with minimal overhead, making it suitable for production environments. The library outputs data in the `pprof` format, which can then be visualized using the external `go tool pprof`. The current version is 1.0.13, last released in August 2023, indicating a maintenance-oriented release cadence.","status":"maintenance","version":"1.0.13","language":"python","source_language":"en","source_url":"https://github.com/timpalpant/zprofile","tags":["profiling","cpu","wall-clock","performance","pprof","diagnostics"],"install":[{"cmd":"pip install zprofile","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"wrong":"from zprofile import CPUProfiler","symbol":"CPUProfiler","correct":"import zprofile"}],"quickstart":{"code":"import time\nfrom zprofile.cpu_profiler import CPUProfiler\n\ndef busy_wait(duration):\n    end_time = time.time() + duration\n    while time.time() < end_time:\n        pass\n\ndef main_function():\n    print(\"Starting CPU intensive task...\")\n    busy_wait(2) # Simulate CPU work\n    print(\"CPU task complete.\")\n\np = CPUProfiler()\nprofile_data = p.profile(10) # Profile for 10 seconds\n\nwith open(\"profile.pprof\", \"wb\") as f:\n    f.write(profile_data)\n\nprint(\"CPU profile data written to profile.pprof\")\nprint(\"Use 'go tool pprof -http=:8080 profile.pprof' to view the profile.\")","lang":"python","description":"This quickstart demonstrates how to use the `CPUProfiler` to collect CPU usage statistics over a 10-second period for a simulated busy-wait function. The collected profile data is saved to a file named `profile.pprof`, which can then be visualized using the `go tool pprof` utility."},"warnings":[{"fix":"Install the Go SDK from golang.org/doc/install and ensure `go tool pprof` is in your system's PATH. Then run `go tool pprof -http=:8080 profile.pprof` in your terminal to view the interactive flame graph.","message":"To visualize the `.pprof` output files, you must install the Go programming language SDK and use its `go tool pprof` utility. This tool is not bundled with the `zprofile` Python library.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For general system profiling, `zprofile` is effective. If precise, per-line execution counts for extremely fast operations are needed, consider `cProfile` (built-in Python) or other deterministic profilers, understanding their potentially higher overhead. Ensure your profiled code runs long enough to generate meaningful samples (e.g., at least a few seconds).","message":"As a statistical (sampling) profiler, `zprofile` captures CPU and wall-clock usage by periodically taking samples. This approach minimizes overhead but might occasionally miss very short-lived function calls or specific line-by-line execution details that a deterministic profiler would catch. For very fine-grained analysis of short functions, consider deterministic profiling tools if overhead is acceptable.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'1.0.13':70 '2023':75 'allow':32 'applic':23 'august':74 'cadenc':82 'clock':7,19,87 'cloud':29 'collect':35 'cpu':3,15,84 'current':67 'data':37,50 'deriv':24 'diagnost':90 'environ':46 'extern':62 'format':54 'go':63 'googl':28 'google-cloud-profil':27 'indic':76 'last':71 'librari':48 'mainten':79 'maintenance-ori':78 'make':41 'minim':39 'orient':80 'output':49 'overhead':40 'perform':88 'pprof':53,65,89 'product':45 'profil':8,20,30,36,83 'provid':12 'python':10,22 'releas':72,81 'sampl':14 'statist':2,13 'suitabl':43 'tool':64 'use':60 'user':33 'version':68 'visual':59 'wall':6,18,86 'wall-clock':5,17,85 'zprofil':1,11","created_at":"2026-04-16T14:17:42.975513+00:00","updated_at":"2026-04-16T14:17:42.975513+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.0.13","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/timpalpant/zprofile","docs":null,"changelog":null,"pypi":"https://pypi.org/project/zprofile/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["observability"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}