PEL: Keep size statistics of PEL repo

Keep a running total of several size statistics of the PEL repository.

The statistics are:
* Total size of all PELs
* Total size of BMC created PELs
* Total size of BMC created informational PELs
* Total size of BMC created non-informational PELs
* Total size of non-BMC created PELs
* Total size of non-BMC created informational PELs
* Total size of non-BMC created non-informational PELs

Here, size refers to the disk size the PEL uses, which is different than
the file size.  The disk size is retrieved from the stat() function and
is the number of 512B blocks used.

The term 'informational' above doesn't strictly refer to the
informational severity value (0x0), but also includes other cases, such
as hidden recovered PELs.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I07a3ccd7cfe802a344a2db47daba5fb05d56489f
diff --git a/extensions/openpower-pels/repository.hpp b/extensions/openpower-pels/repository.hpp
index ecfcf7e..e9b6a27 100644
--- a/extensions/openpower-pels/repository.hpp
+++ b/extensions/openpower-pels/repository.hpp
@@ -112,6 +112,27 @@
         }
     };
 
+    /**
+     * @brief A structure for keeping a breakdown of the sizes of PELs
+     *        of different types in the repository.
+     */
+    struct SizeStats
+    {
+        uint64_t total;
+        uint64_t bmc;
+        uint64_t nonBMC;
+        uint64_t bmcServiceable;
+        uint64_t bmcInfo;
+        uint64_t nonBMCServiceable;
+        uint64_t nonBMCInfo;
+
+        SizeStats() :
+            total(0), bmc(0), nonBMC(0), bmcServiceable(0), bmcInfo(0),
+            nonBMCServiceable(0), nonBMCInfo(0)
+        {
+        }
+    };
+
     Repository() = delete;
     ~Repository() = default;
     Repository(const Repository&) = default;
@@ -313,6 +334,25 @@
      */
     void setPELHMCTransState(uint32_t pelID, TransmissionState state);
 
+    /**
+     * @brief Returns the size stats structure
+     *
+     * @return const SizeStats& - The stats structure
+     */
+    const SizeStats& getSizeStats() const
+    {
+        return _sizes;
+    }
+
+    /**
+     * @brief Says if the PEL is considered serviceable (not just
+     *        informational) as determined by its severity.
+     *
+     * @param[in] pel - The PELAttributes entry for the PEL
+     * @return bool - If serviceable or not
+     */
+    static bool isServiceableSev(const PELAttributes& pel);
+
   private:
     using PELUpdateFunc = std::function<void(PEL&)>;
 
@@ -372,6 +412,15 @@
     void write(const PEL& pel, const std::filesystem::path& path);
 
     /**
+     * @brief Updates the repository statistics after a PEL is
+     *        added or removed.
+     *
+     * @param[in] pel - The PELAttributes entry for the PEL
+     * @param[in] pelAdded - true if the PEL was added, false if removed
+     */
+    void updateRepoStats(const PELAttributes& pel, bool pelAdded);
+
+    /**
      * @brief The filesystem path to the PEL logs.
      */
     const std::filesystem::path _logPath;
@@ -402,6 +451,11 @@
      *        before pruning.
      */
     const size_t _maxNumPELs;
+
+    /**
+     * @brief Statistics on the sizes of the stored PELs.
+     */
+    SizeStats _sizes;
 };
 
 } // namespace pels