未验证 提交 05a602fe 编写于 作者: C Cai Yudong 提交者: GitHub

fix clang tidy warnings (#3340)

* update GrpcRequestHandler namespace
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* fix clang-tidy warnings
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* optmize clang-tidy rules and clean warnings
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>

* fix clang-format
Signed-off-by: Nyudong.cai <yudong.cai@zilliz.com>
上级 17ad160e
......@@ -16,7 +16,11 @@
# under the License.
# The checks defined here will be run and will display by default as warnings.
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-alpha*,google-*,modernize-*,-modernize-use-trailing-return-type'
Checks: >
-*, clang-diagnostic-*, -clang-diagnostic-error,
clang-analyzer-*, -clang-analyzer-alpha*,
google-*, -google-runtime-references, -google-readability-todo,
modernize-*, -modernize-pass-by-value
# produce HeaderFilterRegex from core/build-support/lint_exclusions.txt with:
# echo -n '^?!('; sed -e 's/*/\.*/g' core/build-support/lint_exclusions.txt | tr '\n' '|'; echo ')$'
......
......@@ -255,8 +255,9 @@ ConfigMgr::Attach(const std::string& name, ConfigObserver* observer) {
void
ConfigMgr::Detach(const std::string& name, ConfigObserver* observer) {
std::lock_guard<std::mutex> lock(observer_mutex_);
if (observers_.find(name) == observers_.end())
if (observers_.find(name) == observers_.end()) {
return;
}
auto& ob_list = observers_[name];
ob_list.remove(observer);
}
......@@ -264,8 +265,9 @@ ConfigMgr::Detach(const std::string& name, ConfigObserver* observer) {
void
ConfigMgr::Notify(const std::string& name) {
std::lock_guard<std::mutex> lock(observer_mutex_);
if (observers_.find(name) == observers_.end())
if (observers_.find(name) == observers_.end()) {
return;
}
auto& ob_list = observers_[name];
for (auto& ob : ob_list) {
ob->ConfigUpdate(name);
......
......@@ -54,13 +54,14 @@ boundary_check(T val, T lower_bound, T upper_bound) {
bool
parse_bool(const std::string& str, std::string& err) {
if (!strcasecmp(str.c_str(), "true"))
if (!strcasecmp(str.c_str(), "true")) {
return true;
else if (!strcasecmp(str.c_str(), "false"))
} else if (!strcasecmp(str.c_str(), "false")) {
return false;
else
} else {
err = "The specified value must be true or false";
return false;
return false;
}
}
std::string
......@@ -80,16 +81,20 @@ parse_bytes(const std::string& str, std::string& err) {
}
std::string s = str;
if (is_number(s))
if (is_number(s)) {
return std::stoll(s);
if (s.length() == 0)
}
if (s.length() == 0) {
return 0;
}
auto last_two = s.substr(s.length() - 2, 2);
auto last_one = s.substr(s.length() - 1);
if (is_alpha(last_two) && is_alpha(last_one))
if (last_one == "b" or last_one == "B")
if (is_alpha(last_two) && is_alpha(last_one)) {
if (last_one == "b" or last_one == "B") {
s = s.substr(0, s.length() - 1);
}
}
auto& units = BYTE_UNITS;
auto suffix = str_tolower(s.substr(s.length() - 1));
......@@ -171,11 +176,13 @@ BoolConfig::Set(const std::string& val, bool update) {
std::string err;
bool value = parse_bool(val, err);
if (not err.empty())
if (not err.empty()) {
return ConfigStatus(SetReturn::INVALID, err);
}
if (is_valid_fn_ && not is_valid_fn_(value, err))
if (is_valid_fn_ && not is_valid_fn_(value, err)) {
return ConfigStatus(SetReturn::INVALID, err);
}
bool prev = *config_;
*config_ = value;
......@@ -227,8 +234,9 @@ StringConfig::Set(const std::string& val, bool update) {
}
std::string err;
if (is_valid_fn_ && not is_valid_fn_(val, err))
if (is_valid_fn_ && not is_valid_fn_(val, err)) {
return ConfigStatus(SetReturn::INVALID, err);
}
std::string prev = *config_;
*config_ = val;
......@@ -369,8 +377,9 @@ IntegerConfig::Set(const std::string& val, bool update) {
}
std::string err;
if (is_valid_fn_ && not is_valid_fn_(value, err))
if (is_valid_fn_ && not is_valid_fn_(value, err)) {
return ConfigStatus(SetReturn::INVALID, err);
}
int64_t prev = *config_;
*config_ = value;
......@@ -432,8 +441,9 @@ FloatingConfig::Set(const std::string& val, bool update) {
}
std::string err;
if (is_valid_fn_ && not is_valid_fn_(value, err))
if (is_valid_fn_ && not is_valid_fn_(value, err)) {
return ConfigStatus(SetReturn::INVALID, err);
}
double prev = *config_;
*config_ = value;
......
......@@ -10,6 +10,7 @@
// or implied. See the License for the specific language governing permissions and limitations under the License
#include <cstdio>
#include <utility>
#include "Log.h"
#include "knowhere/common/Exception.h"
......@@ -17,15 +18,10 @@
namespace milvus {
namespace knowhere {
KnowhereException::KnowhereException(const std::string& msg) : msg(msg) {
KnowhereException::KnowhereException(std::string msg) : msg_(std::move(msg)) {
}
KnowhereException::KnowhereException(const std::string& m, const char* funcName, const char* file, int line) {
#ifdef DEBUG
int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, file, line, m.c_str());
msg.resize(size + 1);
snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", funcName, file, line, m.c_str());
#else
std::string filename;
try {
size_t pos;
......@@ -37,14 +33,13 @@ KnowhereException::KnowhereException(const std::string& m, const char* funcName,
}
int size = snprintf(nullptr, 0, "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str());
msg.resize(size + 1);
snprintf(&msg[0], msg.size(), "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str());
#endif
msg_.resize(size + 1);
snprintf(&msg_[0], msg_.size(), "Error in %s at %s:%d: %s", funcName, filename.c_str(), line, m.c_str());
}
const char*
KnowhereException::what() const noexcept {
return msg.c_str();
return msg_.c_str();
}
} // namespace knowhere
......
......@@ -19,14 +19,14 @@ namespace knowhere {
class KnowhereException : public std::exception {
public:
explicit KnowhereException(const std::string& msg);
explicit KnowhereException(std::string msg);
KnowhereException(const std::string& msg, const char* funName, const char* file, int line);
const char*
what() const noexcept override;
std::string msg;
std::string msg_;
};
#define KNOHWERE_ERROR_MSG(MSG) printf("%s", KnowhereException(MSG, __PRETTY_FUNCTION__, __FILE__, __LINE__).what())
......
......@@ -9,7 +9,8 @@
// 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 <iostream> // TODO(linxj): using Log instead
#include <iostream>
#include <utility>
#include "knowhere/common/Log.h"
#include "knowhere/common/Timer.h"
......@@ -17,13 +18,10 @@
namespace milvus {
namespace knowhere {
TimeRecorder::TimeRecorder(const std::string& header, int64_t log_level) : header_(header), log_level_(log_level) {
TimeRecorder::TimeRecorder(std::string hdr, int64_t log_level) : header_(std::move(hdr)), log_level_(log_level) {
start_ = last_ = stdclock::now();
}
TimeRecorder::~TimeRecorder() {
}
std::string
TimeRecorder::GetTimeSpanStr(double span) {
std::string str_sec = std::to_string(span * 0.000001) + ((span > 1000000) ? " seconds" : " second");
......@@ -35,8 +33,9 @@ TimeRecorder::GetTimeSpanStr(double span) {
void
TimeRecorder::PrintTimeRecord(const std::string& msg, double span) {
std::string str_log;
if (!header_.empty())
if (!header_.empty()) {
str_log += header_ + ": ";
}
str_log += msg;
str_log += " (";
str_log += TimeRecorder::GetTimeSpanStr(span);
......@@ -51,14 +50,17 @@ TimeRecorder::PrintTimeRecord(const std::string& msg, double span) {
LOG_KNOWHERE_DEBUG_ << str_log;
break;
}
// case 2: {
// LOG_KNOWHERE_TRACE_ << str_log;
// break;
// }
// case 3: {
// LOG_KNOWHERE_WARNING_ << str_log;
// break;
// }
// case 2: {
// LOG_KNOWHERE_TRACE_ << str_log;
// break;
// }
// case 3: {
// LOG_KNOWHERE_WARNING_ << str_log;
// break;
// }
default:
LOG_KNOWHERE_DEBUG_ << str_log;
break;
}
}
......
......@@ -21,9 +21,9 @@ class TimeRecorder {
using stdclock = std::chrono::high_resolution_clock;
public:
explicit TimeRecorder(const std::string& header, int64_t log_level = 0);
~TimeRecorder(); // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5
// trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5
explicit TimeRecorder(std::string hdr, int64_t log_level = 0);
virtual ~TimeRecorder() = default;
double
RecordSection(const std::string& msg);
......
......@@ -157,7 +157,7 @@ SystemInfo::MemoryPercent() {
Init();
}
double mem_used = static_cast<double>(GetProcessUsedMemory() * 100);
auto mem_used = static_cast<double>(GetProcessUsedMemory() * 100);
return mem_used / static_cast<double>(total_ram_);
}
......@@ -184,7 +184,7 @@ SystemInfo::getTotalCpuTime(std::vector<int64_t>& work_time_array) {
try {
FILE* file = fopen("/proc/stat", "r");
fiu_do_on("SystemInfo.getTotalCpuTime.open_proc", file = NULL);
if (file == NULL) {
if (file == nullptr) {
LOG_SERVER_ERROR_ << "Failed to read /proc/stat";
return total_time_array;
}
......@@ -196,7 +196,7 @@ SystemInfo::getTotalCpuTime(std::vector<int64_t>& work_time_array) {
char buffer[1024];
char* ret = fgets(buffer, sizeof(buffer) - 1, file);
fiu_do_on("SystemInfo.getTotalCpuTime.read_proc", ret = NULL);
if (ret == NULL) {
if (ret == nullptr) {
LOG_SERVER_ERROR_ << "Could not read stat file";
fclose(file);
return total_time_array;
......@@ -248,8 +248,9 @@ std::vector<int64_t>
SystemInfo::GPUMemoryTotal() {
// get GPU usage percent
fiu_do_on("SystemInfo.GPUMemoryTotal.mock", initialized_ = false);
if (!initialized_)
if (!initialized_) {
Init();
}
std::vector<int64_t> result;
#ifdef MILVUS_GPU_VERSION
......@@ -268,8 +269,9 @@ SystemInfo::GPUMemoryTotal() {
std::vector<int64_t>
SystemInfo::GPUTemperature() {
fiu_do_on("SystemInfo.GPUTemperature.mock", initialized_ = false);
if (!initialized_)
if (!initialized_) {
Init();
}
std::vector<int64_t> result;
#ifdef MILVUS_GPU_VERSION
......@@ -297,8 +299,8 @@ SystemInfo::CPUTemperature() {
return result;
}
struct dirent* ptr = NULL;
while ((ptr = readdir(dir)) != NULL) {
struct dirent* ptr = nullptr;
while ((ptr = readdir(dir)) != nullptr) {
std::string filename(path);
filename.append(ptr->d_name);
......@@ -335,8 +337,9 @@ std::vector<int64_t>
SystemInfo::GPUMemoryUsed() {
// get GPU memory used
fiu_do_on("SystemInfo.GPUMemoryUsed.mock", initialized_ = false);
if (!initialized_)
if (!initialized_) {
Init();
}
std::vector<int64_t> result;
......
......@@ -9,21 +9,23 @@
// 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 <utility>
#include "server/context/Context.h"
namespace milvus {
namespace server {
Context::Context(const std::string& req_id) : req_id_(req_id) {
Context::Context(std::string req_id) : req_id_(std::move(req_id)) {
}
const std::shared_ptr<tracing::TraceContext>&
const tracing::TraceContextPtr&
Context::GetTraceContext() const {
return trace_context_;
}
void
Context::SetTraceContext(const std::shared_ptr<tracing::TraceContext>& trace_context) {
Context::SetTraceContext(const tracing::TraceContextPtr& trace_context) {
trace_context_ = trace_context;
}
std::shared_ptr<Context>
......
......@@ -26,7 +26,7 @@ namespace server {
class Context {
public:
explicit Context(const std::string& request_id);
explicit Context(std::string request_id);
inline std::string
ReqID() const {
......@@ -40,9 +40,9 @@ class Context {
Follower(const std::string& operation_name) const;
void
SetTraceContext(const std::shared_ptr<tracing::TraceContext>& trace_context);
SetTraceContext(const tracing::TraceContextPtr& trace_context);
const std::shared_ptr<tracing::TraceContext>&
const tracing::TraceContextPtr&
GetTraceContext() const;
void
......@@ -60,7 +60,7 @@ class Context {
private:
std::string req_id_;
ReqType req_type_;
std::shared_ptr<tracing::TraceContext> trace_context_;
tracing::TraceContextPtr trace_context_;
ConnectionContextPtr context_;
};
......
......@@ -48,12 +48,6 @@ ScheduleReq(const BaseReqPtr& req, std::queue<BaseReqPtr>& queue) {
} // namespace
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ReqQueue::ReqQueue() {
}
ReqQueue::~ReqQueue() {
}
BaseReqPtr
ReqQueue::TakeReq() {
return Take();
......
......@@ -28,8 +28,8 @@ using BlockingReqQueue = BlockingQueue<BaseReqPtr>;
class ReqQueue : public BlockingReqQueue {
public:
ReqQueue();
virtual ~ReqQueue();
ReqQueue() = default;
virtual ~ReqQueue() = default;
BaseReqPtr
TakeReq();
......
......@@ -63,7 +63,7 @@ GetReqGroup(ReqType type) {
auto iter = s_map_type_group.find(type);
if (iter == s_map_type_group.end()) {
LOG_SERVER_ERROR_ << "Unsupported request type: " << (int32_t)type;
LOG_SERVER_ERROR_ << "Unsupported request type: " << static_cast<int32_t>(type);
throw Exception(SERVER_NOT_IMPLEMENT, "request group undefined");
}
return iter->second;
......
......@@ -726,7 +726,7 @@ GrpcRequestHandler::CreateCollection(::grpc::ServerContext* context, const ::mil
const auto& field = request->fields(i);
FieldSchema field_schema;
field_schema.field_type_ = (engine::DataType)field.type();
field_schema.field_type_ = static_cast<engine::DataType>(field.type());
// Currently only one extra_param
if (field.extra_params_size() != 0) {
......@@ -1127,7 +1127,7 @@ GrpcRequestHandler::Cmd(::grpc::ServerContext* context, const ::milvus::grpc::Co
auto request_str = RequestMap(iter.second->GetReqType()) + "-" + iter.second->ReqID();
requests.emplace_back(request_str);
}
nlohmann::json reply_json;
milvus::json reply_json;
reply_json["requests"] = requests;
reply = reply_json.dump();
response->set_string_reply(reply);
......@@ -1438,8 +1438,7 @@ GrpcRequestHandler::SearchPB(::grpc::ServerContext* context, const ::milvus::grp
#if 0
Status
ParseTermQuery(const nlohmann::json& term_json,
std::unordered_map<std::string, engine::DataType> field_type,
ParseTermQuery(const milvus::json& term_json, std::unordered_map<std::string, engine::DataType> field_type,
query::TermQueryPtr& term_query) {
std::string field_name = term_json["field"].get<std::string>();
auto term_value_json = term_json["values"];
......@@ -1506,7 +1505,7 @@ ParseTermQuery(const nlohmann::json& term_json,
}
Status
ParseRangeQuery(const nlohmann::json& range_json, query::RangeQueryPtr& range_query) {
ParseRangeQuery(const milvus::json& range_json, query::RangeQueryPtr& range_query) {
std::string field_name = range_json["field"];
range_query->field_name = field_name;
......@@ -1552,36 +1551,35 @@ ParseRangeQuery(const nlohmann::json& range_json, query::RangeQueryPtr& range_qu
#endif
Status
GrpcRequestHandler::ProcessLeafQueryJson(const nlohmann::json& json, query::BooleanQueryPtr& query,
GrpcRequestHandler::ProcessLeafQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& query,
std::string& field_name) {
auto status = Status::OK();
if (json.contains("term")) {
if (query_json.contains("term")) {
auto leaf_query = std::make_shared<query::LeafQuery>();
auto term_query = std::make_shared<query::TermQuery>();
nlohmann::json json_obj = json["term"];
milvus::json json_obj = query_json["term"];
JSON_NULL_CHECK(json_obj);
JSON_OBJECT_CHECK(json_obj);
term_query->json_obj = json_obj;
nlohmann::json::iterator json_it = json_obj.begin();
milvus::json::iterator json_it = json_obj.begin();
field_name = json_it.key();
leaf_query->term_query = term_query;
query->AddLeafQuery(leaf_query);
} else if (json.contains("range")) {
} else if (query_json.contains("range")) {
auto leaf_query = std::make_shared<query::LeafQuery>();
auto range_query = std::make_shared<query::RangeQuery>();
nlohmann::json json_obj = json["range"];
milvus::json json_obj = query_json["range"];
JSON_NULL_CHECK(json_obj);
JSON_OBJECT_CHECK(json_obj);
range_query->json_obj = json_obj;
nlohmann::json::iterator json_it = json_obj.begin();
milvus::json::iterator json_it = json_obj.begin();
field_name = json_it.key();
leaf_query->range_query = range_query;
query->AddLeafQuery(leaf_query);
} else if (json.contains("vector")) {
} else if (query_json.contains("vector")) {
auto leaf_query = std::make_shared<query::LeafQuery>();
auto vector_json = json["vector"];
auto vector_json = query_json["vector"];
JSON_NULL_CHECK(vector_json);
leaf_query->vector_placeholder = vector_json.get<std::string>();
......@@ -1589,13 +1587,12 @@ GrpcRequestHandler::ProcessLeafQueryJson(const nlohmann::json& json, query::Bool
} else {
return Status{SERVER_INVALID_ARGUMENT, "Leaf query get wrong key"};
}
return status;
return Status::OK();
}
Status
GrpcRequestHandler::ProcessBooleanQueryJson(const nlohmann::json& query_json, query::BooleanQueryPtr& boolean_query,
GrpcRequestHandler::ProcessBooleanQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& boolean_query,
query::QueryPtr& query_ptr) {
auto status = Status::OK();
if (query_json.empty()) {
return Status{SERVER_INVALID_ARGUMENT, "BoolQuery is null"};
}
......@@ -1669,7 +1666,7 @@ GrpcRequestHandler::ProcessBooleanQueryJson(const nlohmann::json& query_json, qu
}
}
return status;
return Status::OK();
}
Status
......@@ -1677,29 +1674,25 @@ GrpcRequestHandler::DeserializeJsonToBoolQuery(
const google::protobuf::RepeatedPtrField<::milvus::grpc::VectorParam>& vector_params, const std::string& dsl_string,
query::BooleanQueryPtr& boolean_query, query::QueryPtr& query_ptr) {
try {
nlohmann::json dsl_json = json::parse(dsl_string);
milvus::json dsl_json = json::parse(dsl_string);
if (dsl_json.empty()) {
return Status{SERVER_INVALID_ARGUMENT, "Query dsl is null"};
}
auto status = Status::OK();
for (const auto& vector_param : vector_params) {
const std::string& vector_string = vector_param.json();
nlohmann::json vector_json = json::parse(vector_string);
json::iterator it = vector_json.begin();
milvus::json vector_json = json::parse(vector_string);
milvus::json::iterator it = vector_json.begin();
std::string placeholder = it.key();
auto vector_query = std::make_shared<query::VectorQuery>();
json::iterator vector_param_it = it.value().begin();
milvus::json::iterator vector_param_it = it.value().begin();
if (vector_param_it != it.value().end()) {
const std::string& field_name = vector_param_it.key();
vector_query->field_name = field_name;
nlohmann::json param_json = vector_param_it.value();
milvus::json param_json = vector_param_it.value();
int64_t topk = param_json["topk"];
status = server::ValidateSearchTopk(topk);
if (!status.ok()) {
return status;
}
STATUS_CHECK(server::ValidateSearchTopk(topk));
vector_query->topk = topk;
if (param_json.contains("metric_type")) {
std::string metric_type = param_json["metric_type"];
......@@ -1723,12 +1716,9 @@ GrpcRequestHandler::DeserializeJsonToBoolQuery(
if (dsl_json.contains("bool")) {
auto boolean_query_json = dsl_json["bool"];
JSON_NULL_CHECK(boolean_query_json);
status = ProcessBooleanQueryJson(boolean_query_json, boolean_query, query_ptr);
if (!status.ok()) {
return status;
}
STATUS_CHECK(ProcessBooleanQueryJson(boolean_query_json, boolean_query, query_ptr));
}
return status;
return Status::OK();
} catch (std::exception& e) {
return Status{SERVER_INVALID_DSL_PARAMETER, e.what()};
}
......
......@@ -324,11 +324,11 @@ class GrpcRequestHandler final : public ::milvus::grpc::MilvusService::Service,
query::QueryPtr& query_ptr);
Status
ProcessBooleanQueryJson(const nlohmann::json& query_json, query::BooleanQueryPtr& boolean_query,
ProcessBooleanQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& boolean_query,
query::QueryPtr& query_ptr);
Status
ProcessLeafQueryJson(const nlohmann::json& json, query::BooleanQueryPtr& query, std::string& field_name);
ProcessLeafQueryJson(const milvus::json& query_json, query::BooleanQueryPtr& query, std::string& field_name);
private:
ReqHandler req_handler_;
......
......@@ -11,10 +11,9 @@
#include "server/init/InstanceLockCheck.h"
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <string>
#include <fiu/fiu-local.h>
......
......@@ -43,7 +43,7 @@ WriteMagic(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path) {
LOG_ENGINE_ERROR_ << err_msg;
throw Exception(SERVER_WRITE_ERROR, err_msg);
}
fs_ptr->writer_ptr_->Write((void*)MAGIC, MAGIC_SIZE);
fs_ptr->writer_ptr_->Write((void*)(MAGIC), MAGIC_SIZE);
fs_ptr->writer_ptr_->Close();
}
......@@ -136,7 +136,7 @@ CheckSum(const storage::FSHandlerPtr& fs_ptr, const std::string& file_path) {
fs_ptr->reader_ptr_->Close();
auto sum = (uint8_t)atoi(record);
auto sum = static_cast<uint8_t>(atoi(record));
return sum == result;
}
......
......@@ -37,5 +37,7 @@ class TraceContext {
std::unique_ptr<opentracing::Span> span_;
};
using TraceContextPtr = std::shared_ptr<TraceContext>;
} // namespace tracing
} // namespace milvus
......@@ -66,16 +66,20 @@ int64_t
parse_bytes(const std::string& str, std::string& err) {
try {
std::string s = str;
if (is_number(s))
if (is_number(s)) {
return std::stoll(s);
if (s.length() == 0)
}
if (s.length() == 0) {
return 0;
}
auto last_two = s.substr(s.length() - 2, 2);
auto last_one = s.substr(s.length() - 1);
if (is_alpha(last_two) && is_alpha(last_one))
if (last_one == "b" or last_one == "B")
if (is_alpha(last_two) && is_alpha(last_one)) {
if (last_one == "b" or last_one == "B") {
s = s.substr(0, s.length() - 1);
}
}
auto& units = BYTE_UNITS;
auto suffix = str_tolower(s.substr(s.length() - 1));
......
......@@ -15,6 +15,7 @@
#include <exception>
#include <string>
#include <utility>
namespace milvus {
......@@ -24,7 +25,7 @@ namespace milvus {
class Exception : public std::exception {
public:
Exception(ErrorCode code, const std::string& message) : code_(code), message_(message) {
Exception(ErrorCode code, std::string msg) : code_(code), message_(std::move(msg)) {
}
ErrorCode
......
......@@ -21,7 +21,7 @@ Status::Status(StatusCode code, const std::string& msg) {
// 4 bytes store code
// 4 bytes store message length
// the left bytes store message string
const uint32_t length = (uint32_t)msg.size();
auto length = static_cast<uint32_t>(msg.size());
auto result = new char[length + sizeof(length) + CODE_WIDTH];
std::memcpy(result, &code, CODE_WIDTH);
std::memcpy(result + CODE_WIDTH, &length, sizeof(length));
......
......@@ -9,17 +9,17 @@
// 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 "utils/TimeRecorder.h"
#include <utility>
#include "utils/Log.h"
#include "utils/TimeRecorder.h"
namespace milvus {
TimeRecorder::TimeRecorder(const std::string& header, int64_t log_level) : header_(header), log_level_(log_level) {
TimeRecorder::TimeRecorder(std::string hdr, int64_t log_level) : header_(std::move(hdr)), log_level_(log_level) {
start_ = last_ = stdclock::now();
}
TimeRecorder::~TimeRecorder() = default;
std::string
TimeRecorder::GetTimeSpanStr(double span) {
std::string str_sec = std::to_string(span * 0.000001) + ((span > 1000000) ? " seconds" : " second");
......@@ -89,7 +89,7 @@ TimeRecorder::ElapseFromBegin(const std::string& msg) {
return span;
}
TimeRecorderAuto::TimeRecorderAuto(const std::string& header, int64_t log_level) : TimeRecorder(header, log_level) {
TimeRecorderAuto::TimeRecorderAuto(std::string hdr, int64_t log_level) : TimeRecorder(hdr, log_level) {
}
TimeRecorderAuto::~TimeRecorderAuto() {
......
......@@ -32,9 +32,9 @@ class TimeRecorder {
using stdclock = std::chrono::high_resolution_clock;
public:
explicit TimeRecorder(const std::string& header, int64_t log_level = 1);
virtual ~TimeRecorder(); // trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5
// trace = 0, debug = 1, info = 2, warn = 3, error = 4, critical = 5
explicit TimeRecorder(std::string hdr, int64_t log_level = 1);
virtual ~TimeRecorder() = default;
double
RecordSection(const std::string& msg);
......@@ -58,8 +58,7 @@ class TimeRecorder {
class TimeRecorderAuto : public TimeRecorder {
public:
explicit TimeRecorderAuto(const std::string& header, int64_t log_level = 1);
explicit TimeRecorderAuto(std::string hdr, int64_t log_level = 1);
~TimeRecorderAuto() override;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册