Files
ThreadPilot/Services/IPerformanceMonitoringService.cs
T
PrimeBuild-pc c9253f879d Enhance CI/release workflow and app robustness
Add comprehensive CI and release improvements (coverage collection, Codecov upload, SBOM generation), split release workflow into build/smoke-test/release stages with deterministic version resolution, artifact uploads, winget manifest updates and changelog generation. Add a pre-commit hook to block large or unwanted artifacts. Introduce runtime improvements: smoke-test startup mode, improved unhandled/dispatcher/task-exception reporting, ThreadPilotException error codes, single-instance behavior adjustments, and logging enhancements. UI and UX changes include a new Logs tab and LogViewer wiring, DWM title-bar theming helper, navigation serialization/unsaved-changes guard, system-tray update backoff logic, and related viewmodel/service integrations. Also add installer template, helper classes, tests, docs, packaging and build scripts, and minor .gitignore updates.
2026-04-15 22:38:35 +02:00

241 lines
6.6 KiB
C#

/*
* ThreadPilot - Advanced Windows Process and Power Plan Manager
* Copyright (C) 2025 Prime Build
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, version 3 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace ThreadPilot.Services
{
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using ThreadPilot.Models;
/// <summary>
/// Service for real-time performance monitoring.
/// </summary>
public interface IPerformanceMonitoringService
{
/// <summary>
/// Get current system performance metrics.
/// </summary>
Task<SystemPerformanceMetrics> GetSystemMetricsAsync(bool lightweight = false);
/// <summary>
/// Get per-core CPU usage.
/// </summary>
Task<List<CpuCoreUsage>> GetCpuCoreUsageAsync();
/// <summary>
/// Get memory usage information.
/// </summary>
Task<MemoryUsageInfo> GetMemoryUsageAsync();
/// <summary>
/// Get top CPU consuming processes.
/// </summary>
Task<List<ProcessPerformanceInfo>> GetTopCpuProcessesAsync(int count = 10);
/// <summary>
/// Get top memory consuming processes.
/// </summary>
Task<List<ProcessPerformanceInfo>> GetTopMemoryProcessesAsync(int count = 10);
/// <summary>
/// Start real-time monitoring.
/// </summary>
Task StartMonitoringAsync();
/// <summary>
/// Stop real-time monitoring.
/// </summary>
Task StopMonitoringAsync();
/// <summary>
/// Event raised when performance metrics are updated
/// </summary>
event EventHandler<PerformanceMetricsUpdatedEventArgs>? MetricsUpdated;
/// <summary>
/// Get historical performance data.
/// </summary>
Task<List<SystemPerformanceMetrics>> GetHistoricalDataAsync(TimeSpan duration);
/// <summary>
/// Clear historical performance data.
/// </summary>
Task ClearHistoricalDataAsync();
}
/// <summary>
/// System performance metrics.
/// </summary>
public class SystemPerformanceMetrics
{
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
public double TotalCpuUsage { get; set; }
public long TotalMemoryUsage { get; set; }
public long AvailableMemory { get; set; }
public long TotalMemory { get; set; }
public double MemoryUsagePercentage { get; set; }
public int Gen0Collections { get; set; }
public int Gen1Collections { get; set; }
public int Gen2Collections { get; set; }
public int Gen0CollectionsDelta { get; set; }
public int Gen1CollectionsDelta { get; set; }
public int Gen2CollectionsDelta { get; set; }
public long TotalAllocatedBytes { get; set; }
public long AllocatedBytesDelta { get; set; }
public long ManagedHeapSizeBytes { get; set; }
public long GcCommittedBytes { get; set; }
public double LastGcPauseMs { get; set; }
public double MaxGcPauseMs { get; set; }
public int HandleCount { get; set; }
public long ProcessWorkingSetBytes { get; set; }
public List<CpuCoreUsage> CpuCoreUsages { get; set; } = new();
public ProcessPerformanceInfo? TopCpuProcess { get; set; }
public ProcessPerformanceInfo? TopMemoryProcess { get; set; }
public int ActiveProcessCount { get; set; }
public int ThreadCount { get; set; }
public double DiskUsage { get; set; }
public double NetworkUsage { get; set; }
}
/// <summary>
/// CPU core usage information.
/// </summary>
public class CpuCoreUsage
{
public int CoreId { get; set; }
public string CoreName { get; set; } = string.Empty;
public double Usage { get; set; }
public string CoreType { get; set; } = "Unknown"; // P-Core, E-Core, etc.
public bool IsHyperThreaded { get; set; }
public int PhysicalCoreId { get; set; }
public double Frequency { get; set; }
public double Temperature { get; set; }
}
/// <summary>
/// Memory usage information.
/// </summary>
public class MemoryUsageInfo
{
public long TotalPhysicalMemory { get; set; }
public long AvailablePhysicalMemory { get; set; }
public long UsedPhysicalMemory { get; set; }
public double PhysicalMemoryUsagePercentage { get; set; }
public long TotalVirtualMemory { get; set; }
public long AvailableVirtualMemory { get; set; }
public long UsedVirtualMemory { get; set; }
public double VirtualMemoryUsagePercentage { get; set; }
public long PageFileSize { get; set; }
public long PageFileUsage { get; set; }
public double PageFileUsagePercentage { get; set; }
}
/// <summary>
/// Process performance information.
/// </summary>
public class ProcessPerformanceInfo
{
public int ProcessId { get; set; }
public string ProcessName { get; set; } = string.Empty;
public string WindowTitle { get; set; } = string.Empty;
public double CpuUsage { get; set; }
public long MemoryUsage { get; set; }
public long VirtualMemoryUsage { get; set; }
public int ThreadCount { get; set; }
public int HandleCount { get; set; }
public DateTime StartTime { get; set; }
public TimeSpan RunTime { get; set; }
public string ExecutablePath { get; set; } = string.Empty;
public bool IsResponding { get; set; }
public string Priority { get; set; } = string.Empty;
public IntPtr ProcessorAffinity { get; set; }
}
/// <summary>
/// Event args for performance metrics updates.
/// </summary>
public class PerformanceMetricsUpdatedEventArgs : EventArgs
{
public SystemPerformanceMetrics Metrics { get; }
public DateTime UpdateTime { get; }
public PerformanceMetricsUpdatedEventArgs(SystemPerformanceMetrics metrics)
{
this.Metrics = metrics;
this.UpdateTime = DateTime.UtcNow;
}
}
}