Skip to content

Commit

Permalink
Optimize TSpan methods to prevent unneeded object construction KIKIMR…
Browse files Browse the repository at this point in the history
…-15449 (#575)
  • Loading branch information
alexvru authored Dec 19, 2023
1 parent 377bc60 commit fbf18bb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ydb/core/blobstorage/backpressure/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ void TBlobStorageQueue::SendToVDisk(const TActorContext& ctx, const TActorId& re
++*QueueItemsSent;

// send item
item.Span.Event("SendToVDisk", {{
item.Span && item.Span.Event("SendToVDisk", {
{"VDiskOrderNumber", vdiskOrderNumber}
}});
});
item.Event.SendToVDisk(ctx, remoteVDisk, item.QueueCookie, item.MsgId, item.SequenceId, sendMeCostSettings,
item.Span.GetTraceId(), ClientId, item.ProcessingTimer);

Expand Down
2 changes: 1 addition & 1 deletion ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ LWTRACE_USING(BLOBSTORAGE_PROVIDER);
"Writer: bootstrap: id# %s chunkId# %u offset# %u storedBlobSize# %u "
"writtenSize# %u", HugeSlot.ToString().data(), chunkId, offset,
storedBlobSize, writtenSize));
Span.Event("Send_TEvChunkWrite", NWilson::TKeyValueList{{{"ChunkId", chunkId}, {"Offset", offset}, {"WrittenSize", writtenSize}}});
Span && Span.Event("Send_TEvChunkWrite", {{"ChunkId", chunkId}, {"Offset", offset}, {"WrittenSize", writtenSize}});
auto ev = std::make_unique<NPDisk::TEvChunkWrite>(HugeKeeperCtx->PDiskCtx->Dsk->Owner,
HugeKeeperCtx->PDiskCtx->Dsk->OwnerRound, chunkId, offset,
partsPtr, Cookie, true, GetWritePriority(), false);
Expand Down
5 changes: 3 additions & 2 deletions ydb/core/tablet_flat/flat_executor_txloglogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,9 @@ TLogicRedo::TCommitRWTransactionResult TLogicRedo::CommitRWTransaction(

Batch->Commit->FirstTx->TxSpan.Attribute("BatchSize", batchSize);

seat->TxSpan.Attribute("Batched", true);
seat->TxSpan.Link(Batch->Commit->FirstTx->GetTxTraceId(), {});
seat->TxSpan
.Attribute("Batched", true)
.Link(Batch->Commit->FirstTx->GetTxTraceId());
}

Batch->Commit->PushTx(seat.Get());
Expand Down
32 changes: 23 additions & 9 deletions ydb/library/actors/wilson/wilson_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,29 +159,32 @@ namespace NWilson {
return *this;
}

TSpan& Name(TString name) {
template<typename T>
TSpan& Name(T&& name) {
if (Y_UNLIKELY(*this)) {
Data->Span.set_name(std::move(name));
Data->Span.set_name(std::forward<T>(name));
} else {
VerifyNotSent();
}
return *this;
}

TSpan& Attribute(TString name, TAttributeValue value) {
template<typename T, typename T1>
TSpan& Attribute(T&& name, T1&& value) {
if (Y_UNLIKELY(*this)) {
SerializeKeyValue(std::move(name), std::move(value), Data->Span.add_attributes());
SerializeKeyValue(std::forward<T>(name), std::forward<T1>(value), Data->Span.add_attributes());
} else {
VerifyNotSent();
}
return *this;
}

TSpan& Event(TString name, TKeyValueList attributes) {
template<typename T, typename T1 = std::initializer_list<std::pair<TString, TAttributeValue>>>
TSpan& Event(T&& name, T1&& attributes) {
if (Y_UNLIKELY(*this)) {
auto *event = Data->Span.add_events();
event->set_time_unix_nano(TimeUnixNano());
event->set_name(std::move(name));
event->set_name(std::forward<T>(name));
for (auto&& [key, value] : attributes) {
SerializeKeyValue(std::move(key), std::move(value), event->add_attributes());
}
Expand All @@ -191,7 +194,13 @@ namespace NWilson {
return *this;
}

TSpan& Link(const TTraceId& traceId, TKeyValueList attributes) {
template<typename T>
TSpan& Event(T&& name) {
return Event(std::forward<T>(name), {});
}

template<typename T = std::initializer_list<std::pair<TString, TAttributeValue>>>
TSpan& Link(const TTraceId& traceId, T&& attributes) {
if (Y_UNLIKELY(*this)) {
auto *link = Data->Span.add_links();
link->set_trace_id(traceId.GetTraceIdPtr(), traceId.GetTraceIdSize());
Expand All @@ -205,6 +214,10 @@ namespace NWilson {
return *this;
}

TSpan& Link(const TTraceId& traceId) {
return Link(traceId, {});
}

void EndOk() {
if (Y_UNLIKELY(*this)) {
auto *status = Data->Span.mutable_status();
Expand All @@ -215,11 +228,12 @@ namespace NWilson {
}
}

void EndError(TString error) {
template<typename T>
void EndError(T&& error) {
if (Y_UNLIKELY(*this)) {
auto *status = Data->Span.mutable_status();
status->set_code(NTraceProto::Status::STATUS_CODE_ERROR);
status->set_message(std::move(error));
status->set_message(std::forward<T>(error));
End();
} else {
VerifyNotSent();
Expand Down

0 comments on commit fbf18bb

Please sign in to comment.