fgerlits commented on code in PR #1152: URL: https://github.com/apache/nifi-minifi-cpp/pull/1152#discussion_r842709445
########## extensions/procfs/ProcFsJsonSerialization.h: ########## @@ -0,0 +1,156 @@ +/** + * 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 <string> +#include <string_view> + +#include "ProcFsSerialization.h" +#include "rapidjson/stream.h" +#include "rapidjson/document.h" + +namespace org::apache::nifi::minifi::extensions::procfs { + +namespace details { +class Serializer { + public: + Serializer(rapidjson::Value& json, rapidjson::Document::AllocatorType& alloc) : + json_(json), alloc_(alloc) { + } + void operator()(const char* key, uint64_t value) { + json_.AddMember(rapidjson::StringRef(key), value, alloc_); + } + void operator()(const char* key, double value) { + json_.AddMember(rapidjson::StringRef(key), value, alloc_); + } + void operator()(const char* key, std::string_view value) { + rapidjson::Value value_json(value.data(), value.size(), alloc_); + json_.AddMember(rapidjson::StringRef(key), value_json, alloc_); + } + private: + rapidjson::Value& json_; + rapidjson::Document::AllocatorType& alloc_; +}; +} // namespace details + +void addCPUStatToJson(const std::string& cpu_name, + const CpuStatData& cpu_stat, + rapidjson::Value& cpu_root, + rapidjson::Document::AllocatorType& alloc) { + rapidjson::Value cpu_key(cpu_name.c_str(), cpu_name.length(), alloc); + cpu_root.AddMember(cpu_key.Move(), rapidjson::kObjectType, alloc); + rapidjson::Value& cpu_stat_json = cpu_root[cpu_name.c_str()]; + SerializeCPUStatData(cpu_stat, + details::Serializer(cpu_stat_json, alloc)); +} + +void addCPUStatPeriodToJson(const std::string& cpu_name, + const CpuStatData& start, + const CpuStatData& end, + rapidjson::Value& cpu_root, + rapidjson::Document::AllocatorType& alloc) { + rapidjson::Value cpu_key(cpu_name.c_str(), cpu_name.length(), alloc); + cpu_root.AddMember(cpu_key.Move(), rapidjson::kObjectType, alloc); + rapidjson::Value& cpu_stat_json = cpu_root[cpu_name.c_str()]; + SerializeNormalizedCPUStat(end-start, + details::Serializer(cpu_stat_json, alloc)); +} + +void addDiskStatToJson(const std::string& disk_name, + const DiskStatData& disk_stat, + rapidjson::Value& disk_root, + rapidjson::Document::AllocatorType& alloc) { + rapidjson::Value disk_key(disk_name.c_str(), disk_name.length(), alloc); + disk_root.AddMember(disk_key.Move(), rapidjson::kObjectType, alloc); + rapidjson::Value& disk_json = disk_root[disk_name.c_str()]; + SerializeDiskStatData(disk_stat, + details::Serializer(disk_json, alloc)); +} + +void addDiskStatPerSecToJson(const std::string& disk_name, + const DiskStatData disk_stat, Review Comment: I think this is a typo: ```suggestion const DiskStatData& disk_stat, ``` (same at line 111) ########## libminifi/include/utils/FlatMap.h: ########## @@ -147,6 +147,22 @@ class FlatMap{ return data_.rbegin()->second; } + const V& at(const K& key) const { Review Comment: These new `FlatMap` member functions are not used in this PR any longer, so I would remove them and their tests. But they are probably going to be useful later, so if you want to keep them, that's fine, too. -- 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]
