Files
webdoorcreator/WebDoorCreator.SDK/ProcStats.cs
T
2023-05-13 12:40:14 +02:00

62 lines
2.1 KiB
C#

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WebDoorCreator.SDK
{
public class ProcStats
{
private static ConcurrentDictionary<string, long> Counter = new ConcurrentDictionary<string, long>();
private static ConcurrentDictionary<string, long> Timers = new ConcurrentDictionary<string, long>();
internal static void UpdateStat(string functionName, long timer)
{
if (!Timers.ContainsKey(functionName))
Timers.TryAdd(functionName, timer);
else
Timers[functionName] += timer;
if (!Counter.ContainsKey(functionName))
Counter.TryAdd(functionName, 1);
else
Counter[functionName]++;
}
internal volatile static Dictionary<string, string> RunningThreadStatus = new Dictionary<string, string>();
public static ConcurrentQueue<(string, long, long)> RecordList = new ConcurrentQueue<(string, long, long)>();
public static ConcurrentDictionary<string, CumSumData> ExeCumSum = new ConcurrentDictionary<string, CumSumData>();
public static bool RecordData(string nameRef, long exeTime, long othTime)
{
bool fatto = false;
if (ExeCumSum.ContainsKey(nameRef))
{
ExeCumSum[nameRef].NumRec++;
ExeCumSum[nameRef].ExeTime += exeTime;
ExeCumSum[nameRef].OthTime += othTime;
}
else
{
ExeCumSum.TryAdd(nameRef, new CumSumData(1, exeTime, othTime));
}
return fatto;
}
public class CumSumData
{
public CumSumData(long nrec, long eTime, long oTime)
{
NumRec = nrec;
ExeTime = eTime;
OthTime = oTime;
}
public long NumRec { get; set; } = 0;
public long ExeTime { get; set; } = 0;
public long OthTime { get; set; } = 0;
}
}
}