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;
59 [[nodiscard]] std::uint64_t ceilToUint64(
const RealType value,
bool& overflowed)
noexcept
61 if (!std::isfinite(value))
70 if (value >=
static_cast<RealType>(max_uint64))
75 const RealType nearest = std::round(value);
76 const RealType tolerance = 1.0e-12 * std::max<RealType>(1.0, std::abs(
nearest));
79 return static_cast<std::uint64_t
>(
nearest);
81 return static_cast<std::uint64_t
>(std::ceil(value));
149 const RealType sample_rate_hz,
bool& overflowed)
noexcept
151 return ceilToUint64(duration_seconds * sample_rate_hz, overflowed);
181 if (
prf <= 0.0 || !std::isfinite(
prf))
189 std::uint64_t
total = 0;
226 overflowed = overflowed ||
added.overflowed;
240#if defined(__linux__)
247 std::ifstream
statm(
"/proc/self/statm");
263 if (bytes.overflowed)
268#elif defined(__APPLE__) && defined(__MACH__)
276 return static_cast<std::uint64_t
>(
info.resident_size);
303 return {{
"bytes",
nullptr}, {
"human",
"unknown"}, {
"overflowed",
false}};
311 std::unordered_map<SimId, std::shared_ptr<timing::Timing>>
unique_timings;
331 std::vector<std::shared_ptr<timing::Timing>> timings;
335 timings.push_back(
entry.second);
410 projection.phase_noise_timing_count =
static_cast<std::uint64_t
>(timings.size());
411 for (
const auto&
timing : timings)
415 ++
projection.enabled_phase_noise_timing_count;
421 projection.enabled_phase_noise_timing_count *
static_cast<std::uint64_t
>(
sizeof(
RealType)),
433 if (
receiver.getMode() == OperationMode::PULSED_MODE)
443 if (
projection.current_resident_set.has_value())
457 constexpr std::array
units = {
"B",
"KiB",
"MiB",
"GiB",
"TiB",
"PiB",
"EiB"};
458 auto value =
static_cast<long double>(bytes);
469 return std::format(
"{:.2f} {}",
static_cast<double>(value),
units.at(
unit_index));
474 const nlohmann::json
result = {
475 {
"duration_seconds",
projection.duration_seconds},
476 {
"simulation_sample_rate_hz",
projection.simulation_sample_rate_hz},
477 {
"oversample_ratio",
projection.oversample_ratio},
479 {{
"streaming_samples",
projection.streaming_sample_count},
480 {
"phase_noise_samples_per_enabled_timing",
projection.phase_noise_sample_count},
481 {
"rendered_hdf5_samples",
projection.rendered_hdf5_sample_count},
482 {
"pulsed_windows",
projection.pulsed_window_count}}},
484 {{
"phase_noise_timing_sources",
projection.phase_noise_timing_count},
485 {
"enabled_phase_noise_timing_sources",
projection.enabled_phase_noise_timing_count},
486 {
"streaming_receivers",
projection.streaming_receiver_count},
487 {
"pulsed_receivers",
projection.pulsed_receiver_count}}},
491 {
"current_resident_set",
493 ? nlohmann::json{{
"bytes", *
projection.current_resident_set},
495 : nlohmann::json{{
"bytes",
nullptr}, {
"human",
"unknown"}}},
504 const std::string resident_baseline =
506 const std::string
total =
projection.projected_total_footprint.has_value()
511 "Projected simulation footprint: phase_noise_lookup_memory={} ({} enabled timing sources x {} samples), "
512 "streaming_output_buffer_memory={} ({} streaming receivers, IF-rate receivers use IF sample counts), "
513 "rendered_hdf5_dataset_payload={} "
514 "({} output samples), resident_baseline={} (current RSS before projected run allocations), "
515 "projected_total_footprint={}.",
521 constexpr std::uint64_t
one_gib = 1024ULL * 1024ULL * 1024ULL;
541 "Receiver {} is outputting RF-rate IF data. Projected file size is {:.2f} GiB. This is expected "
542 "for V1 native dechirping, but ensure you have sufficient disk space. Future versions will support "
543 "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.