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::ProfilingInfo Class Reference

Public Member Functions

 ProfilingInfo (const profiler_settings_t &n_settings, const idx_t depth=0)
 ProfilingInfo (ProfilingInfo &)=default
ProfilingInfo & operator= (ProfilingInfo const &)=default
void ResetMetrics ()
string GetMetricAsString (const MetricType metric) const
void WriteMetricsToLog (ClientContext &context)
void WriteMetricsToJSON (duckdb_yyjson::yyjson_mut_doc *doc, duckdb_yyjson::yyjson_mut_val *destination)
template<class METRIC_TYPE>
METRIC_TYPE GetMetricValue (const MetricType type) const
template<class METRIC_TYPE>
void MetricUpdate (const MetricType type, const Value &value, const std::function< METRIC_TYPE(const METRIC_TYPE &, const METRIC_TYPE &)> &update_fun)
template<class METRIC_TYPE>
void MetricUpdate (const MetricType type, const METRIC_TYPE &value, const std::function< METRIC_TYPE(const METRIC_TYPE &, const METRIC_TYPE &)> &update_fun)
template<class METRIC_TYPE>
void MetricSum (const MetricType type, const Value &value)
template<class METRIC_TYPE>
void MetricSum (const MetricType type, const METRIC_TYPE &value)
template<class METRIC_TYPE>
void MetricMax (const MetricType type, const Value &value)
template<class METRIC_TYPE>
void MetricMax (const MetricType type, const METRIC_TYPE &value)
template<>
InsertionOrderPreservingMap< string > GetMetricValue (const MetricType type) const

Static Public Member Functions

static bool Enabled (const profiler_settings_t &settings, const MetricType metric)
 Returns true, if the query profiler must collect this metric.
static void Expand (profiler_settings_t &settings, const MetricType metric)
 Expand metrics depending on the collection of other metrics.

Public Attributes

profiler_settings_t settings
 Enabling a metric adds it to this set.
profiler_settings_t expanded_settings
 This set contains the expanded to-be-collected metrics, which can differ from 'settings'.
profiler_metrics_t metrics
 Contains all enabled metrics.

Constructor & Destructor Documentation

◆ ProfilingInfo()

duckdb::ProfilingInfo::ProfilingInfo ( const profiler_settings_t & n_settings,
const idx_t depth = 0 )
explicit
294648 : settings(n_settings) {
294649 // Expand.
294650 if (depth > 0) {
294651 settings.insert(MetricType::OPERATOR_NAME);
294652 settings.insert(MetricType::OPERATOR_TYPE);
294653 }
294654 for (const auto &metric : settings) {
294655 Expand(expanded_settings, metric);
294656 }
294657
294658 // Reduce.
294659 if (depth == 0) {
294660 auto op_metrics = MetricsUtils::GetOperatorMetrics();
294661 for (const auto metric : op_metrics) {
294662 settings.erase(metric);
294663 }
294664 } else {
294665 auto root_metrics = MetricsUtils::GetRootScopeMetrics();
294666 for (const auto metric : root_metrics) {
294667 settings.erase(metric);
294668 }
294669 }
294670 ResetMetrics();
294671}
static void Expand(profiler_settings_t &settings, const MetricType metric)
Expand metrics depending on the collection of other metrics.
Definition duckdb.cpp:294692
profiler_settings_t expanded_settings
This set contains the expanded to-be-collected metrics, which can differ from 'settings'.
Definition duckdb.hpp:36302
profiler_settings_t settings
Enabling a metric adds it to this set.
Definition duckdb.hpp:36300

Member Function Documentation

◆ ResetMetrics()

void duckdb::ProfilingInfo::ResetMetrics ( )
294673 {
294674 metrics.clear();
294675 for (auto &metric : expanded_settings) {
294676 if (MetricsUtils::IsOptimizerMetric(metric) || MetricsUtils::IsPhaseTimingMetric(metric)) {
294677 metrics[metric] = Value::CreateValue(0.0);
294678 continue;
294679 }
294680
294681 ProfilingUtils::SetMetricToDefault(metrics, metric);
294682 }
294683}
profiler_metrics_t metrics
Contains all enabled metrics.
Definition duckdb.hpp:36304

◆ Enabled()

bool duckdb::ProfilingInfo::Enabled ( const profiler_settings_t & settings,
const MetricType metric )
static

Returns true, if the query profiler must collect this metric.

294685 {
294686 if (settings.find(metric) != settings.end()) {
294687 return true;
294688 }
294689 return false;
294690}
Here is the caller graph for this function:

◆ Expand()

void duckdb::ProfilingInfo::Expand ( profiler_settings_t & settings,
const MetricType metric )
static

Expand metrics depending on the collection of other metrics.

294692 {
294693 settings.insert(metric);
294694
294695 switch (metric) {
294696 case MetricType::CPU_TIME:
294697 settings.insert(MetricType::OPERATOR_TIMING);
294698 return;
294699 case MetricType::CUMULATIVE_CARDINALITY:
294700 settings.insert(MetricType::OPERATOR_CARDINALITY);
294701 return;
294702 case MetricType::CUMULATIVE_ROWS_SCANNED:
294703 settings.insert(MetricType::OPERATOR_ROWS_SCANNED);
294704 return;
294705 case MetricType::CUMULATIVE_OPTIMIZER_TIMING:
294706 case MetricType::ALL_OPTIMIZERS: {
294707 auto optimizer_metrics = MetricsUtils::GetOptimizerMetrics();
294708 for (const auto optimizer_metric : optimizer_metrics) {
294709 settings.insert(optimizer_metric);
294710 }
294711 return;
294712 }
294713 default:
294714 return;
294715 }
294716}

◆ GetMetricAsString()

string duckdb::ProfilingInfo::GetMetricAsString ( const MetricType metric) const
294718 {
294719 if (!Enabled(settings, metric)) {
294720 throw InternalException("Metric %s not enabled", EnumUtil::ToString(metric));
294721 }
294722
294723 // The metric cannot be NULL and must be initialized.
294724 D_ASSERT(!metrics.at(metric).IsNull());
294725 if (metric == MetricType::OPERATOR_TYPE) {
294726 const auto type = PhysicalOperatorType(metrics.at(metric).GetValue<uint8_t>());
294727 return EnumUtil::ToString(type);
294728 }
294729 return metrics.at(metric).ToString();
294730}
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

◆ WriteMetricsToLog()

void duckdb::ProfilingInfo::WriteMetricsToLog ( ClientContext & context)
294732 {
294733 auto &logger = Logger::Get(context);
294734 if (logger.ShouldLog(MetricsLogType::NAME, MetricsLogType::LEVEL)) {
294735 for (auto &metric : settings) {
294736 logger.WriteLog(MetricsLogType::NAME, MetricsLogType::LEVEL,
294737 MetricsLogType::ConstructLogMessage(metric, metrics[metric]));
294738 }
294739 }
294740}

◆ WriteMetricsToJSON()

void duckdb::ProfilingInfo::WriteMetricsToJSON ( duckdb_yyjson::yyjson_mut_doc * doc,
duckdb_yyjson::yyjson_mut_val * destination )
294742 {
294743 for (auto &metric : settings) {
294744 auto metric_str = StringUtil::Lower(EnumUtil::ToString(metric));
294745 auto key_val = yyjson_mut_strcpy(doc, metric_str.c_str());
294746 auto key_ptr = yyjson_mut_get_str(key_val);
294747
294748 if (metric == MetricType::EXTRA_INFO) {
294749 auto extra_info_obj = yyjson_mut_obj(doc);
294750
294751 auto extra_info = metrics.at(metric);
294752 auto children = MapValue::GetChildren(extra_info);
294753 for (auto &child : children) {
294754 auto struct_children = StructValue::GetChildren(child);
294755 auto key = struct_children[0].GetValue<string>();
294756 auto value = struct_children[1].GetValue<string>();
294757
294758 auto key_mut = unsafe_yyjson_mut_strncpy(doc, key.c_str(), key.size());
294759 auto value_mut = unsafe_yyjson_mut_strncpy(doc, value.c_str(), value.size());
294760
294761 auto splits = StringUtil::Split(value_mut, "\n");
294762 if (splits.size() > 1) {
294763 auto list_items = yyjson_mut_arr(doc);
294764 for (auto &split : splits) {
294765 yyjson_mut_arr_add_strcpy(doc, list_items, split.c_str());
294766 }
294767 yyjson_mut_obj_add_val(doc, extra_info_obj, key_mut, list_items);
294768 } else {
294769 yyjson_mut_obj_add_strcpy(doc, extra_info_obj, key_mut, value_mut);
294770 }
294771 }
294772 yyjson_mut_obj_add_val(doc, dest, key_ptr, extra_info_obj);
294773 continue;
294774 }
294775
294776 // The metric cannot be NULL, and should have been 0 initialized.
294777 D_ASSERT(!metrics[metric].IsNull());
294778
294779 if (MetricsUtils::IsOptimizerMetric(metric) || MetricsUtils::IsPhaseTimingMetric(metric)) {
294780 yyjson_mut_obj_add_real(doc, dest, key_ptr, metrics[metric].GetValue<double>());
294781 continue;
294782 }
294783
294784 ProfilingUtils::MetricToJson(doc, dest, key_ptr, metrics, metric);
294785 }
294786}
static DUCKDB_API vector< string > Split(const string &str, char delimiter)
Split the input string based on newline char.
Definition duckdb.cpp:109734
static DUCKDB_API string Lower(const string &str)
Convert a string to lowercase.
Definition duckdb.cpp:109630
yyjson_api_inline bool yyjson_mut_obj_add_real(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, double val)
Definition duckdb.cpp:43964
yyjson_api_inline yyjson_mut_val * yyjson_mut_obj(yyjson_mut_doc *doc)
Definition duckdb.cpp:43608
yyjson_api_inline const char * yyjson_mut_get_str(yyjson_mut_val *val)
Definition duckdb.cpp:42542
yyjson_api_inline yyjson_mut_val * yyjson_mut_arr(yyjson_mut_doc *doc)
Definition duckdb.cpp:42941
yyjson_api_inline bool yyjson_mut_arr_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *arr, const char *str)
Definition duckdb.cpp:43444
yyjson_api_inline bool yyjson_mut_obj_add_val(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, yyjson_mut_val *val)
Definition duckdb.cpp:44042
yyjson_api_inline yyjson_mut_val * yyjson_mut_strcpy(yyjson_mut_doc *doc, const char *str)
Definition duckdb.cpp:42806
yyjson_api_inline bool yyjson_mut_obj_add_strcpy(yyjson_mut_doc *doc, yyjson_mut_val *obj, const char *key, const char *val)
Definition duckdb.cpp:44000
void split(const Mat &src, Mat *mvbegin)

◆ GetMetricValue() [1/2]

template<class METRIC_TYPE>
METRIC_TYPE duckdb::ProfilingInfo::GetMetricValue ( const MetricType type) const
inline
36326 {
36327 auto val = metrics.at(type);
36328 return val.GetValue<METRIC_TYPE>();
36329 }

◆ MetricUpdate() [1/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricUpdate ( const MetricType type,
const Value & value,
const std::function< METRIC_TYPE(const METRIC_TYPE &, const METRIC_TYPE &)> & update_fun )
inline
36333 {
36334 if (metrics.find(type) == metrics.end()) {
36335 metrics[type] = value;
36336 return;
36337 }
36338 auto new_value = update_fun(metrics[type].GetValue<METRIC_TYPE>(), value.GetValue<METRIC_TYPE>());
36339 metrics[type] = Value::CreateValue(new_value);
36340 }

◆ MetricUpdate() [2/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricUpdate ( const MetricType type,
const METRIC_TYPE & value,
const std::function< METRIC_TYPE(const METRIC_TYPE &, const METRIC_TYPE &)> & update_fun )
inline
36344 {
36345 auto new_value = Value::CreateValue(value);
36346 MetricUpdate<METRIC_TYPE>(type, new_value, update_fun);
36347 }

◆ MetricSum() [1/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricSum ( const MetricType type,
const Value & value )
inline
36350 {
36351 MetricUpdate<METRIC_TYPE>(type, value, [](const METRIC_TYPE &old_value, const METRIC_TYPE &new_value) {
36352 return old_value + new_value;
36353 });
36354 }

◆ MetricSum() [2/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricSum ( const MetricType type,
const METRIC_TYPE & value )
inline
36357 {
36358 auto new_value = Value::CreateValue(value);
36359 return MetricSum<METRIC_TYPE>(type, new_value);
36360 }

◆ MetricMax() [1/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricMax ( const MetricType type,
const Value & value )
inline
36363 {
36364 MetricUpdate<METRIC_TYPE>(type, value, [](const METRIC_TYPE &old_value, const METRIC_TYPE &new_value) {
36365 return MaxValue(old_value, new_value);
36366 });
36367 }

◆ MetricMax() [2/2]

template<class METRIC_TYPE>
void duckdb::ProfilingInfo::MetricMax ( const MetricType type,
const METRIC_TYPE & value )
inline
36370 {
36371 auto new_value = Value::CreateValue(value);
36372 return MetricMax<METRIC_TYPE>(type, new_value);
36373 }

◆ GetMetricValue() [2/2]

template<>
InsertionOrderPreservingMap< string > duckdb::ProfilingInfo::GetMetricValue ( const MetricType type) const
inline
36379 {
36380 auto val = metrics.at(type);
36381 InsertionOrderPreservingMap<string> result;
36382 auto children = MapValue::GetChildren(val);
36383 for (auto &child : children) {
36384 auto struct_children = StructValue::GetChildren(child);
36385 auto key = struct_children[0].GetValue<string>();
36386 auto value = struct_children[1].GetValue<string>();
36387 result.insert(key, value);
36388 }
36389 return result;
36390}

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