mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-10-24 20:21:52 +02:00
60 lines
1.7 KiB
C++
60 lines
1.7 KiB
C++
/*
|
|
This Source Code Form is subject to the
|
|
terms of the Mozilla Public License, v.
|
|
2.0. If a copy of the MPL was not
|
|
distributed with this file, You can
|
|
obtain one at
|
|
http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
// memory of the process, as the system counts it, for the debug panel
|
|
struct process_memory
|
|
{
|
|
bool valid{false};
|
|
std::uint64_t resident{0}; // in physical memory now (working set, resident set)
|
|
std::uint64_t peak{0}; // the most it was in physical memory
|
|
std::uint64_t committed{0}; // private memory the process asked for, in physical memory or not (private bytes; 0 where not known)
|
|
};
|
|
|
|
process_memory query_process_memory();
|
|
|
|
// what the program took with new and hasn't given back with delete (the global operators of the executable count it): bytes of
|
|
// the blocks, as the c runtime made them, and blocks. what libraries, the c runtime and the drivers take otherwise isn't in it
|
|
struct heap_memory
|
|
{
|
|
std::uint64_t bytes{0};
|
|
std::uint64_t blocks{0};
|
|
// the same by the size of the blocks: class N holds the blocks of 2^(N-1) to 2^N - 1 bytes
|
|
static constexpr std::size_t CLASSES{48};
|
|
std::array<std::uint64_t, CLASSES> classbytes{};
|
|
std::array<std::uint64_t, CLASSES> classblocks{};
|
|
};
|
|
|
|
heap_memory query_heap_memory();
|
|
|
|
// what a part of the program keeps in memory: things and bytes
|
|
struct memory_count
|
|
{
|
|
std::uint64_t count{0};
|
|
std::uint64_t bytes{0};
|
|
|
|
memory_count &operator+=(memory_count const &Other)
|
|
{
|
|
count += Other.count;
|
|
bytes += Other.bytes;
|
|
return *this;
|
|
}
|
|
};
|
|
|
|
// bytes a vector keeps for its elements
|
|
template <typename Type_> std::uint64_t memory_of(std::vector<Type_> const &Vector)
|
|
{
|
|
return static_cast<std::uint64_t>(Vector.capacity()) * sizeof(Type_);
|
|
}
|