szaszm commented on a change in pull request #1211: URL: https://github.com/apache/nifi-minifi-cpp/pull/1211#discussion_r748120387
########## File path: libminifi/include/core/extension/Utils.h ########## @@ -0,0 +1,113 @@ +/** + * 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. + */ + +#pragma once + +#include <optional> +#include <functional> +#include <chrono> +#include <utility> +#include <memory> +#include <string> + +#include "utils/gsl.h" +#include "utils/file/FileView.h" +#include "utils/StringUtils.h" + +namespace org::apache::nifi::minifi::core::extension::internal { + +struct Timer { + explicit Timer(std::function<void(int)> cb): cb_(std::move(cb)) {} + ~Timer() { + auto end = std::chrono::steady_clock::now(); + int elapsed = gsl::narrow<int>(std::chrono::duration_cast<std::chrono::milliseconds>(end - start_).count()); + cb_(elapsed); + } + std::chrono::steady_clock::time_point start_{std::chrono::steady_clock::now()}; + std::function<void(int)> cb_; +}; + +struct LibraryDescriptor { + std::string name; + std::filesystem::path dir; + std::string filename; + + [[nodiscard]] + bool verify(const std::shared_ptr<logging::Logger>& logger) const { + auto path = getFullPath(); + Timer timer{[&] (int ms) { + logger->log_error("Verification for '%s' took %d ms", path.string(), ms); + }}; Review comment: After reading the current version, now I think it's good enough without the date library, and maybe it's not such a good idea to include it here, just to use a library function instead of a few extra characters of formatting. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
