Shuo-Jia commented on a change in pull request #597: URL: https://github.com/apache/incubator-pegasus/pull/597#discussion_r485504577
########## File path: src/server/hotspot_partition_calculator.cpp ########## @@ -0,0 +1,100 @@ +// 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. + +#include "hotspot_partition_calculator.h" + +#include <algorithm> +#include <math.h> +#include <dsn/dist/fmt_logging.h> + +namespace pegasus { +namespace server { + +DSN_DEFINE_int64("pegasus.hotspot", + max_hotspot_store_size, + 100, + "the max count of historical data stored in calculator, in order to same Mem"); + +void hotspot_partition_calculator::data_aggregate(const std::vector<row_data> &partitions) +{ + while (_historical_data.size() > FLAGS_max_hotspot_store_size - 1) { + _historical_data.pop(); + } + std::vector<hotspot_partition_data> temp(partitions.size()); + for (int i = 0; i < partitions.size(); i++) { + temp[i] = std::move(hotspot_partition_data(partitions[i])); + } + _historical_data.emplace(temp); +} + +void hotspot_partition_calculator::init_perf_counter(const int perf_counter_count) +{ + std::string counter_name; + std::string counter_desc; + for (int i = 0; i < perf_counter_count; i++) { + string partition_desc = _app_name + '.' + std::to_string(i); + counter_name = fmt::format("app.stat.hotspots@{}", paritition_desc); + counter_desc = fmt::format("statistic the hotspots of app {}", paritition_desc); + _hot_points[i].init_app_counter( + "app.pegasus", counter_name.c_str(), COUNTER_TYPE_NUMBER, counter_desc.c_str()); + } +} + +void hotspot_partition_calculator::_data_analyse( + const std::queue<std::vector<hotspot_partition_data>> &hotspot_app_data, + std::vector<::dsn::perf_counter_wrapper> &perf_counters) +{ + dassert(hotspot_app_data.back().size() == perf_counters.size(), + "partition counts error, please check"); + std::vector<double> data_samples; + data_samples.reserve(hotspot_app_data.size() * perf_counters.size()); + auto temp_data = hotspot_app_data; Review comment: is `temp_data` necessary?may you use `std::vector<<std::vector>>` directly and no need `pop` but use `for` to read the data? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
