[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user asfgit closed the pull request at: https://github.com/apache/incubator-quickstep/pull/302 ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141769721 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { --- End diff -- We may typedef `std::pair`. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141769962 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { +auto result = getCurrentStatsForQuery(); +if (result.second != 0) { + return result.first/static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Get the current stats for the given operator. + * @param operator_id The ID of the operator. + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the operator. + */ + std::pair getCurrentStatsForOperator(std::size_t operator_id) const { +if (hasOperator(operator_id)) { + DCHECK(active_operators_.at(operator_id).get() != nullptr); --- End diff -- Optionally, remove `.get()`, as `unique_ptr` has `operator!=`. `DCHECK(active_operators_.at(operator_id) != nullptr);`. Alternatively, `DCHECK(active_operators_.at(operator_id));` may work as well. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141770622 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { +auto result = getCurrentStatsForQuery(); +if (result.second != 0) { + return result.first/static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Get the current stats for the given operator. + * @param operator_id The ID of the operator. + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the operator. + */ + std::pair getCurrentStatsForOperator(std::size_t operator_id) const { +if (hasOperator(operator_id)) { + DCHECK(active_operators_.at(operator_id).get() != nullptr); + return active_operators_.at(operator_id)->getStats(); +} +return std::make_pair(0, 0); + } + + float getAverageWorkOrderTimeForOperator(std::size_t operator_id) const { +auto result = getCurrentStatsForOperator(operator_id); +if (result.second != 0) { + return result.first / static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Add a new entry to stats. + * + * @param value The value to be added. + * @param operator_index The operator index which the value belongs to. + **/ + void addEntry(std::size_t value, std::size_t operator_index) { +if (!hasOperator(operator_index)) { + // This is the first entry for the given operator. + // Create the OperatorStats object for this operator. + active_operators_[operator_index] = + std::uniq
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141770165 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { +auto result = getCurrentStatsForQuery(); +if (result.second != 0) { + return result.first/static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Get the current stats for the given operator. + * @param operator_id The ID of the operator. + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the operator. + */ + std::pair getCurrentStatsForOperator(std::size_t operator_id) const { +if (hasOperator(operator_id)) { + DCHECK(active_operators_.at(operator_id).get() != nullptr); + return active_operators_.at(operator_id)->getStats(); +} +return std::make_pair(0, 0); + } + + float getAverageWorkOrderTimeForOperator(std::size_t operator_id) const { +auto result = getCurrentStatsForOperator(operator_id); +if (result.second != 0) { + return result.first / static_cast(result.second); --- End diff -- Ditto for `double`. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141768980 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); --- End diff -- Remove an unnecessary pair of `()`. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141769628 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { +auto result = getCurrentStatsForQuery(); +if (result.second != 0) { + return result.first/static_cast(result.second); --- End diff -- Since `result.second` is an `uint64_t`, we have to cast to `double`. Also, please add ` ` between `/` for readability. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141771086 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { --- End diff -- I suggest to use `double`, to be consistent with `uint64_t`. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141770914 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { + for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { +auto operator_stats = getCurrentStatsForOperator((it->first)); +total_time += operator_stats.first; +num_workorders += operator_stats.second; + } +} +return std::make_pair(total_time, num_workorders); + } + + /** + * @brief Get the average work order time for the query. + */ + float getAverageWorkOrderTimeForQuery() const { +auto result = getCurrentStatsForQuery(); +if (result.second != 0) { + return result.first/static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Get the current stats for the given operator. + * @param operator_id The ID of the operator. + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the operator. + */ + std::pair getCurrentStatsForOperator(std::size_t operator_id) const { +if (hasOperator(operator_id)) { + DCHECK(active_operators_.at(operator_id).get() != nullptr); + return active_operators_.at(operator_id)->getStats(); +} +return std::make_pair(0, 0); + } + + float getAverageWorkOrderTimeForOperator(std::size_t operator_id) const { +auto result = getCurrentStatsForOperator(operator_id); +if (result.second != 0) { + return result.first / static_cast(result.second); +} +return 0.0; + } + + /** + * @brief Add a new entry to stats. + * + * @param value The value to be added. + * @param operator_index The operator index which the value belongs to. + **/ + void addEntry(std::size_t value, std::size_t operator_index) { +if (!hasOperator(operator_index)) { + // This is the first entry for the given operator. + // Create the OperatorStats object for this operator. + active_operators_[operator_index] = + std::uniq
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
Github user zuyu commented on a diff in the pull request: https://github.com/apache/incubator-quickstep/pull/302#discussion_r141768847 --- Diff: query_execution/ExecutionStats.hpp --- @@ -0,0 +1,210 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + **/ + +#ifndef QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ +#define QUICKSTEP_QUERY_EXECUTION_EXECUTION_STATS_HPP_ + +#include +#include +#include +#include +#include +#include +#include + +#include "utility/Macros.hpp" + +#include "glog/logging.h" + +namespace quickstep { + +/** \addtogroup QueryExecution + * @{ + */ + +/** + * @brief Record the execution stats of a query. + **/ +class ExecutionStats { + public: + /** + * @brief Constructor + * + * @param max_entries The maximum number of entries we remember for each + *operator. + **/ + explicit ExecutionStats(const std::size_t max_entries) + : max_entries_(max_entries) {} + + /** + * @brief Get the number of active operators in stats. + **/ + const std::size_t getNumActiveOperators() const { +return active_operators_.size(); + } + + /** + * @brief Check if there are stats present for at least one active operator. + **/ + inline bool hasStats() const { +for (auto it = active_operators_.begin(); it != active_operators_.end(); ++it) { + if (it->second->hasStatsForOperator()) { +return true; + } +} +return false; + } + + /** + * @brief Get the current stats for the query. + * + * @return A pair - 1st element is total time, 2nd element is total number of + * WorkOrders for the whole query. + **/ + std::pair getCurrentStatsForQuery() const { +std::uint64_t total_time = 0; +std::uint64_t num_workorders = 0; +if (!active_operators_.empty()) { --- End diff -- No need for this `if`. ---
[GitHub] incubator-quickstep pull request #302: Created a class to track execution st...
GitHub user hbdeshmukh opened a pull request: https://github.com/apache/incubator-quickstep/pull/302 Created a class to track execution statistics Stats are maintained for active operators in the query. Right now, the stats include number of work orders and the execution times of the work orders. The design of the class is open to future extensions to add fields such as number of rows read, peak memory consumption during a work order execution. You can merge this pull request into a Git repository by running: $ git pull https://github.com/hbdeshmukh/incubator-quickstep execution-stats Alternatively you can review and apply these changes as the patch at: https://github.com/apache/incubator-quickstep/pull/302.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #302 commit 24feb548f69bb7440b9a5dbb743e21d3ee7f4543 Author: Harshad Deshmukh Date: 2017-09-27T19:55:16Z Created a class to track execution statistics - Stats are maintained for active operators in the query. ---