Open-source project
gperftools/gperftools avatar
gperftools/gperftools

gperftools: tcmalloc and the profilers that grew up beside it

Main gperftools repository

8,991 stars1,537 forksC++BSD-3-Clause

At a glance

What is it?
Google's performance tools collection, now maintained outside Google, with a README that admits pprof outgrew it.
Who is it for?
gperftools is most useful when you have a C or C++ binary you cannot recompile, because LD_PRELOAD gets you heap profiling without a rebuild. For everything else in this article's territory, modern toolchains have better options: Go has its own pprof integration, and language-level profilers usually understand your program's structure better than a sampling profiler with symbol tables.
Can I use it commercially?
Yes. BSD-3-Clause is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository received new commits within the last day.
What is it written in?
Mainly C++, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 23, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • gperftools/gperftools8,991 ★ · +10
Star history
Repository2026-10-102026-11-23
gperftools/gperftools9k9k

10 Stars in the last 44 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

Two libraries, one malloc replacement and one profiler

gperftools is described as a collection of a high-performance multi-threaded malloc implementation, plus some pretty nifty performance analysis tools. Originally it was Google Performance Tools, and it is now maintained as its own project under the BSD License with a mailing list on Google Groups.

There are effectively two things in the box. The first is tcmalloc, which you link in place of malloc and new, either as -ltcmalloc or in a smaller form as -ltcmalloc_minimal. The second is a set of profilers: the CPU profiler is linked with -lprofiler, while the heap profiler is tcmalloc's own and is used by linking -ltcmalloc.

That split is the first thing to understand. The README is explicit that the cpu profiler, heap checker and heap profiler lie dormant, using no memory or CPU, until you turn them on. Which means there is no harm in linking -lprofiler into every application, and also -ltcmalloc if you are happy with the non-libc malloc library.

So the cost of adopting gperftools is a link flag, not a runtime tax. That is a rare and useful property for a performance tool.

The repository has 8988 stars and 1539 forks with 107 open issues, is BSD-3-Clause licensed, and the last push was 2026-10-29. The language is listed as C++.

Heap profiling three steps, one of which needs no rebuild

The heap profiler quick start in the README is worth reading closely, because the note that follows it changes what the tool is for.

The documented path is to link your executable with -ltcmalloc, run it with the HEAPPROFILE environment variable set, and then analyse the output with pprof:

bash
$ HEAPPROFILE=/tmp/heapprof <path/to/binary> [binary args]
$ pprof <path/to/binary> /tmp/heapprof.0045.heap
$ pprof --gv <path/to/binary> /tmp/heapprof.0045.heap

Note that the output file is numbered, which is why the example shows heapprof.0045.heap: HEAPPROFILE sets a prefix for the dumps rather than a single file name.

The note after the quick start is the important one: you can also use LD_PRELOAD to heap-profile an executable that you did not compile. That turns gperftools from a build-time decision into a deployment-time one, and for a crash triage or a vendor binary it is the only realistic option.

Two limits are stated plainly. The heap profiler is available on all unix-based systems tested, but it is not currently available on Windows. And the analysis step is no longer part of this repository, which is the subject of the next section.

The related heap checker works the same way through HEAPCHECK, which takes a strictness type rather than a path.

The CPU profiler, and the fork caveat in the README

The CPU profiler follows the same shape with different flags. You link with -lprofiler, set CPUPROFILE to a file, and analyse it with pprof, which the README describes as producing pg-like text output, or with the --gv flag for graphical output:

bash
$ CPUPROFILE=/tmp/prof.out <path/to/binary> [binary args]
$ pprof <path/to/binary> /tmp/prof.out
$ pprof --gv <path/to/binary> /tmp/prof.out

The environment variables matter as much as the flags. PROFILESELECTED set to 1 restricts profiling to regions wrapped in ProfilerEnable and ProfilerDisable calls, which is how you avoid drowning in samples from a program that spends its time in a library. CPUPROFILE_FREQUENCY sets how many interrupts per second the profiler samples, which trades overhead against resolution. MALLOCSTATS prints memory-use stats at program exit, and PERFTOOLS_VERBOSE raises the volume of messages malloc emits.

Then there is the caveat, and it is the kind of warning that only appears in a README originally written in 2011. CPU profiling does not work after fork unless you immediately do an exec-style call afterwards. And if you do fork and the child calls exit, it may corrupt the profile data, with _exit given as the workaround.

That last point matters for anything that forks worker processes, which on Linux is a common shape for a service. If your program forks, the child needs to exec immediately, or leave with _exit rather than exit, to keep the profile intact.

The CPU profiler is also not available on Windows. For the full variable list, the README sends you to docs/cpuprofile.adoc and docs/heapprofile.adoc.

pprof was removed from this repository on purpose

This is the paragraph in the README that tells you something about how the project is run, and it is unusual enough to be worth quoting in structure rather than in full.

gperftools was the original home for the pprof program. The original pprof was a Perl script, and the README observes that there are not that many Perl experts nowadays. The script was rewritten in Go around 2016, and that version became more featureful. So the original pprof has been removed in favour of the Go version, which lives in its own repository, and Go's own profiling facilities are based on that same version.

That chain of events is the whole story of this repository's relationship with tooling. gperftools produced something genuinely good, that good thing outgrew it, and the project removed the original in favour of the Go version.

So the correct workflow today is gperftools for capture and google/pprof for analysis, and the README points there rather than shipping a second implementation. If you are following an old tutorial that pipes gperftools output into a local pprof script, that script is the deprecated one.

The README also notes a wiki page on stack trace capturing methods and their issues, and separately points at the TCMALLOC_STACKTRACE_METHOD and TCMALLOC_STACKTRACE_METHOD_VERBOSE variables documented in the INSTALL file.

There is one other stack of documentation at the repository root worth knowing about. docs/ holds the two asciidoc pages named above, INSTALL covers configure flags for advanced users plus the per-platform notes, and README_windows.txt covers the Windows port, which the README describes as basic functionality only.

Why 2.19 replaced the stack unwinder

The current releases are gperftools-2.19.2, published 2026-10-29, gperftools-2.19.1 from 2026-10-21 and gperftools-2.19 from 2026-10-20, three releases in under two weeks.

How stack traces are captured is configurable rather than fixed. The README points to the TCMALLOC_STACKTRACE_METHOD and TCMALLOC_STACKTRACE_METHOD_VERBOSE environment variables, briefly documented in the INSTALL file, and to a wiki page on gperftools' stack trace capturing methods and their issues.

Four build systems in one repository

The tree at the root shows a project that has to be built four different ways, which is normal for a C library with this many downstream consumers.

There is configure.ac with autogen.sh and m4/, which is the autotools path and the traditional one. There is CMakeLists.txt with a cmake/ directory. There is a Bazel path, with BUILD.bazel, MODULE.bazel, .bazelrc and .bazelignore. There is also gperftools.sln and a vsprojects/ directory for Visual Studio.

Other things at the root are diagnostic of a long-lived project. There is a NEWS file alongside ChangeLog.old. AUTHORS is present. There is a .clang-format file, a .clangd file for editor configuration, and a gen_compile_commands.rb script that suggests some developers work in Ruby tooling for build database generation.

The source layout is src/, with benchmark/ for the benchmark harness, generic-config/ for the configure templates, vendor/ for vendored third-party code, and docs/ for the asciidoc manual.

Portability is documented honestly. The README says perftools was developed and tested on x86, aarch64 and riscv Linux systems, and works in its full generality only on those. Much of tcmalloc has been ported to FreeBSD, Solaris x86 and Mac OS X on aarch64, with x86 and ppc not tested recently, and the basic functionality of tcmalloc_minimal has been ported to Windows.

Editorial conclusion

gperftools is most useful when you have a C or C++ binary you cannot recompile, because LD_PRELOAD gets you heap profiling without a rebuild. For everything else in this article's territory, modern toolchains have better options: Go has its own pprof integration, and language-level profilers usually understand your program's structure better than a sampling profiler with symbol tables. What gperftools still does well is the allocator. The tcmalloc replacement for malloc and new is a battle-tested reason to link it on a large C++ service. The current release is gperftools-2.19.2, published 2026-10-29.

Frequently asked questions

How do I profile heap usage with gperftools?

Link your executable with -ltcmalloc, run it with the HEAPPROFILE environment variable set to a path prefix, and analyse the numbered output files with pprof. If you cannot recompile the binary, LD_PRELOAD lets you heap-profile it anyway. The profiler is available on unix-based systems but not on Windows.

How do I collect a CPU profile?

Link with -lprofiler, set CPUPROFILE to an output file, and run the program. Set PROFILESELECTED=1 to restrict sampling to regions wrapped in ProfilerEnable and ProfilerDisable, and use CPUPROFILE_FREQUENCY to trade overhead against resolution. Note the README's warning that CPU profiling does not work after fork unless the child immediately execs, and that a child calling exit may corrupt the profile data.

What happened to pprof in gperftools?

The original pprof was a Perl script that lived here. It was rewritten in Go around 2016, that Go version became more featureful, and the Perl script has been removed in favour of the Go one at github.com/google/pprof. Go's own profiling facilities are based on that same Go version, so the analysis step is not part of gperftools any more.

How does gperftools choose a stack trace method?

Through the TCMALLOC_STACKTRACE_METHOD and TCMALLOC_STACKTRACE_METHOD_VERBOSE environment variables, which the README says are briefly documented in the INSTALL file and on the project wiki page about stack trace capturing methods and their issues.

Does linking gperftools cost anything at runtime?

Not unless you turn it on. The README states the cpu profiler, heap checker and heap profiler stay dormant using no memory or CPU until enabled through environment variables such as CPUPROFILE, HEAPPROFILE and HEAPCHECK. That is why it says there is no harm in linking -lprofiler into every application, and -ltcmalloc if you accept the non-libc allocator.

Official sources

  1. gperftools/gperftools on GitHub
  2. Issues
  3. License: BSD-3-Clause
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/gperftools-gperftools.svg)](https://hysenlabs.com/projects/gperftools-gperftools)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/gperftools-gperftools.svg)](https://hysenlabs.com/projects/gperftools-gperftools)

Was this useful?