// Copyright 2018 RED Software, LLC. All Rights Reserved.

using System;
using System.Diagnostics;

namespace IgniteEngine
{
    /// <summary>
    /// Records application profiling information.
    /// </summary>
    public class Profiler
    {
        /// <summary>
        /// Returns the current application CPU Usage.
        /// </summary>
        public static double CPUUsage => Math.Ceiling(cpuCounter.NextValue());

        /// <summary>
        /// Returns the current application RAM Usage.
        /// </summary>
        public static double RAMUsage => Math.Ceiling(ramCounter.NextValue() / 1024 / 1024);

        /// <summary>
        /// Records application CPU usage.
        /// </summary>
        private static readonly PerformanceCounter cpuCounter = new PerformanceCounter("Process", "% Processor Time", Process.GetCurrentProcess().ProcessName); 

        /// <summary>
        /// Records application RAM usage.
        /// </summary>
        private static readonly PerformanceCounter ramCounter = new PerformanceCounter("Process", "Working Set", Process.GetCurrentProcess().ProcessName);
    }
}
