From 7390a01a12b09a0e61fb1cb9549aab460cd4e6f1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 29 Mar 2025 09:27:45 +0100 Subject: [PATCH] update con log aggregato chiamate frequenti --- MP-TAB3/Components/ProdConfirm.razor | 94 ++++++++++--------- MP-TAB3/MP-TAB3.csproj | 2 +- MP-TAB3/Resources/ChangeLog.html | 2 +- MP-TAB3/Resources/VersNum.txt | 2 +- MP-TAB3/Resources/manifest.xml | 2 +- MP.Data/Services/ExecStatsCollector.cs | 119 +++++++++++++++++++++++++ MP.Data/Services/TabDataService.cs | 85 ++++++++++++++++-- 7 files changed, 250 insertions(+), 56 deletions(-) create mode 100644 MP.Data/Services/ExecStatsCollector.cs diff --git a/MP-TAB3/Components/ProdConfirm.razor b/MP-TAB3/Components/ProdConfirm.razor index 06c650ba..5f078b10 100644 --- a/MP-TAB3/Components/ProdConfirm.razor +++ b/MP-TAB3/Components/ProdConfirm.razor @@ -26,6 +26,56 @@ +@if (showConfirmResult) +{ +
+
+
+ Conferma Produzione effettuata alle @($"{lastConfProd:HH:mm:ss}") +
+
+
+ @if (lastPzBuoni > 0) + { + Pz Buoni + @lastPzBuoni + } + else + { + Pz Buoni + @lastPzBuoni + } +
+
+ @if (lastPzScarto > 0) + { + Pz scarto + @lastPzScarto + } + else + { + Pz scarto + @lastPzScarto + } +
+
+ @if (lastPzRilav > 0) + { + Cicli Rilav. + @lastPzRilav + } + else + { + Cicli Rilav. + @lastPzRilav + } +
+
+
+
+} + + @if (confProdActive) {
@@ -117,6 +167,7 @@
} +
@@ -210,49 +261,6 @@
-@if (showConfirmResult) -{ -
- Conferma Produzione effettuata alle @($"{lastConfProd:HH:mm:ss}") -
- @if (lastPzBuoni > 0) - { - Pz Buoni - @lastPzBuoni - } - else - { - Pz Buoni - @lastPzBuoni - } -
-
- @if (lastPzScarto > 0) - { - Pz scarto - @lastPzScarto - } - else - { - Pz scarto - @lastPzScarto - } -
-
- @if (lastPzRilav > 0) - { - Cicli Rilav. - @lastPzRilav - } - else - { - Cicli Rilav. - @lastPzRilav - } -
-
-} - @if (!confProdActive) {
diff --git a/MP-TAB3/MP-TAB3.csproj b/MP-TAB3/MP-TAB3.csproj index ae01160f..4e3739c2 100644 --- a/MP-TAB3/MP-TAB3.csproj +++ b/MP-TAB3/MP-TAB3.csproj @@ -3,7 +3,7 @@ net6.0 enable - 6.16.2503.2719 + 6.16.2503.2909 enable MP_TAB3 diff --git a/MP-TAB3/Resources/ChangeLog.html b/MP-TAB3/Resources/ChangeLog.html index e75662cc..33502969 100644 --- a/MP-TAB3/Resources/ChangeLog.html +++ b/MP-TAB3/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2503.2719

+

Versione: 6.16.2503.2909


Note di rilascio:
  • diff --git a/MP-TAB3/Resources/VersNum.txt b/MP-TAB3/Resources/VersNum.txt index a7defef1..033f5627 100644 --- a/MP-TAB3/Resources/VersNum.txt +++ b/MP-TAB3/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2503.2719 +6.16.2503.2909 diff --git a/MP-TAB3/Resources/manifest.xml b/MP-TAB3/Resources/manifest.xml index c322ee27..9c4fa659 100644 --- a/MP-TAB3/Resources/manifest.xml +++ b/MP-TAB3/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2503.2719 + 6.16.2503.2909 https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/MP-TAB3.zip https://nexus.steamware.net/repository/SWS/MP-TAB3/stable/LAST/ChangeLog.html false diff --git a/MP.Data/Services/ExecStatsCollector.cs b/MP.Data/Services/ExecStatsCollector.cs new file mode 100644 index 00000000..d8c49143 --- /dev/null +++ b/MP.Data/Services/ExecStatsCollector.cs @@ -0,0 +1,119 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data.Services +{ + /// + /// Gestore statistiche esecuzione processi x analisi timing + /// + public class ExecStatsCollector + { + #region Public Methods + + /// + /// restituisce una stringa da poter emettere in log con il summary degli eventi tracciati ed eventuale reset... + /// + /// + /// + /// + public string GetCallSum(string CallName, bool resetCount) + { + string answ = ""; + if (TrackData.ContainsKey(CallName)) + { + var reqRec = TrackData[CallName]; + answ = $"{CallName} | {reqRec.NumCall} x {reqRec.AvgTime:N3}ms | min: {reqRec.MinTime:N3} | MAX: {reqRec.MaxTime:N3}"; + // se richiede reset --> effettuo + if (resetCount) + { + TrackData[CallName].ListMsRec = new List(); + } + } + return answ; + } + + /// + /// Accumula record di tracciamento info esecuzione e restituisce numero elementi finali + /// + /// nome chiamata da registrare + /// Durata in ms + /// + public int RecordCall(string CallName, double msDuration) + { + if (TrackData.ContainsKey(CallName)) + { + TrackData[CallName].ListMsRec.Add(msDuration); + } + else + { + TrackData.Add(CallName, new RecordData() { ListMsRec = new List() { msDuration } }); + } + return TrackData[CallName].NumCall; + } + + #endregion Public Methods + + #region Public Classes + + /// + /// Record atomico informazioni x un dato task tracciato + /// + public class RecordData + { + #region Public Properties + + /// + /// Tempo medio + /// + public double AvgTime + { + get => ListMsRec.Sum(x => x) / (NumCall > 0 ? NumCall : 1); + } + + /// + /// Lista registrazioni di tempi esecuzione in ms + /// + public List ListMsRec { get; set; } = new List(); + + /// + /// Tempo Massimo + /// + public double MaxTime + { + get => ListMsRec.OrderByDescending(x => x).FirstOrDefault(); + } + + /// + /// Tempo minimo + /// + public double MinTime + { + get => ListMsRec.OrderBy(x => x).FirstOrDefault(); + } + + /// + /// numero registrazioni disponibili + /// + public int NumCall + { + get => ListMsRec.Count(); + } + + #endregion Public Properties + } + + #endregion Public Classes + + #region Private Fields + + /// + /// Dizionario di dati statistici accumulati + /// + private Dictionary TrackData = new Dictionary(); + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MP.Data/Services/TabDataService.cs b/MP.Data/Services/TabDataService.cs index 16ce1881..2a110ffd 100644 --- a/MP.Data/Services/TabDataService.cs +++ b/MP.Data/Services/TabDataService.cs @@ -1052,6 +1052,8 @@ namespace MP.Data.Services /// public async Task> MacchineByMatrOper(int MatrOpr) { + int rndWait = rnd.Next(0, 2); + await Task.Delay(rndWait); // setup parametri costanti string source = "DB"; Stopwatch sw = new Stopwatch(); @@ -1059,7 +1061,10 @@ namespace MP.Data.Services List result = new List(); // cerco in redis... string currKey = $"{redisBaseKey}:MachByMatOp:{MatrOpr}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); +#if false + RedisValue rawData = await redisDb.StringGetAsync(currKey); +#endif + RedisValue rawData = redisDb.StringGet(currKey); //if (!string.IsNullOrEmpty($"{rawData}")) if (rawData.HasValue) { @@ -1071,14 +1076,26 @@ namespace MP.Data.Services result = dbTabController.MacchineByMatrOper(MatrOpr); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, LongCache); + redisDb.StringSet(currKey, rawData, LongCache); +#if false + await redisDb.StringSetAsync(currKey, rawData, LongCache); +#endif } if (result == null) { result = new List(); } sw.Stop(); - Log.Debug($"MacchineByMatrOper | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#if false + Log.Debug($"MacchineByMatrOper | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#endif + + string callName = $"MacchineByMatrOper.{source}"; + int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); + if (numRec >= nRecLog) + { + Log.Debug(esCollect.GetCallSum(callName, true)); + } return result; } @@ -1331,6 +1348,11 @@ namespace MP.Data.Services } } + /// + /// gestore collezione statistiche esecuzione x logging + /// + private ExecStatsCollector esCollect = new ExecStatsCollector(); + /// /// ODL da key /// @@ -1375,7 +1397,15 @@ namespace MP.Data.Services result = new ODLExpModel(); } sw.Stop(); - Log.Debug($"OdlByIdx | {idxOdl} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#if false + Log.Debug($"OdlByIdx | {idxOdl} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#endif + string callName = $"OdlByIdx.{source}"; + int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); + if (numRec >= nRecLog) + { + Log.Debug(esCollect.GetCallSum(callName, true)); + } return result; } @@ -1449,7 +1479,15 @@ namespace MP.Data.Services result = new ODLExpModel(); } sw.Stop(); - Log.Debug($"OdlCurrByMacc | {source} | {idxMacchina} | {sw.Elapsed.TotalMilliseconds}ms"); +#if false + Log.Debug($"OdlCurrByMacc | {source} | {idxMacchina} | {sw.Elapsed.TotalMilliseconds}ms"); +#endif + string callName = $"OdlCurrByMacc.{source}"; + int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); + if (numRec >= nRecLog) + { + Log.Debug(esCollect.GetCallSum(callName, true)); + } } else { @@ -2019,7 +2057,15 @@ namespace MP.Data.Services result = new PODLExpModel(); } sw.Stop(); - Log.Debug($"PODL_getByKey | {idxPODL} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#if false + Log.Debug($"PODL_getByKey | {idxPODL} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#endif + string callName = $"PODL_getByKey.{source}"; + int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); + if (numRec >= nRecLog) + { + Log.Debug(esCollect.GetCallSum(callName, true)); + } return result; } @@ -2990,6 +3036,8 @@ namespace MP.Data.Services /// public async Task StatoProdMacchina(string idxMacchina, DateTime dtReq) { + int rndWait = rnd.Next(0, 2); + await Task.Delay(rndWait); // setup parametri costanti string source = "DB"; Stopwatch sw = new Stopwatch(); @@ -2997,7 +3045,10 @@ namespace MP.Data.Services StatoProdModel? result = new StatoProdModel(); // cerco in redis... string currKey = $"{redisBaseKey}:StatoProd:{idxMacchina}:{dtReq:HHmm}"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); + RedisValue rawData = redisDb.StringGet(currKey); +#if false + RedisValue rawData = await redisDb.StringGetAsync(currKey); +#endif //if (!string.IsNullOrEmpty($"{rawData}")) if (rawData.HasValue) { @@ -3009,17 +3060,33 @@ namespace MP.Data.Services result = dbTabController.StatoProdMacchina(idxMacchina, dtReq); // serializzo e salvo... rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); + redisDb.StringSet(currKey, rawData, UltraFastCache); +#if false + await redisDb.StringSetAsync(currKey, rawData, UltraFastCache); +#endif } if (result == null) { result = new StatoProdModel(); } sw.Stop(); - Log.Debug($"StatoProdMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#if false + Log.Debug($"StatoProdMacchina | {source} | {sw.Elapsed.TotalMilliseconds}ms"); +#endif + string callName = $"StatoProdMacchina.{source}"; + int numRec = esCollect.RecordCall(callName, sw.Elapsed.TotalMilliseconds); + if (numRec >= nRecLog) + { + Log.Debug(esCollect.GetCallSum(callName, true)); + } return result; } + /// + /// numero minimo di record per cui iniziare fase di log + /// + private int nRecLog = 10; + /// /// Turno macchina ///