16#include <nlohmann/json.hpp>
19#include <unordered_map>
21#if defined(__APPLE__) && defined(__MACH__)
23#elif defined(__linux__)
41 constexpr std::uint64_t max_uint64 = std::numeric_limits<std::uint64_t>::max();
50 return receiver.getMode() == OperationMode::CW_MODE ||
receiver.getMode() == OperationMode::FMCW_MODE ||
51 receiver.getMode() == OperationMode::SFCW_MODE;
60 [[nodiscard]] std::uint64_t ceilToUint64(
const RealType value,
bool& overflowed)
noexcept
62 if (!std::isfinite(value))
71 if (value >=
static_cast<RealType>(max_uint64))
76 const RealType nearest = std::round(value);
77 const RealType tolerance = 1.0e-12 * std::max<RealType>(1.0, std::abs(
nearest));
80 return static_cast<std::uint64_t
>(
nearest);
82 return static_cast<std::uint64_t
>(std::ceil(value));
150 const RealType sample_rate_hz,
bool& overflowed)
noexcept
152 return ceilToUint64(duration_seconds * sample_rate_hz, overflowed);
182 if (
prf <= 0.0 || !std::isfinite(
prf))
190 std::uint64_t
total = 0;
227 overflowed = overflowed ||
added.overflowed;
241#if defined(__linux__)
248 std::ifstream
statm(
"/proc/self/statm");
264 if (bytes.overflowed)
269#elif defined(__APPLE__) && defined(__MACH__)
277 return static_cast<std::uint64_t
>(
info.resident_size);
304 return {{
"bytes",
nullptr}, {
"human",
"unknown"}, {
"overflowed",
false}};
312 std::unordered_map<SimId, std::shared_ptr<timing::Timing>>
unique_timings;
332 std::vector<std::shared_ptr<timing::Timing>> timings;
336 timings.push_back(
entry.second);
411 projection.phase_noise_timing_count =
static_cast<std::uint64_t
>(timings.size());
412 for (
const auto&
timing : timings)
416 ++
projection.enabled_phase_noise_timing_count;
422 projection.enabled_phase_noise_timing_count *
static_cast<std::uint64_t
>(
sizeof(
RealType)),
434 if (
receiver.getMode() == OperationMode::PULSED_MODE)
444 if (
projection.current_resident_set.has_value())
458 constexpr std::array
units = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB"};
459 auto value =
static_cast<long double>(bytes);
470 return std::format(
"{:.2f} {}",
static_cast<double>(value),
units.at(
unit_index));
475 const nlohmann::json
result = {
476 {
"duration_seconds",
projection.duration_seconds},
477 {
"simulation_sample_rate_hz",
projection.simulation_sample_rate_hz},
478 {
"oversample_ratio",
projection.oversample_ratio},
480 {{
"streaming_samples",
projection.streaming_sample_count},
481 {
"phase_noise_samples_per_enabled_timing",
projection.phase_noise_sample_count},
482 {
"rendered_hdf5_samples",
projection.rendered_hdf5_sample_count},
483 {
"pulsed_windows",
projection.pulsed_window_count}}},
485 {{
"phase_noise_timing_sources",
projection.phase_noise_timing_count},
486 {
"enabled_phase_noise_timing_sources",
projection.enabled_phase_noise_timing_count},
487 {
"streaming_receivers",
projection.streaming_receiver_count},
488 {
"pulsed_receivers",
projection.pulsed_receiver_count}}},
492 {
"current_resident_set",
494 ? nlohmann::json{{
"bytes", *
projection.current_resident_set},
496 : nlohmann::json{{
"bytes",
nullptr}, {
"human",
"unknown"}}},
505 const std::string resident_baseline =
507 const std::string
total =
projection.projected_total_footprint.has_value()
512 "Projected simulation footprint: phase_noise_lookup_memory={} ({} enabled timing sources x {} samples), "
513 "streaming_output_buffer_memory={} ({} streaming receivers, IF-rate receivers use IF sample counts), "
514 "rendered_hdf5_dataset_payload={} "
515 "({} output samples), resident_baseline={} (current RSS before projected run allocations), "
516 "projected_total_footprint={}.",
522 constexpr std::uint64_t
one_gib = 1024ULL * 1024ULL * 1024ULL;
542 "Receiver {} is outputting RF-rate IF data. Projected file size is {:.2f} GiB. This is expected "
543 "for V1 native dechirping, but ensure you have sufficient disk space. Future versions will support "
544 "IF-rate decimation.",
const Receiver & receiver
The World class manages the simulator environment.
const std::vector< std::unique_ptr< radar::Transmitter > > & getTransmitters() const noexcept
Retrieves the list of radar transmitters.
const std::vector< std::unique_ptr< radar::Receiver > > & getReceivers() const noexcept
Retrieves the list of radar receivers.
RealType earliestPhaseNoiseLookupStart() const
Finds the earliest simulation time that can require CW phase-noise samples.
Manages radar signal reception and response processing.
double RealType
Type for real numbers.
std::complex< RealType > ComplexType
Type for complex numbers.
Header file for the logging system.
Startup memory and output-size projection helpers for simulations.
void logSimulationMemoryProjection(const World &world)
Logs the projected simulation memory footprint for the provided world.
void addPulsedReceiverProjection(SimulationMemoryProjection &projection, const radar::Receiver &receiver)
std::string memoryProjectionToJsonString(const SimulationMemoryProjection &projection)
Serializes a simulation memory projection as JSON.
void addStreamingReceiverProjection(SimulationMemoryProjection &projection, const radar::Receiver &receiver, const bool sample_count_overflowed)
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.
@ WARNING
Warning level for potentially harmful situations.
@ DEBUG
Debug level for general debugging information.
RealType endTime() noexcept
Get the end time for the simulation.
RealType rate() noexcept
Get the rendering sample rate.
RealType startTime() noexcept
Get the start time for the simulation.
unsigned oversampleRatio() noexcept
Get the oversampling ratio.
OperationMode
Defines the operational mode of a radar component.
Defines the Parameters struct and provides methods for managing simulation parameters.
Radar Receiver class for managing signal reception and response handling.
Describes a projected byte count and whether it saturated during arithmetic.
std::uint64_t bytes
Projected byte count, clamped to uint64_t max on overflow.
Captures startup memory and rendered-output projections for a simulation.
Timing source for simulation objects.
Header file for the Transmitter class in the radar namespace.
Header file for the World class in the simulator.