# HG changeset patch
# User David Scott <dave.scott@xxxxxxxxxxxxx>
# Date 1271091282 -3600
# Node ID 06f4d30cef5f458c7b2cf8b47427424c9948db4f
# Parent da78a9af0fdf61ad133a0c04d96d7eb286a94cdb
CA-40149: Add an explicit cache of the local hostname and make it posible to
invalidate the cache.
The hostname is included in every log line.
Signed-off-by: David Scott <dave.scott@xxxxxxxxxxxxx>
diff -r da78a9af0fdf -r 06f4d30cef5f log/debug.ml
--- a/log/debug.ml Fri Apr 09 10:49:50 2010 +0100
+++ b/log/debug.ml Mon Apr 12 17:54:42 2010 +0100
@@ -21,11 +21,6 @@
let get_thread_id () =
try Thread.id (Thread.self ()) with _ -> -1
-
-(* Theses functions need to be defined later in the code. *)
-let get_hostname =
- let f () = "Debug.get_hostname not set" in
- ref f
let associate_thread_with_task task =
let id = get_thread_id () in
@@ -81,8 +76,18 @@
val name: string
end
+let hostname_cache = ref None
+let hostname_m = Mutex.create ()
+let get_hostname () =
+ match Mutex.execute hostname_m (fun () -> !hostname_cache) with
+ | Some h -> h
+ | None ->
+ let h = Unix.gethostname () in
+ Mutex.execute hostname_m (fun () -> hostname_cache := Some h);
+ h
+let invalidate_hostname_cache () = Mutex.execute hostname_m (fun () ->
hostname_cache := None)
+
module Debugger = functor(Brand: BRAND) -> struct
- let hostname = Unix.gethostname ()
let _ =
Mutex.execute dkmutex (fun () ->
debug_keys := StringSet.add Brand.name !debug_keys)
@@ -102,7 +107,7 @@
let output (f:string -> ?extra:string -> ('a, unit, string, 'b) format4 ->
'a) fmt =
let extra =
Printf.sprintf "%s|%s|%s|%s"
- hostname
+ (get_hostname ())
(get_thread_name ())
(get_task ())
Brand.name
@@ -112,7 +117,7 @@
let output_and_return ?raw (f:string -> ?raw:bool -> ?extra:string ->
('a, unit, string, 'b) format4 -> 'a) fmt =
let extra =
Printf.sprintf "%s|%s|%s|%s"
- hostname
+ (get_hostname ())
(get_thread_name ())
(get_task ())
Brand.name
diff -r da78a9af0fdf -r 06f4d30cef5f log/debug.mli
--- a/log/debug.mli Fri Apr 09 10:49:50 2010 +0100
+++ b/log/debug.mli Mon Apr 12 17:54:42 2010 +0100
@@ -13,6 +13,9 @@
*)
(** Debug utilities *)
+
+(** Throw away the cached hostname. The next log line will re-query the
hostname *)
+val invalidate_hostname_cache: unit -> unit
(** {2 Associate a task to the current actions} *)
2 files changed, 16 insertions(+), 8 deletions(-)
log/debug.ml | 21 +++++++++++++--------
log/debug.mli | 3 +++
xen-api-libs.hg.patch
Description: Text Data
_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api
|