Skip to content

Commit 74c09b6

Browse files
committed
latency-histogram: include min,max,stddev
Also: When a bin had only one count, it was not showing when using y axis logscale -- so alter bin value from 1 to 1.1 to appear as a pip above the yaxis 1E0 line. Rearrange documenting lines for better fit with --nobase Suggested by Peter Wallace Thanks to jepler for rtapi_math64 with rtapi_div_u64 Signed-off-by: Dewey Garrett <dgarrett@panix.com>
1 parent 04d117c commit 74c09b6

File tree

3 files changed

+83
-16
lines changed

3 files changed

+83
-16
lines changed
20.9 KB
Loading

scripts/latency-histogram

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ proc config {} {
187187
exit 1
188188
}
189189

190-
set ::LH(title) "$::argv0 $::LH(note,txt)"
190+
set ::LH(title) "$::argv0"
191191
wm title . $::LH(title)
192192

193193
foreach thd $::LH(threads) {
@@ -226,14 +226,10 @@ proc other_info {} {
226226
}
227227
set linuxcncversion [exec linuxcnc_var LINUXCNCVERSION]
228228
return "\
229-
$::LH(date) \
230-
[exec hostname] \
231229
$::tcl_platform(machine) \
232230
$::tcl_platform(osVersion) \
233231
$linuxcncversion \
234232
$display \
235-
$::tcl_platform(user) \
236-
$::LH(note,txt) \
237233
"
238234
} ;# other_info
239235

@@ -340,10 +336,18 @@ proc load_packages {} {
340336
proc make_gui { {w .} } {
341337
set f [frame ${w}fa]
342338
pack $f -side top -fill x -expand 1
343-
pack [label $f.l -anchor w -text $::LH(info)] -fill x -expand 1
339+
set hname [exec hostname]
340+
set user $::tcl_platform(user)
341+
pack [label $f.l -anchor w \
342+
-text "$::LH(date) $hname $user $::LH(note,txt)"
343+
] -fill x -expand 1
344344

345345
set f [frame ${w}fb]
346346
pack $f -side top -fill x -expand 1
347+
pack [label $f.l -anchor w -text $::LH(info)] -fill x -expand 1
348+
349+
set f [frame ${w}fc]
350+
pack $f -side top -fill x -expand 1
347351
pack [label $f.l -anchor w -text $::LH(processor)] -fill x -expand 1
348352

349353
set fmain [frame ${w}fmain]
@@ -369,8 +373,29 @@ proc make_gui { {w .} } {
369373
xaxis $thd
370374
$::LH(w,$thd) axis configure y -logscale $::LH(y,logscale)
371375

376+
set f [frame $f1.extra12]
377+
pack $f -side top -anchor w -fill x -expand 1
378+
379+
pack [label $f.min -text "min (us)"] \
380+
-side left -anchor e
381+
set e [entry $f.emin -textvariable ::LH($thd,latency_min,us) \
382+
-state readonly -justify right -width 9]
383+
pack $e -side left -anchor e
384+
385+
pack [label $f.sdev -text " sdev (us):"] \
386+
-side left
387+
set e [entry $f.esdev -textvariable ::LH($thd,latency_sdev,us) \
388+
-state readonly -justify right -width 9]
389+
pack $e -side left -anchor e
390+
391+
set e [entry $f.emax -textvariable ::LH($thd,latency_max,us) \
392+
-state readonly -justify right -width 9]
393+
pack $e -side right -anchor e
394+
pack [label $f.max -text "max(us)"] \
395+
-side right -anchor e
396+
372397
if $::LH(opt,show) {
373-
set f [frame $f1.extra]
398+
set f [frame $f1.extra2]
374399
pack $f -side top -anchor w -fill x -expand 1
375400
set e [entry $f.emin -textvariable ::LH($thd,n,more) \
376401
-state readonly -justify right -width 9]
@@ -511,6 +536,9 @@ proc reset_data {} {
511536
set ::LH($thd,nextra) 0
512537
set ::LH($thd,p,more) 0
513538
set ::LH($thd,n,more) 0
539+
set ::LH($thd,latency_min,us) ""
540+
set ::LH($thd,latency_max,us) ""
541+
set ::LH($thd,latency_sdev,us) ""
514542
}
515543
after 100
516544
foreach thd $::LH(threads) {
@@ -647,10 +675,9 @@ proc update_chart {thd} {
647675
set pbin [hal getp $::LH($thd,name).pbinvalue]
648676
set nbin [hal getp $::LH($thd,name).nbinvalue]
649677

650-
#verify index in range
651-
#if { ($pbin < 0) || ($nbin < 0) } {
652-
# puts stderr "Unexpected: thd=$thd index=$bin pbin=$pbin, nbin=$nbin"
653-
#}
678+
# 1.1 value makes single unit bins show as pips when using log y scale:
679+
if {$pbin == 1} {set pbin 1.1}
680+
if {$nbin == 1} {set nbin 1.1}
654681

655682
lappend pxd [expr $bin * $::LH($thd,binsize,us)]
656683
lappend pyd $pbin
@@ -664,6 +691,19 @@ proc update_chart {thd} {
664691
}
665692
} ;# for bin
666693

694+
set ::LH($thd,latency_min,us) [format %.1f \
695+
[expr 1e-3 * [hal getp $::LH($thd,name).latency-min]]]
696+
set ::LH($thd,latency_max,us) [format %.1f \
697+
[expr 1e-3 * [hal getp $::LH($thd,name).latency-max]]]
698+
699+
set variance [hal getp $::LH($thd,name).variance]
700+
if [catch {
701+
set ::LH($thd,latency_sdev,us) [format %.1f \
702+
[expr 1e-3 * sqrt($variance)]]
703+
} msg] {
704+
puts msg=$msg
705+
}
706+
667707
set ::LH($thd,pextra) [hal getp $::LH($thd,name).pextra]
668708
set ::LH($thd,p,more) [expr $pmore + $::LH($thd,pextra)]
669709

src/hal/components/latencybins.comp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ Usage:
1313
Iterate:
1414
Set index pin to a bin number: 0 <= index <= maxbinnumber.
1515
Read check pin and verify that check pin == index pin.
16-
Read pbinvalue,nbinvalue,pextra,nextra pins.
17-
(pbinvalue is count for bin = +index)
18-
(nbinvalue is count for bin = -index)
19-
(pextra is count for all bins > maxbinnumber)
20-
(nextra is count for all bins < maxbinnumber)
16+
Read output pins:
17+
pbinvalue is count for bin = +index
18+
nbinvalue is count for bin = -index
19+
pextra is count for all bins > maxbinnumber
20+
nextra is count for all bins < maxbinnumber
21+
latency-min is max negative latency
22+
latency-max is max positive latency
2123

2224
If index is out of range ( index < 0 or index > maxbinnumber)
2325
then pbinvalue = nbinvalue = -1.
@@ -34,10 +36,13 @@ pin in s32 nsbinsize;
3436

3537
pin out s32 check;
3638
pin out s32 latency;
39+
pin out s32 latency_max;
40+
pin out s32 latency_min;
3741
pin out s32 pbinvalue;
3842
pin out s32 nbinvalue;
3943
pin out s32 pextra;
4044
pin out s32 nextra;
45+
pin out s32 variance;
4146

4247
// user may interrogate available bins to determine this compiled-in limit
4348
pin out s32 availablebins = 1000; // MAXBINNUMBER
@@ -50,6 +55,10 @@ variable int pbins[1001]; // MAXBINNUMBER+1
5055
variable int nbins[1001]; // MAXBINNUMBER+1
5156
variable int binmax = 0;
5257

58+
variable rtapi_u32 nsamples;
59+
variable rtapi_u64 sum;
60+
variable rtapi_u64 sq_sum;
61+
5362
license "GPL";
5463
;;
5564

@@ -73,13 +82,20 @@ if ( first
7382
) {
7483
first = 0;
7584
latency = 0;
85+
latency_min = 0x7FFFFFFF;
86+
latency_max = 0x80000000;
7687
pextra = 0; nextra = 0;
7788
for (i = 0; i <= binmax; i++) {
7889
pbins[i] = 0; nbins[i] = 0;
7990
}
91+
nsamples = 0;
92+
sum = 0;
93+
sq_sum = 0;
8094
} else {
8195
latency = lat32;
8296
i = lat32/nsbinsize;
97+
if (lat32 > latency_max) latency_max = lat32;
98+
if (lat32 < latency_min) latency_min = lat32;
8399
if (i >= 0) {
84100
if (i > binmax) {
85101
pextra++;
@@ -94,6 +110,17 @@ if ( first
94110
nbins[i]++;
95111
}
96112
}
113+
nsamples++;
114+
sum += lat32;
115+
sq_sum += lat32 * lat32;
116+
if (nsamples > 1) {
117+
// note: divison required is: u64/u32
118+
rtapi_u64 dividend;
119+
rtapi_u64 divisor;
120+
dividend = sq_sum - rtapi_div_u64(sum * sum,nsamples);
121+
divisor = nsamples -1;
122+
variance = rtapi_div_u64(dividend,divisor);
123+
}
97124
}
98125

99126
check = index; // user should verify check==index for reading values

0 commit comments

Comments
 (0)