martinzink commented on a change in pull request #1152:
URL: https://github.com/apache/nifi-minifi-cpp/pull/1152#discussion_r838355369



##########
File path: extensions/procfs/ProcFs.h
##########
@@ -0,0 +1,64 @@
+/**
+ * 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 <unistd.h>
+
+#include <unordered_map>
+#include <utility>
+#include <string>
+#include <optional>
+#include <filesystem>
+#include <memory>
+
+#include "ProcessStat.h"
+#include "MemInfo.h"
+#include "CpuStat.h"
+#include "NetDev.h"
+#include "DiskStat.h"
+
+#include "core/logging/LoggerConfiguration.h"
+#include "core/logging/Logger.h"
+
+namespace org::apache::nifi::minifi::extensions::procfs {
+
+class ProcFs {
+  static constexpr const char* DEFAULT_ROOT_PATH = "/proc";
+  static constexpr const char* MEMINFO_FILE = "meminfo";
+  static constexpr const char* STAT_FILE = "stat";
+  static constexpr const char* NET_DEV_FILE = "net/dev";
+  static constexpr const char* DISK_STATS_FILE = "diskstats";
+ public:
+  explicit ProcFs(std::filesystem::path path = DEFAULT_ROOT_PATH)
+      : root_path_(std::move(path)) {
+  }
+
+  [[nodiscard]] std::unordered_map<pid_t, ProcessStat> getProcessStats() const;
+  [[nodiscard]] std::unordered_map<std::string, CpuStatData> getCpuStats() 
const;
+  [[nodiscard]] std::optional<MemInfo> getMemInfo() const;
+  [[nodiscard]] std::unordered_map<std::string, NetDevData> getNetDevs() const;
+  [[nodiscard]] std::unordered_map<std::string, DiskStatData> getDiskStats() 
const;

Review comment:
       I went with a mix of your ideas.
   When it comes to CPUStat, DiskStat, NetDev the original order makes sense 
and the number of entries are expected to be low so I went with FlatMap.
   With ProcessStats the original order is already random (due to 
std::filesystem::directory_iterator) and I can image scenarios where the number 
of processes go high where the linear lookup of FlatMap could hurt performance 
in a measurable way, so I went with std::map.
   
   What do you think? 
https://github.com/apache/nifi-minifi-cpp/pull/1152/commits/d04a5cd15e513d41c8dc9d6ad19a959ddaee0642




-- 
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]


Reply via email to