Skip to content

Commit 350363f

Browse files
authored
Extend diagnostic-timing-stats to optionally show counts (xapi-project#6703)
The Host.get_diagnostic_timing_stats API call shows mean and SD of time spent. We would like to know how many samples were used to this but can't simmply add this because it could break existing clients. Add an optional flag to include them with a default that maintains the existing behaviour. The `n=xxx` is new and depends on the `counts=true` flag. ``` [root@eu1-dt034 ~]# xe diagnostic-timing-stats counts=true | head host-uuid : 9eb655ef-3249-46fb-beab-d7d12c0acbaf host-name-label: eu1-dt034 Stats reporting thread: 0.000136 [sd = 0.000000, n=1] Sync UEFI certificates on host with XAPI db: 0.012959 [sd = 0.000000, n=1] Db_gc: PGPUs: 0.000006 [sd = 0.000001, n=18] Db_gc: Consoles: 0.000020 [sd = 0.000003, n=18] Cleanup attached pool_updates when start: 0.000003 [sd = 0.000000, n=1] Cancel_tasks.update_all_allowed_operations: SR: 0.000824 [sd = 0.000000, n=1] Db_gc: VTPMs: 0.000001 [sd = 0.000001, n=18] Initialise monitor configuration: 0.001076 [sd = 0.000000, n=1] ```
2 parents f29348b + 1ff2972 commit 350363f

6 files changed

Lines changed: 34 additions & 12 deletions

File tree

ocaml/database/stats.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ let sd (p : Normal_population.t) =
6868
in
6969
sqrt v
7070

71-
let string_of (p : Normal_population.t) =
72-
Printf.sprintf "%f [sd = %f]" (mean p) (sd p)
71+
let string_of ?(counts = false) (p : Normal_population.t) =
72+
match counts with
73+
| false ->
74+
Printf.sprintf "%f [sd = %f]" (mean p) (sd p)
75+
| true ->
76+
Printf.sprintf "%f [sd = %f, n=%d]" (mean p) (sd p) p.n
7377

7478
(** [sample thing t] records new time [t] for population named [thing] *)
7579
let sample (name : string) (x : float) : unit =
@@ -104,7 +108,7 @@ let time_this (name : string) f =
104108
name
105109
)
106110

107-
let summarise () =
111+
let summarise ?(counts = false) () =
108112
with_lock timings_m (fun () ->
109-
Hashtbl.fold (fun k v acc -> (k, string_of v) :: acc) timings []
113+
Hashtbl.fold (fun k v acc -> (k, string_of ~counts v) :: acc) timings []
110114
)

ocaml/database/stats.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15-
val summarise : unit -> (string * string) list
15+
val summarise : ?counts:bool -> unit -> (string * string) list
1616
(** Produce a string name -> string mean, standard deviation summary for each population *)
1717

1818
val time_this : string -> (unit -> 'a) -> 'a

ocaml/idl/datamodel_host.ml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -940,9 +940,26 @@ let get_diagnostic_timing_stats =
940940
]
941941
~name:"get_diagnostic_timing_stats"
942942
~doc:"Return timing statistics for diagnostic purposes"
943-
~params:[(Ref _host, "host", "The host to interrogate")]
944943
~result:(Map (String, String), "population name to summary map")
945-
~hide_from_docs:true ~allowed_roles:_R_READ_ONLY ()
944+
~hide_from_docs:true ~allowed_roles:_R_READ_ONLY
945+
~versioned_params:
946+
[
947+
{
948+
param_type= Ref _host
949+
; param_name= "host"
950+
; param_doc= "The host"
951+
; param_release= miami_release
952+
; param_default= None
953+
}
954+
; {
955+
param_type= Bool
956+
; param_name= "counts"
957+
; param_doc= "Include counts in the result"
958+
; param_release= numbered_release "25.33.0"
959+
; param_default= Some (VBool false)
960+
}
961+
]
962+
()
946963

947964
let create_new_blob =
948965
call ~name:"create_new_blob"

ocaml/xapi-cli-server/cli_operations.ml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,15 @@ let get_file_or_fail fd desc filename =
195195
| Some chunks ->
196196
chunks
197197

198-
let diagnostic_timing_stats printer rpc session_id _params =
198+
let diagnostic_timing_stats printer rpc session_id params =
199+
let counts = get_bool_param params "counts" in
199200
let table_of_host host =
200201
[
201202
("host-uuid", Client.Host.get_uuid ~rpc ~session_id ~self:host)
202203
; ("host-name-label", Client.Host.get_name_label ~rpc ~session_id ~self:host)
203204
]
204205
@
205-
try Client.Host.get_diagnostic_timing_stats ~rpc ~session_id ~host
206+
try Client.Host.get_diagnostic_timing_stats ~rpc ~session_id ~host ~counts
206207
with e -> [("Error", Api_errors.to_string e)]
207208
in
208209
let all = List.map table_of_host (Client.Host.get_all ~rpc ~session_id) in

ocaml/xapi/xapi_host.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,8 +1365,8 @@ let get_thread_diagnostics ~__context ~host:_ =
13651365
let sm_dp_destroy ~__context ~host:_ ~dp ~allow_leak =
13661366
Storage_access.dp_destroy ~__context dp allow_leak
13671367

1368-
let get_diagnostic_timing_stats ~__context ~host:_ =
1369-
Xapi_database.Stats.summarise ()
1368+
let get_diagnostic_timing_stats ~__context ~host:_ ~counts =
1369+
Xapi_database.Stats.summarise ~counts ()
13701370

13711371
(* CP-825: Serialize execution of host-enable-extauth and host-disable-extauth *)
13721372
(* We need to protect against concurrent execution of the extauth-hook script and host.enable/disable extauth, *)

ocaml/xapi/xapi_host.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ val get_system_status_capabilities :
207207
__context:Context.t -> host:API.ref_host -> string
208208

209209
val get_diagnostic_timing_stats :
210-
__context:Context.t -> host:'b -> (string * string) list
210+
__context:Context.t -> host:'b -> counts:bool -> (string * string) list
211211

212212
val set_hostname_live :
213213
__context:Context.t -> host:[`host] Ref.t -> hostname:string -> unit

0 commit comments

Comments
 (0)