#pragma once
#include <cstdint>
#include <deque>
#include <memory_resource>
#include <mutex>
#include "../global_include.h"
struct Process_Memory_Snapshot {
    std::uint64_t timestamp_ms{};
    std::uint64_t rss_bytes{};
    std::uint64_t peak_rss_bytes{};
    std::uint64_t anonymous_rss_bytes{};
    std::uint64_t file_rss_bytes{};
    std::uint64_t shared_rss_bytes{};
    std::uint64_t virtual_bytes{};
    std::uint64_t swap_bytes{};
    std::uint64_t commit_bytes{};
    std::uint64_t peak_commit_bytes{};
    std::uint64_t system_total_bytes{};
    std::uint64_t system_available_bytes{};
    std::uint64_t page_faults{};
    std::uint64_t allocator_live_bytes{};
    std::uint64_t allocator_peak_live_bytes{};
    std::uint64_t pmr_live_bytes{};
    std::uint64_t pmr_peak_live_bytes{};
};
class Memory_Monitor {
public:
    static Memory_Monitor& instance();
    void sample();
    Psc::JSON state_json() const;
private:
    Memory_Monitor();
    mutable std::mutex mutex_;
    std::pmr::deque<Process_Memory_Snapshot> history_;
};
