ddn.util.monaco.optimize

Performance optimization utilities for Monaco system monitoring.

This module provides optimized file reading, memory-mapped I/O, and other performance enhancements for system monitoring operations.

Types 8

classOptimizationException : Exception

Exception thrown when optimization operations fail.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)

Configuration for optimization features.

Fields
bool useMmapWhether to use memory-mapped files for reading
size_t bufferSizeBuffer size for file reading (in bytes)
bool enableCachingWhether to cache parsed values
size_t maxMmapSizeMaximum size for files to be memory-mapped (in bytes)

Optimized file reader with buffering and memory mapping support.

This class provides efficient file reading operations, particularly for /proc and /sys files which are commonly accessed in system monitoring.

Example:

auto reader = new OptimizedFileReader();
auto content = reader.readText("/proc/stat");

Fields
private OptimizationConfig config
private char[] readBuffer
Methods
string readText(string path) @safeReads a file and returns its contents as a string.
string[] readLines(string path) @safeReads a file and returns its contents as lines.
string readSingleValue(string path) @safeReads a single value from a file (first line, stripped).
string[string] readKeyValuePairs(string path, char separator = ':') @safeReads a file and parses it as key-value pairs.
OptimizationConfig configuration() @safe pure nothrowGets the current configuration.
Constructors
this()Creates a new optimized file reader with default configuration.
this(OptimizationConfig cfg)Creates a new optimized file reader with custom configuration.

Lazy evaluation range for process enumeration.

This struct provides lazy iteration over processes, avoiding the overhead of loading all process information at once.

Example:

auto range = ProcessRange("/proc");
foreach (pid; range)
{
   // Process pid lazily
}

Fields
private string procPath
private int currentPid
private bool initialized
Methods
int front() @property @safeReturns the front element.
void popFront() @safeAdvances to the next element.
bool empty() @property @safe pure nothrowChecks if the range is empty.
ProcessRange save() @property @safe pure nothrowReturns a copy of this range.
Constructors
this(string path)Creates a new process range.

Batch reader for reading multiple files efficiently.

This class optimizes reading multiple files by grouping operations and minimizing system calls.

Example:

auto batch = new BatchReader();
batch.add("/proc/stat");
batch.add("/proc/meminfo");
auto results = batch.readAll();

Fields
private string[] paths
private OptimizedFileReader reader
Methods
void add(string path) @safe pure nothrowAdds a file path to the batch.
void clear() @safe pure nothrowClears all paths from the batch.
string[string] readAll() @safeReads all files in the batch.
size_t length() @safe pure nothrowReturns the number of files in the batch.
Constructors
this()Creates a new batch reader.

Parsing utilities optimized for system files.

Methods
long parseNumber(string str) @safe pureParses a number from a string, skipping non-numeric characters.
ulong parseMemoryValue(string str) @safe pureParses a memory value with optional suffix (kB, MB, GB).
double parseTimeValue(string str) @safe pureParses a time value in seconds from various formats.

String interning pool for reducing memory allocations.

This class maintains a pool of unique strings, returning references to existing strings rather than creating duplicates.

Fields
private string[string] pool
Methods
string intern(string str) @safe pure nothrowInterns a string, returning a reference to a unique copy.
void clear() @safe pure nothrowClears the string pool.
size_t length() @safe pure nothrowReturns the number of unique strings in the pool.

Global optimization manager singleton.

Fields
private OptimizationManager instance
private OptimizedFileReader fileReader
private StringPool stringPool
private OptimizationConfig config
Methods
OptimizationManager getInstance() @safeGets the singleton instance.
OptimizedFileReader getFileReader() @safe pure nothrowGets the optimized file reader.
StringPool getStringPool() @safe pure nothrowGets the string pool.
OptimizationConfig getConfiguration() @safe pure nothrowGets the current configuration.
Constructors