@@ -13,6 +13,7 @@ package kvserver
1313import (
1414 "context"
1515 "reflect"
16+ "runtime/pprof"
1617
1718 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/batcheval"
1819 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/concurrency"
@@ -24,6 +25,7 @@ import (
2425 "github.com/cockroachdb/cockroach/pkg/kv/kvserver/txnwait"
2526 "github.com/cockroachdb/cockroach/pkg/roachpb"
2627 "github.com/cockroachdb/cockroach/pkg/settings"
28+ "github.com/cockroachdb/cockroach/pkg/settings/cluster"
2729 "github.com/cockroachdb/cockroach/pkg/util/circuit"
2830 "github.com/cockroachdb/cockroach/pkg/util/hlc"
2931 "github.com/cockroachdb/cockroach/pkg/util/log"
@@ -109,38 +111,17 @@ func (r *Replica) Send(
109111// SendWithWriteBytes is the implementation of Send with an additional
110112// *StoreWriteBytes return value.
111113func (r * Replica ) SendWithWriteBytes (
112- ctx context.Context , ba roachpb.BatchRequest ,
114+ ctx context.Context , req roachpb.BatchRequest ,
113115) (* roachpb.BatchResponse , * StoreWriteBytes , * roachpb.Error ) {
114- return r .sendWithoutRangeID (ctx , & ba )
115- }
116-
117- // sendWithoutRangeID used to be called sendWithRangeID, accepted a `_forStacks
118- // roachpb.RangeID` argument, and had the description below. Ever since Go
119- // switched to the register-based calling convention though, this stopped
120- // working, giving essentially random numbers in the goroutine dumps that were
121- // misleading. It has thus been "disarmed" until Go produces useful values
122- // again.
123- //
124- // See (internal): https://cockroachlabs.slack.com/archives/G01G8LK77DK/p1641478596004700
125- //
126- // sendWithRangeID takes an unused rangeID argument so that the range
127- // ID will be accessible in stack traces (both in panics and when
128- // sampling goroutines from a live server). This line is subject to
129- // the whims of the compiler and it can be difficult to find the right
130- // value, but as of this writing the following example shows a stack
131- // while processing range 21 (0x15) (the first occurrence of that
132- // number is the rangeID argument, the second is within the encoded
133- // BatchRequest, although we don't want to rely on that occurring
134- // within the portion printed in the stack trace):
135- //
136- // github.com/cockroachdb/cockroach/pkg/storage.(*Replica).sendWithRangeID(0xc420d1a000, 0x64bfb80, 0xc421564b10, 0x15, 0x153fd4634aeb0193, 0x0, 0x100000001, 0x1, 0x15, 0x0, ...)
137- func (r * Replica ) sendWithoutRangeID (
138- ctx context.Context , ba * roachpb.BatchRequest ,
139- ) (_ * roachpb.BatchResponse , _ * StoreWriteBytes , rErr * roachpb.Error ) {
140- var br * roachpb.BatchResponse
141-
116+ if r .store .cfg .Settings .CPUProfileType () == cluster .CPUProfileWithLabels {
117+ defer pprof .SetGoroutineLabels (ctx )
118+ // Note: the defer statement captured the previous context.
119+ ctx = pprof .WithLabels (ctx , pprof .Labels ("range_str" , r .rangeStr .String ()))
120+ pprof .SetGoroutineLabels (ctx )
121+ }
142122 // Add the range log tag.
143123 ctx = r .AnnotateCtx (ctx )
124+ ba := & req
144125
145126 // Record summary throughput information about the batch request for
146127 // accounting.
@@ -177,6 +158,7 @@ func (r *Replica) sendWithoutRangeID(
177158 }
178159
179160 // Differentiate between read-write, read-only, and admin.
161+ var br * roachpb.BatchResponse
180162 var pErr * roachpb.Error
181163 var writeBytes * StoreWriteBytes
182164 if isReadOnly {
0 commit comments