2
2
* Process Hacker Network Tools -
3
3
* Ping dialog
4
4
*
5
- * Copyright (C) 2015 dmex
5
+ * Copyright (C) 2015-2021 dmex
6
6
*
7
7
* This file is part of Process Hacker.
8
8
*
21
21
*/
22
22
23
23
#include "nettools.h"
24
- #include <commonutil .h>
24
+ #include <math .h>
25
25
26
26
#define WM_PING_UPDATE (WM_APP + 151)
27
27
@@ -42,7 +42,7 @@ NTSTATUS NetworkPingThreadStart(
42
42
PPH_STRING icmpRandString = NULL ;
43
43
IP_OPTION_INFORMATION pingOptions =
44
44
{
45
- 255 , // Time To Live
45
+ UCHAR_MAX , // Time To Live
46
46
0 , // Type Of Service
47
47
IP_FLAG_DF , // IP header flags
48
48
0 // Size of options data
@@ -253,7 +253,7 @@ VOID NetworkPingUpdateGraph(
253
253
)
254
254
{
255
255
Context -> PingGraphState .Valid = FALSE;
256
- Context -> PingGraphState .TooltipIndex = -1 ;
256
+ Context -> PingGraphState .TooltipIndex = ULONG_MAX ;
257
257
Graph_MoveGrid (Context -> PingGraphHandle , 1 );
258
258
Graph_Draw (Context -> PingGraphHandle );
259
259
Graph_UpdateTooltip (Context -> PingGraphHandle );
@@ -326,6 +326,8 @@ INT_PTR CALLBACK NetworkPingWndProc(
326
326
PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_ICMP_MAX ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
327
327
PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_PINGS_SENT ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
328
328
PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_PINGS_LOST ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
329
+ PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_ICMP_STDEV ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
330
+ PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_ICMP_STVAR ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
329
331
PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_BAD_HASH ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
330
332
PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_ANON_ADDR ), NULL , PH_ANCHOR_BOTTOM | PH_ANCHOR_LEFT );
331
333
panelItem = PhAddLayoutItem (& context -> LayoutManager , GetDlgItem (hwndDlg , IDC_PING_LAYOUT ), NULL , PH_ANCHOR_ALL );
@@ -401,19 +403,35 @@ INT_PTR CALLBACK NetworkPingWndProc(
401
403
break ;
402
404
case WM_PING_UPDATE :
403
405
{
404
- ULONG maxGraphHeight = 0 ;
405
- ULONG pingAvgValue = 0 ;
406
+ ULONG pingHistoryValue = 0 ;
407
+ ULONG pingSumValue = 0 ;
408
+ DOUBLE pingAvgMeanValue = 0 ;
409
+ DOUBLE pingDeviationValue = 0 ;
410
+ DOUBLE pingVarianceValue = 0 ;
406
411
407
- NetworkPingUpdateGraph (context );
412
+ for (ULONG i = 0 ; i < context -> PingHistory .Count ; i ++ )
413
+ {
414
+ pingSumValue += PhGetItemCircularBuffer_ULONG (& context -> PingHistory , i );
415
+ }
416
+
417
+ pingAvgMeanValue = (DOUBLE )pingSumValue / context -> PingHistory .Count ;
408
418
409
419
for (ULONG i = 0 ; i < context -> PingHistory .Count ; i ++ )
410
420
{
411
- maxGraphHeight = maxGraphHeight + PhGetItemCircularBuffer_ULONG (& context -> PingHistory , i );
412
- pingAvgValue = maxGraphHeight / context -> PingHistory .Count ;
421
+ pingHistoryValue = PhGetItemCircularBuffer_ULONG (& context -> PingHistory , i );
422
+
423
+ pingDeviationValue += pow (pingHistoryValue - pingAvgMeanValue , 2 );
424
+ }
425
+
426
+ if (context -> PingHistory .Count )
427
+ {
428
+ pingVarianceValue = pingDeviationValue / context -> PingHistory .Count ;
429
+
430
+ pingDeviationValue = sqrt (pingVarianceValue );
413
431
}
414
432
415
433
PhSetDialogItemText (hwndDlg , IDC_ICMP_AVG , PhaFormatString (
416
- L"Average: %lums" , pingAvgValue )-> Buffer );
434
+ L"Average: %lums" , ( ULONG ) pingAvgMeanValue )-> Buffer );
417
435
PhSetDialogItemText (hwndDlg , IDC_ICMP_MIN , PhaFormatString (
418
436
L"Minimum: %lums" , context -> PingMinMs )-> Buffer );
419
437
PhSetDialogItemText (hwndDlg , IDC_ICMP_MAX , PhaFormatString (
@@ -425,6 +443,11 @@ INT_PTR CALLBACK NetworkPingWndProc(
425
443
L"Pings lost: %lu (%.0f%%)" , context -> PingLossCount ,
426
444
((DOUBLE )context -> PingLossCount / context -> PingSentCount * 100 ))-> Buffer );
427
445
446
+ PhSetDialogItemText (hwndDlg , IDC_ICMP_STDEV , PhaFormatString (
447
+ L"Deviation: %.2f" , pingDeviationValue )-> Buffer );
448
+ PhSetDialogItemText (hwndDlg , IDC_ICMP_STVAR , PhaFormatString (
449
+ L"Variance: %.2f" , pingVarianceValue )-> Buffer );
450
+
428
451
//PhSetDialogItemText(hwndDlg, IDC_BAD_HASH, PhaFormatString(
429
452
// L"Bad hashes: %lu", context->HashFailCount)->Buffer);
430
453
PhSetDialogItemText (hwndDlg , IDC_ANON_ADDR , PhaFormatString (
0 commit comments