Update x statistiche SIM multi-thread
This commit is contained in:
+36
-21
@@ -42,10 +42,11 @@ Partial Class ProcMan
|
||||
Me.TimerUI = New System.Windows.Forms.Timer(Me.components)
|
||||
Me.TimerProgBar = New System.Windows.Forms.Timer(Me.components)
|
||||
Me.LISTThreadStatus = New System.Windows.Forms.ListView()
|
||||
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
|
||||
Me.chThread = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
|
||||
Me.chJob = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
|
||||
Me.chTime = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
|
||||
Me.chOther = CType(New System.Windows.Forms.ColumnHeader(), System.Windows.Forms.ColumnHeader)
|
||||
Me.GroupBox1 = New System.Windows.Forms.GroupBox()
|
||||
Me.chkStatAggr = New System.Windows.Forms.CheckBox()
|
||||
Me.StatusStrip1.SuspendLayout()
|
||||
Me.GroupBox1.SuspendLayout()
|
||||
Me.SuspendLayout()
|
||||
@@ -140,7 +141,7 @@ Partial Class ProcMan
|
||||
Me.StatusStrip1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.tsProgBar})
|
||||
Me.StatusStrip1.Location = New System.Drawing.Point(0, 423)
|
||||
Me.StatusStrip1.Name = "StatusStrip1"
|
||||
Me.StatusStrip1.Size = New System.Drawing.Size(510, 22)
|
||||
Me.StatusStrip1.Size = New System.Drawing.Size(552, 22)
|
||||
Me.StatusStrip1.TabIndex = 11
|
||||
Me.StatusStrip1.Text = "StatusStrip1"
|
||||
'
|
||||
@@ -200,17 +201,33 @@ Partial Class ProcMan
|
||||
'
|
||||
'LISTThreadStatus
|
||||
'
|
||||
Me.LISTThreadStatus.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chThread, Me.chJob, Me.chTime})
|
||||
Me.LISTThreadStatus.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.chThread, Me.chTime, Me.chOther})
|
||||
Me.LISTThreadStatus.HideSelection = False
|
||||
Me.LISTThreadStatus.Location = New System.Drawing.Point(13, 48)
|
||||
Me.LISTThreadStatus.Name = "LISTThreadStatus"
|
||||
Me.LISTThreadStatus.Size = New System.Drawing.Size(306, 302)
|
||||
Me.LISTThreadStatus.Size = New System.Drawing.Size(403, 302)
|
||||
Me.LISTThreadStatus.TabIndex = 16
|
||||
Me.LISTThreadStatus.UseCompatibleStateImageBehavior = False
|
||||
Me.LISTThreadStatus.View = System.Windows.Forms.View.Details
|
||||
'
|
||||
'chThread
|
||||
'
|
||||
Me.chThread.Text = "Thread"
|
||||
Me.chThread.Width = 100
|
||||
'
|
||||
'chTime
|
||||
'
|
||||
Me.chTime.Text = "Time"
|
||||
Me.chTime.Width = 100
|
||||
'
|
||||
'chOther
|
||||
'
|
||||
Me.chOther.Text = "Other"
|
||||
Me.chOther.Width = 100
|
||||
'
|
||||
'GroupBox1
|
||||
'
|
||||
Me.GroupBox1.Controls.Add(Me.chkStatAggr)
|
||||
Me.GroupBox1.Controls.Add(Me.LISTThreadStatus)
|
||||
Me.GroupBox1.Controls.Add(Me.lblRunning)
|
||||
Me.GroupBox1.Controls.Add(Me.txtNumThread)
|
||||
@@ -219,31 +236,28 @@ Partial Class ProcMan
|
||||
Me.GroupBox1.Controls.Add(Me.StartProcess)
|
||||
Me.GroupBox1.Location = New System.Drawing.Point(118, 64)
|
||||
Me.GroupBox1.Name = "GroupBox1"
|
||||
Me.GroupBox1.Size = New System.Drawing.Size(338, 356)
|
||||
Me.GroupBox1.Size = New System.Drawing.Size(422, 356)
|
||||
Me.GroupBox1.TabIndex = 17
|
||||
Me.GroupBox1.TabStop = False
|
||||
Me.GroupBox1.Text = "Threads"
|
||||
'
|
||||
'chThread
|
||||
'chkStatAggr
|
||||
'
|
||||
Me.chThread.Text = "Thread"
|
||||
Me.chThread.Width = 20
|
||||
'
|
||||
'chJob
|
||||
'
|
||||
Me.chJob.Text = "Job"
|
||||
Me.chJob.Width = 100
|
||||
'
|
||||
'chTime
|
||||
'
|
||||
Me.chTime.Text = "Time"
|
||||
Me.chTime.Width = 180
|
||||
Me.chkStatAggr.AutoSize = True
|
||||
Me.chkStatAggr.Checked = True
|
||||
Me.chkStatAggr.CheckState = System.Windows.Forms.CheckState.Checked
|
||||
Me.chkStatAggr.Location = New System.Drawing.Point(326, 21)
|
||||
Me.chkStatAggr.Name = "chkStatAggr"
|
||||
Me.chkStatAggr.Size = New System.Drawing.Size(75, 17)
|
||||
Me.chkStatAggr.TabIndex = 17
|
||||
Me.chkStatAggr.Text = "Aggr Stats"
|
||||
Me.chkStatAggr.UseVisualStyleBackColor = True
|
||||
'
|
||||
'ProcMan
|
||||
'
|
||||
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
|
||||
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
|
||||
Me.ClientSize = New System.Drawing.Size(510, 445)
|
||||
Me.ClientSize = New System.Drawing.Size(552, 445)
|
||||
Me.Controls.Add(Me.GroupBox1)
|
||||
Me.Controls.Add(Me.txtQueue)
|
||||
Me.Controls.Add(Me.StatusStrip1)
|
||||
@@ -286,6 +300,7 @@ Partial Class ProcMan
|
||||
Friend WithEvents LISTThreadStatus As ListView
|
||||
Friend WithEvents GroupBox1 As GroupBox
|
||||
Friend WithEvents chThread As ColumnHeader
|
||||
Friend WithEvents chJob As ColumnHeader
|
||||
Friend WithEvents chTime As ColumnHeader
|
||||
Friend WithEvents chOther As ColumnHeader
|
||||
Friend WithEvents chkStatAggr As CheckBox
|
||||
End Class
|
||||
|
||||
@@ -535,6 +535,8 @@ Public Class ProcMan
|
||||
Dim sExePath As String = "c:\EgtProg\EgtEngine\EgtEngineR32.exe"
|
||||
Dim sCurrDdfDir As String = "c:\EgtData\WebDoor\Ddf"
|
||||
Dim stopWatch As New Stopwatch()
|
||||
Dim lExeTime As Long = 0
|
||||
Dim lOtherTime As Long = 0
|
||||
|
||||
While Not m_bStopProcess
|
||||
|
||||
@@ -548,8 +550,8 @@ Public Class ProcMan
|
||||
If bOk Then
|
||||
|
||||
' avvio cronometro
|
||||
stopWatch.Reset()
|
||||
stopWatch.Start()
|
||||
'stopWatch.Reset()
|
||||
stopWatch.Restart()
|
||||
' svuoto vecchio set file della porta richiesta
|
||||
Dim fileList As String() = Directory.GetFiles(sCurrDdfDir, Item.Key + ".*")
|
||||
' elimino vecchi
|
||||
@@ -580,6 +582,10 @@ Public Class ProcMan
|
||||
While Not Proc.HasExited
|
||||
Thread.Sleep(1)
|
||||
End While
|
||||
' salvo exe time...
|
||||
stopWatch.Stop()
|
||||
lExeTime = stopWatch.ElapsedMilliseconds
|
||||
stopWatch.Restart()
|
||||
Dim procResults As New List(Of CalcResultDTO)
|
||||
Dim currRes As New CalcResultDTO
|
||||
Dim fContent As String = ""
|
||||
@@ -600,9 +606,9 @@ Public Class ProcMan
|
||||
Dim respPut As String = currWDC.SendProcResults(procResults)
|
||||
|
||||
stopWatch.Stop()
|
||||
lOtherTime = stopWatch.ElapsedMilliseconds
|
||||
' aggiorno thread display...
|
||||
UpdateThreadList("0", Item.Key, $"{stopWatch.ElapsedMilliseconds:N2} ms")
|
||||
|
||||
UpdateThreadList(Item.Key, lExeTime, lOtherTime)
|
||||
End If
|
||||
stopWatch.Stop()
|
||||
|
||||
@@ -635,29 +641,64 @@ Public Class ProcMan
|
||||
End If
|
||||
End Sub
|
||||
|
||||
|
||||
Private isUpdatingThreads As Boolean = False
|
||||
''' <summary>
|
||||
''' Esecuzione update display lista stato threads
|
||||
''' </summary>
|
||||
Private Sub UpdateThreadList(tId As String, tStatus As String, tTime As String)
|
||||
Private Sub UpdateThreadList(tId As String, tExeCam As Long, tOther As Long)
|
||||
synchronizationContext.Post(New SendOrPostCallback(
|
||||
Sub(o)
|
||||
'Begin the update
|
||||
LISTThreadStatus.BeginUpdate()
|
||||
' elimino ultimo in coda e metto in testa...
|
||||
Dim maxItems As Integer = 20
|
||||
Dim numItems = LISTThreadStatus.Items.Count
|
||||
If numItems > maxItems Then
|
||||
LISTThreadStatus.Items.RemoveAt(0)
|
||||
If Not isUpdatingThreads Then
|
||||
isUpdatingThreads = True
|
||||
ProcStats.RecordData($"{m_MaxCamInstances}", tExeCam, tOther)
|
||||
ProcStats.RecordList.Enqueue((tId, tExeCam, tOther))
|
||||
'Begin the update
|
||||
LISTThreadStatus.BeginUpdate()
|
||||
LISTThreadStatus.Items.Clear()
|
||||
|
||||
' compilo in base al tipo di stat richiesta
|
||||
If (chkStatAggr.Checked) Then
|
||||
' statistiche di sintesi
|
||||
|
||||
Dim sorted = From pair In ProcStats.ExeCumSum
|
||||
Order By pair.Key
|
||||
For Each item In sorted
|
||||
LISTThreadStatus.Items.Add(
|
||||
New ListViewItem(New String() {item.Key,
|
||||
$"{item.Value.NumRec} x {item.Value.ExeTime / item.Value.NumRec:N2} ms",
|
||||
$"{item.Value.NumRec} x {item.Value.OthTime / item.Value.NumRec:N2} ms"
|
||||
}))
|
||||
Next
|
||||
Else
|
||||
' formato log
|
||||
Dim maxItems As Integer = 15
|
||||
While ProcStats.RecordList.Count > maxItems
|
||||
Dim oldItem As (String, Long, Long) = ("", 0, 0)
|
||||
ProcStats.RecordList.TryDequeue(oldItem)
|
||||
End While
|
||||
|
||||
For Each item As (String, Long, Long) In ProcStats.RecordList.Reverse
|
||||
LISTThreadStatus.Items.Add(New ListViewItem(New String() {
|
||||
item.Item1,
|
||||
$"{item.Item2} ms",
|
||||
$"{item.Item3} ms"
|
||||
}))
|
||||
Next
|
||||
|
||||
|
||||
End If
|
||||
|
||||
'End the update
|
||||
LISTThreadStatus.EndUpdate()
|
||||
isUpdatingThreads = False
|
||||
End If
|
||||
'Add item on top
|
||||
LISTThreadStatus.Items.Add(New ListViewItem(New String() {tId, tStatus, tTime}))
|
||||
'End the update
|
||||
LISTThreadStatus.EndUpdate()
|
||||
End Sub
|
||||
), "")
|
||||
|
||||
End Sub
|
||||
|
||||
|
||||
#End Region
|
||||
|
||||
#If False Then
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,6 +363,5 @@ namespace WebDoorCreator.SDK
|
||||
}
|
||||
|
||||
#endregion Protected Methods
|
||||
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CalcResultDTO.cs" />
|
||||
<Compile Include="ProcStats.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="WDC.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user