Skip to content

Commit

Permalink
CP-52524 - dbsync_slave: stop calculating boot time ourselves
Browse files Browse the repository at this point in the history
Completes the 15+ years old TODO, at the expense of removing an ultimate
example of a "not invented here" attitude.

Signed-off-by: Andrii Sultanov <andrii.sultanov@cloud.com>
  • Loading branch information
last-genius committed Nov 22, 2024
1 parent 7c62ede commit 228071a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
27 changes: 15 additions & 12 deletions ocaml/xapi/dbsync_slave.ml
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,24 @@ let create_localhost ~__context info =
in
()

(* TODO cat /proc/stat for btime ? *)
let get_start_time () =
try
debug "Calculating boot time..." ;
let now = Unix.time () in
let uptime = Unixext.string_of_file "/proc/uptime" in
let uptime = String.trim uptime in
let uptime = String.split ' ' uptime in
let uptime = List.hd uptime in
let uptime = float_of_string uptime in
let boot_time = Date.of_unix_time (now -. uptime) in
debug " system booted at %s" (Date.to_rfc3339 boot_time) ;
boot_time
match
Unixext.string_of_file "/proc/stat"
|> String.trim
|> String.split '\n'
|> List.find (fun s -> String.starts_with ~prefix:"btime" s)
|> String.split ' '
with
| _ :: btime :: _ ->
let boot_time = Date.of_unix_time (float_of_string btime) in
debug "%s: system booted at %s" __FUNCTION__ (Date.to_rfc3339 boot_time) ;
boot_time
| _ ->
failwith "Couldn't parse /proc/stat"
with e ->
debug "Calculating boot time failed with '%s'" (ExnHelper.string_of_exn e) ;
debug "%s: Calculating boot time failed with '%s'" __FUNCTION__
(ExnHelper.string_of_exn e) ;
Date.epoch

(* not sufficient just to fill in this data on create time [Xen caps may change if VT enabled in BIOS etc.] *)
Expand Down
2 changes: 1 addition & 1 deletion quality-gate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

list-hd () {
N=294
N=293
LIST_HD=$(git grep -r --count 'List.hd' -- **/*.ml | cut -d ':' -f 2 | paste -sd+ - | bc)
if [ "$LIST_HD" -eq "$N" ]; then
echo "OK counted $LIST_HD List.hd usages"
Expand Down

0 comments on commit 228071a

Please sign in to comment.