Autonomy Software C++ 24.5.1
Welcome to the Autonomy Software repository of the Mars Rover Design Team (MRDT) at Missouri University of Science and Technology (Missouri S&T)! API reference contains the source code and other resources for the development of the autonomy software for our Mars rover. The Autonomy Software project aims to compete in the University Rover Challenge (URC) by demonstrating advanced autonomous capabilities and robust navigation algorithms.
Loading...
Searching...
No Matches
duckdb::OperatorProfiler Class Reference

The OperatorProfiler measures timings of individual operators This class exists once for all operators and collects OperatorInfo for each operator. More...

#include <duckdb.hpp>

Collaboration diagram for duckdb::OperatorProfiler:

Public Member Functions

DUCKDB_API OperatorProfiler (ClientContext &context)
DUCKDB_API void StartOperator (optional_ptr< const PhysicalOperator > phys_op)
DUCKDB_API void EndOperator (optional_ptr< DataChunk > chunk)
DUCKDB_API void FinishSource (GlobalSourceState &gstate, LocalSourceState &lstate)
DUCKDB_API void Flush (const PhysicalOperator &phys_op)
 Adds the timings in the OperatorProfiler (tree) to the QueryProfiler (tree).
DUCKDB_API OperatorInformation & GetOperatorInfo (const PhysicalOperator &phys_op)
DUCKDB_API bool OperatorInfoIsInitialized (const PhysicalOperator &phys_op)

Public Attributes

ClientContext & context

Private Attributes

bool enabled
 Whether or not the profiler is enabled.
profiler_settings_t settings
 Sub-settings for the operator profiler.
Profiler op
 The timer used to time the execution time of the individual Physical Operators.
optional_ptr< const PhysicalOperator > active_operator
 The stack of Physical Operators that are currently active.
reference_map_t< const PhysicalOperator, OperatorInformation > operator_infos
 A mapping of physical operators to profiled operator information.

Friends

class QueryProfiler

Detailed Description

The OperatorProfiler measures timings of individual operators This class exists once for all operators and collects OperatorInfo for each operator.

Constructor & Destructor Documentation

◆ OperatorProfiler()

duckdb::OperatorProfiler::OperatorProfiler ( ClientContext & context)
explicit
295349 : context(context) {
295350 enabled = QueryProfiler::Get(context).IsEnabled();
295351 auto &context_metrics = ClientConfig::GetConfig(context).profiler_settings;
295352
295353 // Expand.
295354 for (const auto metric : context_metrics) {
295355 settings.insert(metric);
295357 }
295358
295359 // Reduce.
295360 auto root_metrics = MetricsUtils::GetRootScopeMetrics();
295361 for (const auto metric : root_metrics) {
295362 settings.erase(metric);
295363 }
295364}
bool enabled
Whether or not the profiler is enabled.
Definition duckdb.hpp:36805
profiler_settings_t settings
Sub-settings for the operator profiler.
Definition duckdb.hpp:36807
static void Expand(profiler_settings_t &settings, const MetricType metric)
Expand metrics depending on the collection of other metrics.
Definition duckdb.cpp:294692

◆ ~OperatorProfiler()

duckdb::OperatorProfiler::~OperatorProfiler ( )
inline
36787 {
36788 }

Member Function Documentation

◆ StartOperator()

void duckdb::OperatorProfiler::StartOperator ( optional_ptr< const PhysicalOperator > phys_op)
295366 {
295367 if (!enabled) {
295368 return;
295369 }
295370 if (active_operator) {
295371 throw InternalException("OperatorProfiler: Attempting to call StartOperator while another operator is active");
295372 }
295373 active_operator = phys_op;
295374
295375 if (!settings.empty()) {
295376 if (ProfilingInfo::Enabled(settings, MetricType::EXTRA_INFO)) {
295377 if (!OperatorInfoIsInitialized(*active_operator)) {
295378 // first time calling into this operator - fetch the info
295379 auto &info = GetOperatorInfo(*active_operator);
295380 auto params = active_operator->ParamsToString();
295381 info.extra_info = params;
295382 }
295383 }
295384
295385 // Start the timing of the current operator.
295386 if (ProfilingInfo::Enabled(settings, MetricType::OPERATOR_TIMING)) {
295387 op.Start();
295388 }
295389 }
295390}
optional_ptr< const PhysicalOperator > active_operator
The stack of Physical Operators that are currently active.
Definition duckdb.hpp:36812
Profiler op
The timer used to time the execution time of the individual Physical Operators.
Definition duckdb.hpp:36810
static bool Enabled(const profiler_settings_t &settings, const MetricType metric)
Returns true, if the query profiler must collect this metric.
Definition duckdb.cpp:294685
PyParams params(const std::string &tag, const std::string &model, const std::string &weights, const std::string &device)

◆ EndOperator()

void duckdb::OperatorProfiler::EndOperator ( optional_ptr< DataChunk > chunk)
295392 {
295393 if (!enabled) {
295394 return;
295395 }
295396 if (!active_operator) {
295397 throw InternalException("OperatorProfiler: Attempting to call EndOperator while no operator is active");
295398 }
295399
295400 if (!settings.empty()) {
295401 auto &info = GetOperatorInfo(*active_operator);
295402 if (ProfilingInfo::Enabled(settings, MetricType::OPERATOR_TIMING)) {
295403 op.End();
295404 info.AddMetric(MetricType::OPERATOR_TIMING, op.Elapsed());
295405 }
295406 if (ProfilingInfo::Enabled(settings, MetricType::OPERATOR_CARDINALITY) && chunk) {
295407 info.AddMetric(MetricType::OPERATOR_CARDINALITY, chunk->size());
295408 }
295409 if (ProfilingInfo::Enabled(settings, MetricType::RESULT_SET_SIZE) && chunk) {
295410 auto result_set_size = chunk->GetAllocationSize();
295411 info.AddMetric(MetricType::RESULT_SET_SIZE, result_set_size);
295412 }
295413 if (ProfilingInfo::Enabled(settings, MetricType::SYSTEM_PEAK_BUFFER_MEMORY)) {
295414 auto used_memory = BufferManager::GetBufferManager(context).GetBufferPool().GetUsedMemory(false);
295415 info.AddMetric(MetricType::SYSTEM_PEAK_BUFFER_MEMORY, used_memory);
295416 }
295417 if (ProfilingInfo::Enabled(settings, MetricType::SYSTEM_PEAK_TEMP_DIR_SIZE)) {
295418 auto used_swap = BufferManager::GetBufferManager(context).GetUsedSwap();
295419 info.AddMetric(MetricType::SYSTEM_PEAK_TEMP_DIR_SIZE, used_swap);
295420 }
295421 }
295422 active_operator = nullptr;
295423}

◆ FinishSource()

void duckdb::OperatorProfiler::FinishSource ( GlobalSourceState & gstate,
LocalSourceState & lstate )
295425 {
295426 if (!enabled) {
295427 return;
295428 }
295429 if (!active_operator) {
295430 throw InternalException("OperatorProfiler: Attempting to call FinishSource while no operator is active");
295431 }
295432 if (!settings.empty()) {
295433 if (ProfilingInfo::Enabled(settings, MetricType::EXTRA_INFO)) {
295434 // we're emitting extra info - get the extra source info
295435 auto &info = GetOperatorInfo(*active_operator);
295436 auto extra_info = active_operator->ExtraSourceParams(gstate, lstate);
295437 for (auto &new_info : extra_info) {
295438 auto entry = info.extra_info.find(new_info.first);
295439 if (entry != info.extra_info.end()) {
295440 // entry exists - override
295441 entry->second = std::move(new_info.second);
295442 } else {
295443 // entry does not exist yet - insert
295444 info.extra_info.insert(std::move(new_info));
295445 }
295446 }
295447 }
295448 if (ProfilingInfo::Enabled(settings, MetricType::OPERATOR_ROWS_SCANNED) &&
295449 active_operator.get()->type == PhysicalOperatorType::TABLE_SCAN) {
295450 const auto &table_scan = active_operator->Cast<PhysicalTableScan>();
295451 const auto rows_scanned = table_scan.GetRowsScanned(gstate, lstate);
295452 auto &info = GetOperatorInfo(*active_operator);
295453 if (rows_scanned.IsValid()) {
295454 // Use exact value if available.
295455 info.AddMetric(MetricType::OPERATOR_ROWS_SCANNED, rows_scanned.GetIndex());
295456 } else {
295457 // Otherwise estimate as the cardinality of the table scan, if there is no exact value available.
295458 auto &bind_data = table_scan.bind_data;
295459 if (bind_data && table_scan.function.cardinality) {
295460 auto cardinality = table_scan.function.cardinality(context, &(*bind_data));
295461 if (cardinality && cardinality->has_estimated_cardinality) {
295462 info.AddMetric(MetricType::OPERATOR_ROWS_SCANNED, cardinality->estimated_cardinality);
295463 }
295464 }
295465 }
295466 }
295467 }
295468}

◆ Flush()

void duckdb::OperatorProfiler::Flush ( const PhysicalOperator & phys_op)

Adds the timings in the OperatorProfiler (tree) to the QueryProfiler (tree).

295486 {
295487 auto entry = operator_infos.find(phys_op);
295488 if (entry == operator_infos.end()) {
295489 return;
295490 }
295491
295492 auto &info = operator_infos.find(phys_op)->second;
295493 info.name = phys_op.GetName();
295494}
reference_map_t< const PhysicalOperator, OperatorInformation > operator_infos
A mapping of physical operators to profiled operator information.
Definition duckdb.hpp:36814

◆ GetOperatorInfo()

OperatorInformation & duckdb::OperatorProfiler::GetOperatorInfo ( const PhysicalOperator & phys_op)
295475 {
295476 auto entry = operator_infos.find(phys_op);
295477 if (entry != operator_infos.end()) {
295478 return entry->second;
295479 }
295480
295481 // Add a new entry.
295482 operator_infos[phys_op] = OperatorInformation();
295483 return operator_infos[phys_op];
295484}

◆ OperatorInfoIsInitialized()

bool duckdb::OperatorProfiler::OperatorInfoIsInitialized ( const PhysicalOperator & phys_op)
295470 {
295471 auto entry = operator_infos.find(phys_op);
295472 return entry != operator_infos.end();
295473}

The documentation for this class was generated from the following files: