Skip to content

Commit 81a10d0

Browse files
craig[bot]tbg
andcommitted
Merge #147756
147756: kvserver: add useful execution trace regions r=tbg a=tbg This PR adds regions for the range on which a BatchRequest executes, as well as regions indicating the method of each request while it's being evaluated. Some samples from running this script: ```bash #!/bin/bash set -euo pipefail c=local-tpcc wh=10 (roachprod create -n 4 $c || true) &> /dev/null roachprod stop $c roachprod put $c cockroach roachprod start $c:1-3 roachprod run $c:4 -- "if [ ! -f loaded ]; then ./cockroach workload init tpcc --warehouses $wh {pgurl:1-3} && touch loaded; fi" roachprod run $c:4 -- ./cockroach workload run tpcc --warehouses $wh --concurrency 10 {pgurl:1-3} ``` and then ``` curl -o regiontrace.bin "$(roachprod adminui local-tpcc:1)debug/pprof/trace?seconds=10" gotraceui regiontrace.bin ``` <img width="735" alt="image" src="https://github.com/user-attachments/assets/938b871b-c5c5-4960-9cd2-420ade908a2b" /> <img width="992" alt="image" src="https://github.com/user-attachments/assets/012ed3c6-75d6-4fde-b00e-f0bf731f172e" /> Related to #146873. Epic: none Release note: none Co-authored-by: Tobias Grieger <[email protected]>
2 parents 4803923 + 10a83ba commit 81a10d0

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/kv/kvserver/replica_evaluate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"bytes"
1010
"context"
1111
"fmt"
12+
"runtime/trace"
1213

1314
"github.com/cockroachdb/cockroach/pkg/keys"
1415
"github.com/cockroachdb/cockroach/pkg/kv/kvnemesis/kvnemesisutil"
@@ -335,9 +336,17 @@ func evaluateBatch(
335336
// Note that `reply` is populated even when an error is returned: it
336337
// may carry a response transaction and in the case of WriteTooOldError
337338
// (which is sometimes deferred) it is fully populated.
339+
var reg *trace.Region
340+
if trace.IsEnabled() {
341+
regName := args.Method().String() // NB: this is cheap, no allocs
342+
reg = trace.StartRegion(ctx, regName)
343+
}
338344
curResult, err := evaluateCommand(
339345
ctx, readWriter, rec, ms, ss, baHeader, args, reply, g, st, ui, evalPath, omitInRangefeeds,
340346
)
347+
if reg != nil {
348+
reg.End()
349+
}
341350

342351
if filter := rec.EvalKnobs().TestingPostEvalFilter; filter != nil {
343352
filterArgs := kvserverbase.FilterArgs{

pkg/kv/kvserver/replica_send.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"reflect"
1111
"runtime/pprof"
12+
"runtime/trace"
1213
"time"
1314

1415
"github.com/cockroachdb/cockroach/pkg/kv/kvpb"
@@ -128,6 +129,9 @@ func (r *Replica) SendWithWriteBytes(
128129
ctx = pprof.WithLabels(ctx, pprof.Labels("range_str", r.rangeStr.ID()))
129130
pprof.SetGoroutineLabels(ctx)
130131
}
132+
if trace.IsEnabled() {
133+
defer trace.StartRegion(ctx, r.rangeStr.String() /* cheap */).End()
134+
}
131135
// Add the range log tag.
132136
ctx = r.AnnotateCtx(ctx)
133137

0 commit comments

Comments
 (0)