Skip to content

Commit a1b83c1

Browse files
committed
prepare discard stats
Signed-off-by: Anthoine Bourgeois <[email protected]>
1 parent f219fe1 commit a1b83c1

File tree

4 files changed

+145
-5
lines changed

4 files changed

+145
-5
lines changed

ocaml/xcp-rrdd/bin/read-blktap-stats/read_blktap_stats.ml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ let () =
3636
Printf.printf "write_sectors = %Ld\n" (get_stats_write_sectors s) ;
3737
Printf.printf "write_total_ticks = %Ld\n" (get_stats_write_total_ticks s) ;
3838
Printf.printf "io_errors = %Ld\n" (get_stats_io_errors s) ;
39-
Printf.printf "flags = %Ld\n" (get_stats_flags s)
39+
Printf.printf "flags = %Ld\n" (get_stats_flags s) ;
40+
Printf.printf "discard_reqs_submitted = %Ld\n"
41+
(get_stats_discard_reqs_submitted s) ;
42+
Printf.printf "discard_reqs_completed = %Ld\n"
43+
(get_stats_discard_reqs_completed s) ;
44+
Printf.printf "discard_sectors = %Ld\n" (get_stats_discard_sectors s) ;
45+
Printf.printf "discard_total_ticks = %Ld\n"
46+
(get_stats_discard_total_ticks s)
4047
| _ ->
4148
usage ()

ocaml/xcp-rrdd/bin/rrdp-iostat/rrdp_iostat.ml

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,12 +590,16 @@ module Stats_value = struct
590590
type t = {
591591
rd_bytes: int64
592592
; wr_bytes: int64
593+
; ds_bytes: int64
593594
; rd_avg_usecs: int64
594595
; wr_avg_usecs: int64
596+
; ds_avg_usecs: int64
595597
; io_throughput_read_mb: float
596598
; io_throughput_write_mb: float
599+
; io_throughput_discard_mb: float
597600
; iops_read: int64
598601
; iops_write: int64
602+
; iops_discard: int64
599603
; iowait: float
600604
; inflight: int64
601605
}
@@ -604,12 +608,16 @@ module Stats_value = struct
604608
{
605609
rd_bytes= 0L
606610
; wr_bytes= 0L
611+
; ds_bytes= 0L
607612
; rd_avg_usecs= 0L
608613
; wr_avg_usecs= 0L
614+
; ds_avg_usecs= 0L
609615
; io_throughput_read_mb= 0.
610616
; io_throughput_write_mb= 0.
617+
; io_throughput_discard_mb= 0.
611618
; iops_read= 0L
612619
; iops_write= 0L
620+
; iops_discard= 0L
613621
; iowait= 0.
614622
; inflight= 0L
615623
}
@@ -632,6 +640,7 @@ module Stats_value = struct
632640
{
633641
rd_bytes= stats_diff_get 13
634642
; wr_bytes= stats_diff_get 14
643+
; ds_bytes= 0L
635644
; rd_avg_usecs=
636645
( if stats_diff_get 0 > 0L then
637646
Int64.div (stats_diff_get 3) (stats_diff_get 0)
@@ -644,10 +653,13 @@ module Stats_value = struct
644653
else
645654
0L
646655
)
656+
; ds_avg_usecs= 0L
647657
; io_throughput_read_mb= to_float (stats_diff_get 13) /. 1048576.
648658
; io_throughput_write_mb= to_float (stats_diff_get 14) /. 1048576.
659+
; io_throughput_discard_mb= 0.
649660
; iops_read= stats_diff_get 0
650661
; iops_write= stats_diff_get 4
662+
; iops_discard= 0L
651663
; iowait= to_float (stats_diff_get 10) /. 1000.
652664
; inflight= stats_get 8
653665
}
@@ -686,12 +698,16 @@ module Stats_value = struct
686698
{
687699
rd_bytes= Int64.mul (get_stats_read_sectors s3) 512L
688700
; wr_bytes= Int64.mul (get_stats_write_sectors s3) 512L
701+
; ds_bytes= Int64.mul (get_stats_discard_sectors s3) 512L
689702
; rd_avg_usecs=
690703
avg_reqs_completed_last_five_secs get_stats_read_reqs_completed
691704
get_stats_read_total_ticks
692705
; wr_avg_usecs=
693706
avg_reqs_completed_last_five_secs get_stats_write_reqs_completed
694707
get_stats_write_total_ticks
708+
; ds_avg_usecs=
709+
avg_reqs_completed_last_five_secs get_stats_discard_reqs_completed
710+
get_stats_discard_total_ticks
695711
; io_throughput_read_mb=
696712
to_float
697713
(get_stats_read_sectors s3 -- opt get_stats_read_sectors last_s3)
@@ -702,12 +718,22 @@ module Stats_value = struct
702718
(get_stats_write_sectors s3 -- opt get_stats_write_sectors last_s3)
703719
*. 512.
704720
/. 1048576.
721+
; io_throughput_discard_mb=
722+
to_float
723+
(get_stats_discard_sectors s3
724+
-- opt get_stats_discard_sectors last_s3
725+
)
726+
*. 512.
727+
/. 1048576.
705728
; iops_read=
706729
get_stats_read_reqs_completed s3
707730
-- opt get_stats_read_reqs_completed last_s3
708731
; iops_write=
709732
get_stats_write_reqs_completed s3
710733
-- opt get_stats_write_reqs_completed last_s3
734+
; iops_discard=
735+
get_stats_discard_reqs_completed s3
736+
-- opt get_stats_discard_reqs_completed last_s3
711737
; iowait=
712738
to_float
713739
(get_stats_read_total_ticks s3
@@ -736,12 +762,17 @@ module Stats_value = struct
736762
; rd_avg_usecs= acc.rd_avg_usecs ++ v.rd_avg_usecs
737763
; wr_bytes= acc.wr_bytes ++ v.wr_bytes
738764
; wr_avg_usecs= acc.wr_avg_usecs ++ v.wr_avg_usecs
765+
; ds_bytes= acc.ds_bytes ++ v.ds_bytes
766+
; ds_avg_usecs= acc.ds_avg_usecs ++ v.ds_avg_usecs
739767
; io_throughput_read_mb=
740768
acc.io_throughput_read_mb +. v.io_throughput_read_mb
741769
; io_throughput_write_mb=
742770
acc.io_throughput_write_mb +. v.io_throughput_write_mb
771+
; io_throughput_discard_mb=
772+
acc.io_throughput_discard_mb +. v.io_throughput_discard_mb
743773
; iops_read= acc.iops_read ++ v.iops_read
744774
; iops_write= acc.iops_write ++ v.iops_write
775+
; iops_discard= acc.iops_discard ++ v.iops_discard
745776
; iowait= acc.iowait +. v.iowait
746777
; inflight= acc.inflight ++ v.inflight
747778
}
@@ -763,6 +794,12 @@ module Stats_value = struct
763794
~value:(Rrd.VT_Int64 value.wr_bytes) ~ty:Rrd.Derive ~units:"B/s"
764795
~min:0.0 ()
765796
)
797+
; ( owner
798+
, ds_make ~name:(key_format "discard")
799+
~description:("Discards from device " ^ name ^ ", in B/s")
800+
~value:(Rrd.VT_Int64 value.ds_bytes) ~ty:Rrd.Derive ~units:"B/s"
801+
~min:0.0 ()
802+
)
766803
; ( owner
767804
, ds_make
768805
~name:(key_format "read_latency")
@@ -778,6 +815,14 @@ module Stats_value = struct
778815
~value:(Rrd.VT_Int64 value.wr_avg_usecs) ~ty:Rrd.Gauge ~units:"μs"
779816
~min:0.0 ()
780817
)
818+
; ( owner
819+
, ds_make
820+
~name:(key_format "discard_latency")
821+
~description:
822+
("Discard latency from device " ^ name ^ ", in microseconds")
823+
~value:(Rrd.VT_Int64 value.ds_avg_usecs) ~ty:Rrd.Gauge ~units:"μs"
824+
~min:0.0 ()
825+
)
781826
; ( owner
782827
, ds_make
783828
~name:(key_format "io_throughput_read")
@@ -792,6 +837,13 @@ module Stats_value = struct
792837
~value:(Rrd.VT_Float value.io_throughput_write_mb) ~ty:Rrd.Absolute
793838
~units:"MiB/s" ~min:0. ()
794839
)
840+
; ( owner
841+
, ds_make
842+
~name:(key_format "io_throughput_discard")
843+
~description:("Data discard to the " ^ name ^ ", in MiB/s")
844+
~value:(Rrd.VT_Float value.io_throughput_discard_mb) ~ty:Rrd.Absolute
845+
~units:"MiB/s" ~min:0. ()
846+
)
795847
; ( owner
796848
, ds_make
797849
~name:(key_format "io_throughput_total")
@@ -814,10 +866,22 @@ module Stats_value = struct
814866
~value:(Rrd.VT_Int64 value.iops_write) ~ty:Rrd.Absolute
815867
~units:"requests/s" ~min:0. ()
816868
)
869+
; ( owner
870+
, ds_make
871+
~name:(key_format "iops_discard")
872+
~description:"Discard requests per second"
873+
~value:(Rrd.VT_Int64 value.iops_discard) ~ty:Rrd.Absolute
874+
~units:"requests/s" ~min:0. ()
875+
)
817876
; ( owner
818877
, ds_make ~name:(key_format "iops_total")
819878
~description:"I/O Requests per second"
820-
~value:(Rrd.VT_Int64 (Int64.add value.iops_read value.iops_write))
879+
~value:
880+
(Rrd.VT_Int64
881+
(Int64.add value.iops_read
882+
(Int64.add value.iops_write value.iops_discard)
883+
)
884+
)
821885
~ty:Rrd.Absolute ~units:"requests/s" ~min:0. ()
822886
)
823887
; ( owner
@@ -855,15 +919,19 @@ module Iostats_value = struct
855919
let s3_usecs =
856920
get_stats_read_total_ticks s3
857921
++ get_stats_write_total_ticks s3
922+
++ get_stats_discard_total_ticks s3
858923
-- (opt get_stats_read_total_ticks last_s3
859924
++ opt get_stats_write_total_ticks last_s3
925+
++ opt get_stats_discard_total_ticks last_s3
860926
)
861927
in
862928
let s3_count =
863929
get_stats_read_reqs_completed s3
864930
++ get_stats_write_reqs_completed s3
931+
++ get_stats_discard_reqs_completed s3
865932
-- (opt get_stats_read_reqs_completed last_s3
866933
++ opt get_stats_write_reqs_completed last_s3
934+
++ opt get_stats_discard_reqs_completed last_s3
867935
)
868936
in
869937
let s3_latency_average =
@@ -874,8 +942,10 @@ module Iostats_value = struct
874942
to_float
875943
(get_stats_read_total_ticks s3
876944
++ get_stats_write_total_ticks s3
945+
++ get_stats_discard_total_ticks s3
877946
-- (opt get_stats_read_total_ticks last_s3
878947
++ opt get_stats_write_total_ticks last_s3
948+
++ opt get_stats_discard_total_ticks last_s3
879949
)
880950
)
881951
/. 1000_000.0

ocaml/xcp-rrdd/lib/blktap/lib/blktap3_stats.ml

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,28 @@ type stats = {
4242
}
4343
[@@little_endian]]
4444

45+
[%%cstruct
46+
type stats_v2 = {
47+
_v1_version: uint32_t
48+
; _v1_pad: uint32_t
49+
; _v1_oo_reqs: uint64_t
50+
; _v1_read_reqs_submitted: uint64_t
51+
; _v1_read_reqs_completed: uint64_t
52+
; _v1_read_sectors: uint64_t
53+
; _v1_read_total_ticks: uint64_t
54+
; _v1_write_reqs_submitted: uint64_t
55+
; _v1_write_reqs_completed: uint64_t
56+
; _v1_write_sectors: uint64_t
57+
; _v1_write_total_ticks: uint64_t
58+
; _v1_io_errors: uint64_t
59+
; _v1_flags: uint64_t
60+
; discard_reqs_submitted: uint64_t
61+
; discard_reqs_completed: uint64_t
62+
; discard_sectors: uint64_t
63+
; discard_total_ticks: uint64_t
64+
}
65+
[@@little_endian]]
66+
4567
let of_file f =
4668
let fd = Unix.(openfile f [O_RDONLY] 0o000) in
4769
try
@@ -51,6 +73,39 @@ let of_file f =
5173

5274
let copy : t -> t =
5375
fun t ->
54-
let t' = Cstruct.create_unsafe sizeof_stats in
55-
Cstruct.blit t 0 t' 0 sizeof_stats ;
56-
t'
76+
let size =
77+
if get_stats_version t >= 2l then
78+
sizeof_stats_v2
79+
else
80+
sizeof_stats
81+
in
82+
let t' = Cstruct.create_unsafe size in
83+
Cstruct.blit t 0 t' 0 size ; t'
84+
85+
let get_stats_discard_reqs_submitted : t -> Cstruct.uint64 =
86+
fun t ->
87+
if get_stats_version t >= 2l then
88+
get_stats_v2_discard_reqs_submitted t
89+
else
90+
0L
91+
92+
let get_stats_discard_reqs_completed : t -> Cstruct.uint64 =
93+
fun t ->
94+
if get_stats_version t >= 2l then
95+
get_stats_v2_discard_reqs_completed t
96+
else
97+
0L
98+
99+
let get_stats_discard_sectors : t -> Cstruct.uint64 =
100+
fun t ->
101+
if get_stats_version t >= 2l then
102+
get_stats_v2_discard_sectors t
103+
else
104+
0L
105+
106+
let get_stats_discard_total_ticks : t -> Cstruct.uint64 =
107+
fun t ->
108+
if get_stats_version t >= 2l then
109+
get_stats_v2_discard_total_ticks t
110+
else
111+
0L

ocaml/xcp-rrdd/lib/blktap/lib/blktap3_stats.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ val get_stats_io_errors : t -> Cstruct.uint64
4444

4545
val get_stats_flags : t -> Cstruct.uint64
4646

47+
val get_stats_discard_reqs_submitted : t -> Cstruct.uint64
48+
49+
val get_stats_discard_reqs_completed : t -> Cstruct.uint64
50+
51+
val get_stats_discard_sectors : t -> Cstruct.uint64
52+
53+
val get_stats_discard_total_ticks : t -> Cstruct.uint64
54+
4755
val of_file : string -> t
4856

4957
val copy : t -> t

0 commit comments

Comments
 (0)