diff options
author | Alexander Rutkovsky <alexvru@ydb.tech> | 2023-12-19 15:59:40 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-19 15:59:40 +0300 |
commit | fbf18bba656ff942e8209d4df10bd85a19961666 (patch) | |
tree | 583858494efd1971ce3a3cc962cdff329e264555 | |
parent | 377bc60f8765f046c1475ad69a5fc048786044dc (diff) | |
download | ydb-fbf18bba656ff942e8209d4df10bd85a19961666.tar.gz |
Optimize TSpan methods to prevent unneeded object construction KIKIMR-15449 (#575)
-rw-r--r-- | ydb/core/blobstorage/backpressure/queue.cpp | 4 | ||||
-rw-r--r-- | ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp | 2 | ||||
-rw-r--r-- | ydb/core/tablet_flat/flat_executor_txloglogic.cpp | 5 | ||||
-rw-r--r-- | ydb/library/actors/wilson/wilson_span.h | 32 |
4 files changed, 29 insertions, 14 deletions
diff --git a/ydb/core/blobstorage/backpressure/queue.cpp b/ydb/core/blobstorage/backpressure/queue.cpp index fc83187df6a..b2402a32c67 100644 --- a/ydb/core/blobstorage/backpressure/queue.cpp +++ b/ydb/core/blobstorage/backpressure/queue.cpp @@ -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); diff --git a/ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp b/ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp index bf75aeaf74a..79acac7304e 100644 --- a/ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp +++ b/ydb/core/blobstorage/vdisk/huge/blobstorage_hullhuge.cpp @@ -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); diff --git a/ydb/core/tablet_flat/flat_executor_txloglogic.cpp b/ydb/core/tablet_flat/flat_executor_txloglogic.cpp index d3aa1160d59..24ad5c0a9d2 100644 --- a/ydb/core/tablet_flat/flat_executor_txloglogic.cpp +++ b/ydb/core/tablet_flat/flat_executor_txloglogic.cpp @@ -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()); diff --git a/ydb/library/actors/wilson/wilson_span.h b/ydb/library/actors/wilson/wilson_span.h index 9cbf0f8c2d5..3db7786a0bf 100644 --- a/ydb/library/actors/wilson/wilson_span.h +++ b/ydb/library/actors/wilson/wilson_span.h @@ -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()); } @@ -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()); @@ -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(); @@ -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(); |