ddn.util.monaco.query

Advanced Process Querying

This module provides powerful filtering and search capabilities for processes, including a fluent query API and process tree construction.

Features:

  • Fluent query DSL for process filtering
  • Pattern matching (glob-style)
  • Process tree construction
  • Aggregate statistics
  • Performance optimized

Platform Availability:

  • Fully cross-platform
  • Linux, Windows, macOS, BSD

Types 2

A fluent query builder for filtering and searching processes.

This struct provides a chainable API for building complex process queries. Multiple filters can be combined to find specific processes.

Example:

auto procs = ProcessQuery()
  .name("python*")
  .memoryAbove(1024 * 1024 * 1024)  // 1 GB
  .cpuAbove(50.0)
  .execute();

Fields
private string namePattern_
private string exePattern_
private string username_
private double cpuAbove_
private ulong memoryAbove_
private ProcessStatus status_
private bool hasStatus_
private int parentPid_
private string openFilePath_
private string connectionAddr_
private ushort connectionPort_
private bool hasConnection_
Methods
ProcessQuery name(string pattern)Filters processes by name pattern.
ProcessQuery exe(string pattern)Filters processes by executable path pattern.
ProcessQuery user(string username)Filters processes by username.
ProcessQuery cpuAbove(double percent)Filters processes with CPU usage above a threshold.
ProcessQuery memoryAbove(ulong bytes)Filters processes with memory usage above a threshold.
ProcessQuery status(ProcessStatus s)Filters processes by status.
ProcessQuery parent(int pid)Filters processes by parent PID.
ProcessQuery hasOpenFile(string path)Filters processes that have a specific file open.
ProcessQuery hasConnection(string addr, ushort port)Filters processes that have a network connection.
Process[] execute()Executes the query and returns matching processes.
int count()Counts the number of processes matching the criteria.
Process first()Returns the first process matching the criteria.
private bool matchesCriteria(Process proc)Checks if a process matches all query criteria.
private bool globMatch(string str, string pattern)Matches a string against a glob pattern.

Represents a hierarchical tree of processes.

A ProcessTree contains a root process and its children (recursively). This is useful for visualizing process hierarchies and calculating aggregate statistics.

Example:

auto tree = processTree(1);
tree.visit((proc, depth) {
  writeln("  ".repeat(depth), proc.name());
});

Fields
Process rootThe root process of this tree node
ProcessTree[] childrenChild process trees
Methods
void visit(void delegate(Process, int depth) visitor)Visits all processes in the tree using a visitor function.
private void visitImpl(void delegate(Process, int depth) visitor, int depth)Implementation of visit with depth tracking.
Process[] flatten()Flattens the tree into a single array of processes.
ulong totalMemory()Calculates total memory usage of all processes in the tree.
double totalCpu()Calculates total CPU usage of all processes in the tree.

Functions 3

fnProcessTree processTree(int rootPid) @safeBuilds a process tree starting from a specific PID.
fnProcessTree[] processForest() @safeBuilds process trees for all top-level processes.
private fnProcessTree[] buildChildTrees(int parentPid) @safeRecursively builds child trees for a given parent PID.