FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
memory_projection.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2026-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7/**
8 * @file memory_projection.h
9 * @brief Startup memory and output-size projection helpers for simulations.
10 */
11
12#pragma once
13
14#include <cstdint>
15#include <memory>
16#include <optional>
17#include <string>
18#include <vector>
19
20#include "core/config.h"
21
22namespace timing
23{
24 class Timing;
25}
26
27namespace core
28{
29 class World;
30
31 /**
32 * @brief Describes a projected byte count and whether it saturated during arithmetic.
33 */
35 {
36 std::uint64_t bytes = 0; ///< Projected byte count, clamped to `uint64_t` max on overflow.
37 bool overflowed = false; ///< True if any arithmetic used to produce `bytes` overflowed.
38 };
39
40 /**
41 * @brief Captures startup memory and rendered-output projections for a simulation.
42 *
43 * The projection separates memory that is expected to be allocated by the simulation
44 * run itself from the resident baseline already present at startup. Byte totals are
45 * estimates intended for logging, diagnostics, and API reporting.
46 */
48 {
49 RealType duration_seconds = 0.0; ///< Simulated duration covered by the projection.
50 RealType simulation_sample_rate_hz = 0.0; ///< Oversampled simulation rate used for sample counts.
51 unsigned oversample_ratio = 1; ///< Oversampling ratio applied to the configured output rate.
52
53 std::uint64_t streaming_sample_count = 0; ///< Internal samples produced for each full-duration stream.
54 std::uint64_t phase_noise_sample_count = 0; ///< Samples held by each enabled phase-noise lookup.
55 std::uint64_t phase_noise_timing_count = 0; ///< Unique streaming timing sources considered.
56 std::uint64_t enabled_phase_noise_timing_count = 0; ///< Unique timing sources with phase noise enabled.
57 std::uint64_t streaming_receiver_count = 0; ///< Receivers that emit streaming output.
58 std::uint64_t pulsed_receiver_count = 0; ///< Receivers that render finite pulsed receive windows.
59 std::uint64_t pulsed_window_count = 0; ///< Projected count of pulsed receive windows.
60 std::uint64_t rendered_hdf5_sample_count = 0; ///< Projected IQ samples written to HDF5 datasets.
61
62 ByteProjection phase_noise_lookup; ///< Projected memory for all enabled timing-source lookup tables.
63 ByteProjection streaming_iq_buffers; ///< Projected full-duration streaming output sink memory.
64 ByteProjection rendered_hdf5_payload; ///< Projected raw I/Q dataset payload bytes written to HDF5.
65 std::optional<ByteProjection> resident_baseline; ///< Startup RSS observed before projected run allocations.
66 std::optional<ByteProjection> projected_total_footprint; ///< Projected total resident footprint at peak.
67 std::optional<std::uint64_t> current_resident_set; ///< Process RSS at projection time, when available.
68 };
69
70 /**
71 * @brief Collects unique timing sources used by CW/FMCW transmitters and receivers.
72 * @param world The simulation world to inspect.
73 * @return A vector of unique timing sources that may need phase-noise lookup tables.
74 */
75 [[nodiscard]] std::vector<std::shared_ptr<timing::Timing>> collectCwPhaseNoiseTimings(const World& world);
76
77 /**
78 * @brief Projects startup memory and rendered-output sizes for a simulation world.
79 * @param world The simulation world to inspect.
80 * @return A populated memory projection for the current simulation parameters.
81 */
83
84 /**
85 * @brief Formats a byte count using binary units.
86 * @param bytes The byte count to format.
87 * @return A human-readable string such as `512 B` or `1.50 MiB`.
88 */
89 [[nodiscard]] std::string formatByteSize(std::uint64_t bytes);
90
91 /**
92 * @brief Serializes a simulation memory projection as JSON.
93 * @param projection The projection to serialize.
94 * @return A formatted JSON string suitable for API responses and diagnostics.
95 */
97
98 /**
99 * @brief Logs the projected simulation memory footprint for the provided world.
100 * @param world The simulation world to inspect and report.
101 */
102 void logSimulationMemoryProjection(const World& world);
103}
The World class manages the simulator environment.
Definition world.h:39
Represents a timing source for simulation.
Definition timing.h:36
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
void logSimulationMemoryProjection(const World &world)
Logs the projected simulation memory footprint for the provided world.
std::string memoryProjectionToJsonString(const SimulationMemoryProjection &projection)
Serializes a simulation memory projection as JSON.
std::vector< std::shared_ptr< timing::Timing > > collectCwPhaseNoiseTimings(const World &world)
Collects unique timing sources used by CW/FMCW transmitters and receivers.
SimulationMemoryProjection projectSimulationMemory(const World &world)
Projects startup memory and rendered-output sizes for a simulation world.
std::string formatByteSize(const std::uint64_t bytes)
Formats a byte count using binary units.
math::Vec3 max
Describes a projected byte count and whether it saturated during arithmetic.
bool overflowed
True if any arithmetic used to produce bytes overflowed.
std::uint64_t bytes
Projected byte count, clamped to uint64_t max on overflow.
Captures startup memory and rendered-output projections for a simulation.
std::uint64_t streaming_receiver_count
Receivers that emit streaming output.
std::uint64_t streaming_sample_count
Internal samples produced for each full-duration stream.
std::uint64_t phase_noise_sample_count
Samples held by each enabled phase-noise lookup.
ByteProjection rendered_hdf5_payload
Projected raw I/Q dataset payload bytes written to HDF5.
unsigned oversample_ratio
Oversampling ratio applied to the configured output rate.
ByteProjection streaming_iq_buffers
Projected full-duration streaming output sink memory.
ByteProjection phase_noise_lookup
Projected memory for all enabled timing-source lookup tables.
std::uint64_t enabled_phase_noise_timing_count
Unique timing sources with phase noise enabled.
std::uint64_t pulsed_receiver_count
Receivers that render finite pulsed receive windows.
std::optional< ByteProjection > projected_total_footprint
Projected total resident footprint at peak.
std::uint64_t pulsed_window_count
Projected count of pulsed receive windows.
std::uint64_t rendered_hdf5_sample_count
Projected IQ samples written to HDF5 datasets.
RealType duration_seconds
Simulated duration covered by the projection.
std::uint64_t phase_noise_timing_count
Unique streaming timing sources considered.
std::optional< std::uint64_t > current_resident_set
Process RSS at projection time, when available.
std::optional< ByteProjection > resident_baseline
Startup RSS observed before projected run allocations.
RealType simulation_sample_rate_hz
Oversampled simulation rate used for sample counts.