Skip to content

cmd/pprof: Feature: profiling support for regular tests #23811

@dbkaplun

Description

@dbkaplun

It would be great if I could profile tests (or code in general) without having to write new code.

Currently, to profile tests via -cpuprofile, I have to contort my tests to get picked up by the profiler. I have to change all Test* functions to be called Benchmark*. To do so, I run something like this:

find . \
  -iname '*_test.go' \
  -not -path '*/vendor/*' \
    | xargs sed -Ei 's/(func )Test(\w+[(]t \*testing\.)T/\1Benchmark\2B/g'

Clearly not ideal.

However, the output that this generates is exactly what I'm looking for. The function graph is perfectly generated as I would expect. It would be great if I could easily profile tests without jumping through hoops.

Thanks for considering!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions