mirror of https://github.com/milvus-io/milvus.git
enhance: span tracing of c++ part (#36205)
fix: https://github.com/milvus-io/milvus/issues/36204 Signed-off-by: longjiquan <jiquan.long@zilliz.com>pull/36240/head^2
parent
06a706e5f0
commit
f0f2fb4cf0
|
@ -124,6 +124,15 @@ StartSpan(const std::string& name, TraceContext* parentCtx) {
|
|||
return GetTracer()->StartSpan(name, opts);
|
||||
}
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
StartSpan(const std::string& name, const std::shared_ptr<trace::Span>& span) {
|
||||
trace::StartSpanOptions opts;
|
||||
if (span != nullptr) {
|
||||
opts.parent = span->GetContext();
|
||||
}
|
||||
return GetTracer()->StartSpan(name, opts);
|
||||
}
|
||||
|
||||
thread_local std::shared_ptr<trace::Span> local_span;
|
||||
void
|
||||
SetRootSpan(std::shared_ptr<trace::Span> span) {
|
||||
|
@ -132,6 +141,14 @@ SetRootSpan(std::shared_ptr<trace::Span> span) {
|
|||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
GetRootSpan() {
|
||||
if (enable_trace) {
|
||||
return local_span;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void
|
||||
CloseRootSpan() {
|
||||
if (enable_trace.load()) {
|
||||
|
@ -208,4 +225,34 @@ GetSpanIDAsHexStr(const TraceContext* ctx) {
|
|||
}
|
||||
}
|
||||
|
||||
AutoSpan::AutoSpan(const std::string& name,
|
||||
TraceContext* ctx,
|
||||
bool is_root_span)
|
||||
: is_root_span_(is_root_span) {
|
||||
span_ = StartSpan(name, ctx);
|
||||
if (is_root_span) {
|
||||
SetRootSpan(span_);
|
||||
}
|
||||
}
|
||||
|
||||
AutoSpan::AutoSpan(const std::string& name,
|
||||
const std::shared_ptr<trace::Span>& span)
|
||||
: is_root_span_(false) {
|
||||
span_ = StartSpan(name, span);
|
||||
}
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
AutoSpan::GetSpan() {
|
||||
return span_;
|
||||
}
|
||||
|
||||
AutoSpan::~AutoSpan() {
|
||||
if (span_ != nullptr) {
|
||||
span_->End();
|
||||
}
|
||||
if (is_root_span_) {
|
||||
CloseRootSpan();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace milvus::tracer
|
||||
|
|
|
@ -47,9 +47,15 @@ GetTracer();
|
|||
std::shared_ptr<trace::Span>
|
||||
StartSpan(const std::string& name, TraceContext* ctx = nullptr);
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
StartSpan(const std::string& name, const std::shared_ptr<trace::Span>& span);
|
||||
|
||||
void
|
||||
SetRootSpan(std::shared_ptr<trace::Span> span);
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
GetRootSpan();
|
||||
|
||||
void
|
||||
CloseRootSpan();
|
||||
|
||||
|
@ -77,21 +83,19 @@ GetSpanIDAsHexStr(const TraceContext* ctx);
|
|||
struct AutoSpan {
|
||||
explicit AutoSpan(const std::string& name,
|
||||
TraceContext* ctx = nullptr,
|
||||
bool is_root_span = false) {
|
||||
span_ = StartSpan(name, ctx);
|
||||
if (is_root_span) {
|
||||
SetRootSpan(span_);
|
||||
}
|
||||
}
|
||||
bool is_root_span = false);
|
||||
|
||||
~AutoSpan() {
|
||||
if (span_ != nullptr) {
|
||||
span_->End();
|
||||
}
|
||||
}
|
||||
explicit AutoSpan(const std::string& name,
|
||||
const std::shared_ptr<trace::Span>& span);
|
||||
|
||||
std::shared_ptr<trace::Span>
|
||||
GetSpan();
|
||||
|
||||
~AutoSpan();
|
||||
|
||||
private:
|
||||
std::shared_ptr<trace::Span> span_;
|
||||
bool is_root_span_;
|
||||
};
|
||||
|
||||
} // namespace milvus::tracer
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "exec/Task.h"
|
||||
#include "segcore/SegmentInterface.h"
|
||||
#include "query/groupby/SearchGroupByOperator.h"
|
||||
#include "common/Tracer.h"
|
||||
namespace milvus::query {
|
||||
|
||||
namespace impl {
|
||||
|
@ -279,6 +280,7 @@ ExecPlanNodeVisitor::visit(RetrievePlanNode& node) {
|
|||
|
||||
std::vector<int64_t> cache_offsets;
|
||||
if (node.filter_plannode_.has_value()) {
|
||||
tracer::AutoSpan _("Execute Filter", tracer::GetRootSpan());
|
||||
ExecuteExprNode(node.filter_plannode_.value(),
|
||||
segment,
|
||||
active_count,
|
||||
|
@ -304,6 +306,7 @@ ExecPlanNodeVisitor::visit(RetrievePlanNode& node) {
|
|||
}
|
||||
|
||||
retrieve_result.total_data_cnt_ = bitset_holder.size();
|
||||
tracer::AutoSpan _("Find Limit Pk", tracer::GetRootSpan());
|
||||
auto results_pair = segment->find_first(node.limit_, bitset_holder);
|
||||
retrieve_result.result_offsets_ = std::move(results_pair.first);
|
||||
retrieve_result.has_more_result = results_pair.second;
|
||||
|
|
|
@ -97,7 +97,7 @@ SegmentInternalInterface::Retrieve(tracer::TraceContext* trace_ctx,
|
|||
int64_t limit_size,
|
||||
bool ignore_non_pk) const {
|
||||
std::shared_lock lck(mutex_);
|
||||
tracer::AutoSpan span("Retrieve", trace_ctx, false);
|
||||
tracer::AutoSpan span("Retrieve", tracer::GetRootSpan());
|
||||
auto results = std::make_unique<proto::segcore::RetrieveResults>();
|
||||
query::ExecPlanNodeVisitor visitor(*this, timestamp);
|
||||
auto retrieve_results = visitor.get_retrieve_result(*plan->plan_node_);
|
||||
|
@ -144,7 +144,7 @@ SegmentInternalInterface::FillTargetEntry(
|
|||
int64_t size,
|
||||
bool ignore_non_pk,
|
||||
bool fill_ids) const {
|
||||
tracer::AutoSpan span("FillTargetEntry", trace_ctx, false);
|
||||
tracer::AutoSpan span("FillTargetEntry", tracer::GetRootSpan());
|
||||
|
||||
auto fields_data = results->mutable_fields_data();
|
||||
auto ids = results->mutable_ids();
|
||||
|
@ -240,7 +240,7 @@ SegmentInternalInterface::Retrieve(tracer::TraceContext* trace_ctx,
|
|||
const int64_t* offsets,
|
||||
int64_t size) const {
|
||||
std::shared_lock lck(mutex_);
|
||||
tracer::AutoSpan span("RetrieveByOffsets", trace_ctx, false);
|
||||
tracer::AutoSpan span("RetrieveByOffsets", tracer::GetRootSpan());
|
||||
auto results = std::make_unique<proto::segcore::RetrieveResults>();
|
||||
FillTargetEntry(trace_ctx, Plan, results, offsets, size, false, false);
|
||||
return results;
|
||||
|
|
|
@ -62,7 +62,7 @@ ReduceHelper::Reduce() {
|
|||
|
||||
void
|
||||
ReduceHelper::Marshal() {
|
||||
tracer::AutoSpan span("ReduceHelper::Marshal", trace_ctx_, false);
|
||||
tracer::AutoSpan span("ReduceHelper::Marshal", tracer::GetRootSpan());
|
||||
// get search result data blobs of slices
|
||||
search_result_data_blobs_ =
|
||||
std::make_unique<milvus::segcore::SearchResultDataBlobs>();
|
||||
|
@ -123,7 +123,8 @@ ReduceHelper::FilterInvalidSearchResult(SearchResult* search_result) {
|
|||
|
||||
void
|
||||
ReduceHelper::FillPrimaryKey() {
|
||||
tracer::AutoSpan span("ReduceHelper::FillPrimaryKey", trace_ctx_, false);
|
||||
tracer::AutoSpan span("ReduceHelper::FillPrimaryKey",
|
||||
tracer::GetRootSpan());
|
||||
// get primary keys for duplicates removal
|
||||
uint32_t valid_index = 0;
|
||||
for (auto& search_result : search_results_) {
|
||||
|
@ -146,8 +147,8 @@ ReduceHelper::FillPrimaryKey() {
|
|||
|
||||
void
|
||||
ReduceHelper::RefreshSearchResults() {
|
||||
tracer::AutoSpan span(
|
||||
"ReduceHelper::RefreshSearchResults", trace_ctx_, false);
|
||||
tracer::AutoSpan span("ReduceHelper::RefreshSearchResults",
|
||||
tracer::GetRootSpan());
|
||||
for (int i = 0; i < num_segments_; i++) {
|
||||
std::vector<int64_t> real_topks(total_nq_, 0);
|
||||
auto search_result = search_results_[i];
|
||||
|
@ -184,7 +185,7 @@ ReduceHelper::RefreshSingleSearchResult(SearchResult* search_result,
|
|||
|
||||
void
|
||||
ReduceHelper::FillEntryData() {
|
||||
tracer::AutoSpan span("ReduceHelper::FillEntryData", trace_ctx_, false);
|
||||
tracer::AutoSpan span("ReduceHelper::FillEntryData", tracer::GetRootSpan());
|
||||
for (auto search_result : search_results_) {
|
||||
auto segment = static_cast<milvus::segcore::SegmentInterface*>(
|
||||
search_result->segment_);
|
||||
|
@ -254,7 +255,8 @@ ReduceHelper::ReduceSearchResultForOneNQ(int64_t qi,
|
|||
|
||||
void
|
||||
ReduceHelper::ReduceResultData() {
|
||||
tracer::AutoSpan span("ReduceHelper::ReduceResultData", trace_ctx_, false);
|
||||
tracer::AutoSpan span("ReduceHelper::ReduceResultData",
|
||||
tracer::GetRootSpan());
|
||||
for (int i = 0; i < num_segments_; i++) {
|
||||
auto search_result = search_results_[i];
|
||||
auto result_count = search_result->get_total_result_count();
|
||||
|
|
Loading…
Reference in New Issue