martinzink commented on a change in pull request #1152: URL: https://github.com/apache/nifi-minifi-cpp/pull/1152#discussion_r811917049
########## File path: extensions/procfs/CpuStat.h ########## @@ -0,0 +1,140 @@ +/** + * 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 <sstream> +#include <string> +#include <utility> +#include <optional> +#include "rapidjson/document.h" + +namespace org::apache::nifi::minifi::procfs { + +class CpuStatData { + CpuStatData() = default; + + public: + CpuStatData(const CpuStatData& src) = default; + CpuStatData(CpuStatData&& src) noexcept = default; + + static std::optional<CpuStatData> parseCpuStatLine(std::istringstream& iss); + + bool operator>=(const CpuStatData &rhs) const; + bool operator==(const CpuStatData &rhs) const; + CpuStatData operator-(const CpuStatData &rhs) const; + + uint64_t getUser() const { return user_; } + uint64_t getNice() const { return nice_; } + uint64_t getSystem() const { return system_; } + uint64_t getIdle() const { return idle_; } + uint64_t getIoWait() const { return io_wait_; } + uint64_t getIrq() const { return irq_; } + uint64_t getSoftIrq() const { return soft_irq_; } + uint64_t getSteal() const { return steal_; } + uint64_t getGuest() const { return guest_; } + uint64_t getGuestNice() const { return guest_nice_; } + + uint64_t getIdleAll() const { return idle_ + io_wait_; } + uint64_t getSystemAll() const { return system_ + irq_ + soft_irq_; } + uint64_t getVirtAll() const { return guest_ + guest_nice_; } + uint64_t getTotal() const { return user_ + nice_ + getSystemAll() + getIdleAll() + steal_ + getVirtAll(); } + + private: + uint64_t user_; + uint64_t nice_; + uint64_t system_; + uint64_t idle_; + uint64_t io_wait_; + uint64_t irq_; + uint64_t soft_irq_; + uint64_t steal_; + uint64_t guest_; + uint64_t guest_nice_; +}; + +class CpuStat { + public: + static constexpr const char USER_STR[] = "user time"; + static constexpr const char NICE_STR[] = "nice time"; + static constexpr const char SYSTEM_STR[] = "system time"; + static constexpr const char IDLE_STR[] = "idle time"; + static constexpr const char IO_WAIT_STR[] = "io wait time"; + static constexpr const char IRQ_STR[] = "irq time"; + static constexpr const char SOFT_IRQ_STR[] = "soft irq time"; + static constexpr const char STEAL_STR[] = "steal time"; + static constexpr const char GUEST_STR[] = "guest time"; + static constexpr const char GUEST_NICE_STR[] = "guest nice time"; + + CpuStat(const CpuStat& src) = default; + CpuStat(CpuStat&& src) noexcept = default; + Review comment: The rework removed these classes -- 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]
