/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2024-2025 Gregory Lirent */ using System.Text.Json.Serialization; namespace WebmrAPI.Models { public class ProcessBaseInfo : MemoryRegion { public enum ProcessStatus { Undefined, Running, NotResponding } private TimeSpan _lastPTime = TimeSpan.Zero; private TimeSpan _curPTime = TimeSpan.Zero; private int _pid = 0; private int _ppid = -1; private int _tcount = 0; private string? _name = null; private string? _fname = null; private string? _cmd = null; private ProcessStatus _status = ProcessStatus.Undefined; private DateTime? _startTime = null; private double _cpuUsage = 0; [JsonIgnore] public TimeSpan TotalProcessorTime { set { lock (_lock) { _lastPTime = _curPTime; _curPTime = value; } } } [JsonIgnore] public double ProcessorTime { get { lock (_lock) return (_curPTime - _lastPTime).TotalMilliseconds; } } public int PID { get => LockedGet(ref _pid); set => LockedSet(ref _pid, value); } public int ParentPID { get => LockedGet(ref _ppid); set => LockedSet(ref _ppid, value); } public string? Name { get => LockedGet(ref _name); set => LockedSet(ref _name, value); } public string? FileName { get => LockedGet(ref _fname); set => LockedSet(ref _fname, value); } public string? CommandLine { get => LockedGet(ref _cmd); set => LockedSet(ref _cmd, value); } public int ThreadCount { get => LockedGet(ref _tcount); set => LockedSet(ref _tcount, value); } public ProcessStatus Status { get => LockedGet(ref _status); set => LockedSet(ref _status, value); } public DateTime? StartTime { get => LockedGet(ref _startTime); set => LockedSet(ref _startTime, value); } public double CpuUsage { get => LockedGet(ref _cpuUsage); set => LockedSet(ref _cpuUsage, value); } } }