Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/crosscluster/logical/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ go_library(
"//pkg/util/log/logcrash",
"//pkg/util/metamorphic",
"//pkg/util/metric",
"//pkg/util/pprofutil",
"//pkg/util/protoutil",
"//pkg/util/randutil",
"//pkg/util/retry",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"fmt"
"hash/fnv"
"regexp"
"runtime/pprof"
"slices"
"strings"
"time"
Expand Down Expand Up @@ -45,6 +44,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/log/logcrash"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/span"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -349,12 +349,12 @@ func (lrw *logicalReplicationWriterProcessor) Start(ctx context.Context) {
})
lrw.workerGroup.GoCtx(func(ctx context.Context) error {
defer close(lrw.checkpointCh)
pprof.Do(ctx, pprof.Labels("proc", fmt.Sprintf("%d", lrw.ProcessorID)), func(ctx context.Context) {
pprofutil.Do(ctx, func(ctx context.Context) {
if err := lrw.consumeEvents(ctx); err != nil {
log.Dev.Infof(lrw.Ctx(), "consumer completed. Error: %s", err)
lrw.sendError(errors.Wrap(err, "consume events"))
}
})
}, "proc", fmt.Sprintf("%d", lrw.ProcessorID))
return nil
})
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/crosscluster/logical/offline_initial_scan_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package logical
import (
"context"
"fmt"
"runtime/pprof"
"time"

"github.com/cockroachdb/cockroach/pkg/backup"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/log/logcrash"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/span"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -225,7 +225,7 @@ func (o *offlineInitialScanProcessor) Start(ctx context.Context) {
o.workerGroup.GoCtx(func(ctx context.Context) error {
defer close(o.checkpointCh)
defer close(o.rangeStatsCh)
pprof.Do(ctx, pprof.Labels("proc", fmt.Sprintf("%d", o.ProcessorID)), func(ctx context.Context) {
pprofutil.Do(ctx, func(ctx context.Context) {
for event := range o.subscription.Events() {
if err := o.handleEvent(ctx, event); err != nil {
log.Dev.Infof(o.Ctx(), "consumer completed. Error: %s", err)
Expand All @@ -235,7 +235,7 @@ func (o *offlineInitialScanProcessor) Start(ctx context.Context) {
if err := o.subscription.Err(); err != nil {
o.sendError(errors.Wrap(err, "subscription"))
}
})
}, "proc", fmt.Sprintf("%d", o.ProcessorID))
return nil
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvclient/rangefeed/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ go_library(
"//pkg/util/limit",
"//pkg/util/log",
"//pkg/util/mon",
"//pkg/util/pprofutil",
"//pkg/util/retry",
"//pkg/util/span",
"//pkg/util/stop",
Expand Down
8 changes: 4 additions & 4 deletions pkg/kv/kvclient/rangefeed/rangefeed.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package rangefeed
import (
"context"
"fmt"
"runtime/pprof"
"strings"
"sync"
"sync/atomic"
Expand All @@ -23,6 +22,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/ctxgroup"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/span"
"github.com/cockroachdb/cockroach/pkg/util/stop"
Expand Down Expand Up @@ -241,9 +241,9 @@ func (f *RangeFeed) start(
// pprof.Do function does exactly what we do here, but it also results in
// pprof.Do function showing up in the stack traces -- so, just set and reset
// labels manually.
defer pprof.SetGoroutineLabels(ctx)
ctx = pprof.WithLabels(ctx, pprof.Labels(append(f.extraPProfLabels, "rangefeed", f.name)...))
pprof.SetGoroutineLabels(ctx)
ctx, reset := pprofutil.SetProfilerLabels(ctx, append(f.extraPProfLabels, "rangefeed", f.name)...)
defer reset()

if f.invoker != nil {
_ = f.invoker(func() error {
f.run(ctx, frontier, resumeFromFrontier)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/raft_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"math"
"net"
"runtime/pprof"
"sync/atomic"
"time"

Expand All @@ -29,6 +28,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/storage"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -931,7 +931,7 @@ func (t *RaftTransport) startProcessNewQueue(
}
go func(ctx context.Context) {
defer hdl.Activate(ctx).Release(ctx)
pprof.Do(ctx, pprof.Labels("remote_node_id", toNodeID.String()), worker)
pprofutil.Do(ctx, worker, "remote_node_id", toNodeID.String())
}(ctx)
return true
}
Expand Down
13 changes: 5 additions & 8 deletions pkg/kv/kvserver/replica_send.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package kvserver
import (
"context"
"reflect"
"runtime/pprof"
"runtime/trace"
"time"

Expand All @@ -30,6 +29,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/grunning"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -131,16 +131,13 @@ func (r *Replica) SendWithWriteBytes(
defer r.MeasureReqCPUNanos(ctx, startCPU)

if r.store.cfg.Settings.CPUProfileType() == cluster.CPUProfileWithLabels {
defer pprof.SetGoroutineLabels(ctx)
// Note: the defer statement captured the previous context.
var lbls pprof.LabelSet
var reset func()
if tenantIDOrZero.IsSet() {
lbls = pprof.Labels("range_str", r.rangeStr.ID(), "tenant_id", tenantIDOrZero.String())
ctx, reset = pprofutil.SetProfilerLabels(ctx, "range_str", r.rangeStr.ID(), "tenant_id", tenantIDOrZero.String())
} else {
lbls = pprof.Labels("range_str", r.rangeStr.ID())
ctx, reset = pprofutil.SetProfilerLabels(ctx, "range_str", r.rangeStr.ID())
}
ctx = pprof.WithLabels(ctx, lbls)
pprof.SetGoroutineLabels(ctx)
defer reset()
}
if trace.IsEnabled() {
defer trace.StartRegion(ctx, r.rangeStr.String() /* cheap */).End()
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/storeliveness/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ go_library(
"//pkg/util/log",
"//pkg/util/metamorphic",
"//pkg/util/metric",
"//pkg/util/pprofutil",
"//pkg/util/protoutil",
"//pkg/util/stop",
"//pkg/util/syncutil",
Expand Down
4 changes: 2 additions & 2 deletions pkg/kv/kvserver/storeliveness/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package storeliveness

import (
"context"
"runtime/pprof"
"time"

slpb "github.com/cockroachdb/cockroach/pkg/kv/kvserver/storeliveness/storelivenesspb"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/metamorphic"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/taskpacer"
Expand Down Expand Up @@ -570,7 +570,7 @@ func (t *Transport) startProcessNewQueue(
err := t.stopper.RunAsyncTask(
ctx, "storeliveness.Transport: sending messages",
func(ctx context.Context) {
pprof.Do(ctx, pprof.Labels("remote_node_id", toNodeID.String()), worker)
pprofutil.Do(ctx, worker, "remote_node_id", toNodeID.String())
},
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/kv/kvserver/txnwait/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ go_library(
"//pkg/util/hlc",
"//pkg/util/log",
"//pkg/util/metric",
"//pkg/util/pprofutil",
"//pkg/util/retry",
"//pkg/util/stop",
"//pkg/util/syncutil",
Expand Down
7 changes: 3 additions & 4 deletions pkg/kv/kvserver/txnwait/queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"bytes"
"container/list"
"context"
"runtime/pprof"
"sync/atomic"
"time"

Expand All @@ -24,6 +23,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/envutil"
"github.com/cockroachdb/cockroach/pkg/util/hlc"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
Expand Down Expand Up @@ -639,10 +639,9 @@ func (q *Queue) MaybeWaitForPush(
)
var res *kvpb.PushTxnResponse
var err *kvpb.Error
labels := pprof.Labels("pushee", req.PusheeTxn.ID.String(), "pusher", pusherStr)
pprof.Do(ctx, labels, func(ctx context.Context) {
pprofutil.Do(ctx, func(ctx context.Context) {
res, err = q.waitForPush(ctx, req, push, pending)
})
}, "pushee", req.PusheeTxn.ID.String(), "pusher", pusherStr)
return res, err
}

Expand Down
1 change: 1 addition & 0 deletions pkg/rpc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ go_library(
"//pkg/util/metric/aggmetric",
"//pkg/util/netutil",
"//pkg/util/netutil/addr",
"//pkg/util/pprofutil",
"//pkg/util/stop",
"//pkg/util/syncutil",
"//pkg/util/sysutil",
Expand Down
6 changes: 3 additions & 3 deletions pkg/rpc/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"net"
"runtime/pprof"
"time"

"github.com/VividCortex/ewma"
Expand All @@ -19,6 +18,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/grpcutil"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/netutil"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/sysutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
Expand Down Expand Up @@ -269,9 +269,9 @@ func newPeer[Conn rpcConn](rpcCtx *Context, k peerKey, peerOpts *peerOptions[Con
b = circuit.NewBreaker(circuit.Options{
Name: "breaker", // log tags already represent `k`
AsyncProbe: func(report func(error), done func()) {
pprof.Do(ctx, pprof.Labels("tags", logtags.FromContext(ctx).String()), func(ctx context.Context) {
pprofutil.Do(ctx, func(ctx context.Context) {
p.launch(ctx, report, done)
})
}, "tags", logtags.FromContext(ctx).String())
},
})
p.b = b
Expand Down
7 changes: 3 additions & 4 deletions pkg/server/server_controller_channel_orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ package server

import (
"context"
"runtime/pprof"
"sync"

"github.com/cockroachdb/cockroach/pkg/base"
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/stop"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
Expand Down Expand Up @@ -330,9 +330,8 @@ func (o *channelOrchestrator) startControlledServer(
// Set the pprof label to more easily identify
// goroutines related to this virtual cluster. The
// calls here are exactly what pprof.Do does.
defer pprof.SetGoroutineLabels(ctx)
ctx = pprof.WithLabels(ctx, pprof.Labels("cluster", string(tenantName)))
pprof.SetGoroutineLabels(ctx)
ctx, reset := pprofutil.SetProfilerLabels(ctx, "cluster", string(tenantName))
defer reset()

// We want a context that gets cancelled when the server is
// shutting down, for the possible few cases in
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ go_library(
"//pkg/util/metric/aggmetric",
"//pkg/util/mon",
"//pkg/util/optional",
"//pkg/util/pprofutil",
"//pkg/util/pretty",
"//pkg/util/protoutil",
"//pkg/util/quotapool",
Expand Down Expand Up @@ -965,6 +966,7 @@ go_test(
"//pkg/util/metamorphic",
"//pkg/util/metric",
"//pkg/util/mon",
"//pkg/util/pprofutil",
"//pkg/util/protoutil",
"//pkg/util/randutil",
"//pkg/util/retry",
Expand Down
9 changes: 4 additions & 5 deletions pkg/sql/conn_executor_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"context"
"encoding/base64"
"fmt"
"runtime/pprof"
"strings"
"time"

Expand Down Expand Up @@ -69,6 +68,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/log/severity"
"github.com/cockroachdb/cockroach/pkg/util/metamorphic"
"github.com/cockroachdb/cockroach/pkg/util/metric"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/retry"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
Expand Down Expand Up @@ -4434,15 +4434,14 @@ func (ex *connExecutor) execWithProfiling(
} else {
stmtNoConstants = tree.FormatStatementHideConstants(ast)
}
labels := pprof.Labels(
pprofutil.Do(ctx, func(ctx context.Context) {
err = op(ctx)
},
"appname", ex.sessionData().ApplicationName,
"addr", remoteAddr,
"stmt.tag", ast.StatementTag(),
"stmt.no.constants", stmtNoConstants,
)
pprof.Do(ctx, labels, func(ctx context.Context) {
err = op(ctx)
})
} else {
err = op(ctx)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/jobs_profiler_execution_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"fmt"
"io"
"net/http"
"runtime/pprof"
"sort"
"strings"
"testing"
Expand All @@ -35,6 +34,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/util/httputil"
"github.com/cockroachdb/cockroach/pkg/util/leaktest"
"github.com/cockroachdb/cockroach/pkg/util/log"
"github.com/cockroachdb/cockroach/pkg/util/pprofutil"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/tracing"
"github.com/cockroachdb/cockroach/pkg/util/uuid"
Expand Down Expand Up @@ -208,10 +208,10 @@ func TestReadWriteProfilerExecutionDetails(t *testing.T) {
defer jobs.TestingRegisterConstructor(jobspb.TypeImport, func(j *jobs.Job, _ *cluster.Settings) jobs.Resumer {
return fakeExecResumer{
OnResume: func(ctx context.Context) error {
pprof.Do(ctx, pprof.Labels("foo", "bar"), func(ctx2 context.Context) {
pprofutil.Do(ctx, func(ctx2 context.Context) {
blockCh <- struct{}{}
<-continueCh
})
}, "foo", "bar")
return nil
},
}
Expand Down
Loading
Loading