Skip to content

Commit 10a1175

Browse files
authored
Merge pull request #209 from lindig/CA-285213
CA-285213 add error logging to memory interface
2 parents df830c5 + 5b3fbc3 commit 10a1175

File tree

4 files changed

+113
-29
lines changed

4 files changed

+113
-29
lines changed

gpumon/gpumon_interface.ml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
open Rpc
1616
open Idl
1717

18+
module D = Debug.Make(struct let name = "gpumon_interface" end)
19+
open D
20+
1821
let service_name = "gpumon"
1922
let queue_name = Xcp_service.common_prefix ^ service_name
2023
let xml_path = "/var/xapi/" ^ service_name
@@ -73,14 +76,32 @@ type gpu_errors =
7376

7477
exception Gpumon_error of gpu_errors
7578

79+
let () = (* register printer *)
80+
let sprintf = Printf.sprintf in
81+
let string_of_error e =
82+
Rpcmarshal.marshal gpu_errors.Rpc.Types.ty e |> Rpc.to_string in
83+
let printer = function
84+
| Gpumon_error e ->
85+
Some (sprintf "Gpumon_interface.Gpumon_error(%s)" (string_of_error e))
86+
| _ -> None in
87+
Printexc.register_printer printer
88+
7689
(** Error handler *)
77-
let gpu_err = Error.{
78-
def = gpu_errors;
79-
raiser = (fun e -> raise (Gpumon_error e));
80-
matcher = (function
81-
| Gpumon_error e -> Some e
82-
| e -> Some (Internal_error (Printexc.to_string e)))
83-
}
90+
let gpu_err = Error.
91+
{ def = gpu_errors
92+
; raiser = (fun e ->
93+
log_backtrace ();
94+
let exn = Gpumon_error e in
95+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
96+
raise exn)
97+
; matcher = (function
98+
| Gpumon_error e as exn ->
99+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
100+
Some e
101+
| exn ->
102+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
103+
Some (Internal_error (Printexc.to_string exn)))
104+
}
84105

85106
(** Functor to autogenerate API calls *)
86107
module RPC_API(R : RPC) = struct

memory/memory_interface.ml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
open Rpc
1818
open Idl
1919

20+
module D = Debug.Make(struct let name = "memory_interface" end)
21+
open D
22+
2023
let service_name = "memory"
2124
let queue_name = Xcp_service.common_prefix ^ service_name
2225
let json_path = "/var/xapi/memory.json"
@@ -75,13 +78,31 @@ type errors =
7578

7679
exception MemoryError of errors
7780

78-
let err = Error.{
79-
def = errors;
80-
raiser = (fun e -> raise (MemoryError e));
81-
matcher = (function
82-
| MemoryError e -> Some e
83-
| e -> Some (Internal_error (Printexc.to_string e)))
84-
}
81+
let () = (* register printer for MemoryError *)
82+
let sprintf = Printf.sprintf in
83+
let string_of_error e =
84+
Rpcmarshal.marshal errors.Rpc.Types.ty e |> Rpc.to_string in
85+
let printer = function
86+
| MemoryError e ->
87+
Some (sprintf "Memory_interface.Memory_error(%s)" (string_of_error e))
88+
| _ -> None in
89+
Printexc.register_printer printer
90+
91+
let err = Error.
92+
{ def = errors
93+
; raiser = (fun e ->
94+
log_backtrace ();
95+
let exn = MemoryError e in
96+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
97+
raise exn)
98+
; matcher = (function
99+
| MemoryError e as exn ->
100+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
101+
Some e
102+
| exn ->
103+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
104+
Some (Internal_error (Printexc.to_string exn)))
105+
}
85106

86107
type debug_info = string
87108
[@@doc ["An uninterpreted string associated with the operation."]]

network/network_interface.ml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
open Rpc
1515
open Idl
1616

17+
module D = Debug.Make(struct let name = "network_interface" end)
18+
open D
19+
1720
(** {2 Helper functions} *)
1821

1922
let service_name = "networkd"
@@ -224,13 +227,31 @@ type errors =
224227

225228
exception Network_error of errors
226229

227-
let err = Error.{
228-
def = errors;
229-
raiser = (function | e -> raise (Network_error e));
230-
matcher = (function
231-
| Network_error e -> Some e
232-
| e -> Some (Internal_error (Printexc.to_string e)))
233-
}
230+
let () = (* register printer *)
231+
let sprintf = Printf.sprintf in
232+
let string_of_error e =
233+
Rpcmarshal.marshal errors.Rpc.Types.ty e |> Rpc.to_string in
234+
let printer = function
235+
| Network_error e ->
236+
Some (sprintf "Network_interface.Network_error(%s)" (string_of_error e))
237+
| _ -> None in
238+
Printexc.register_printer printer
239+
240+
let err = Error.
241+
{ def = errors
242+
; raiser = (fun e ->
243+
log_backtrace ();
244+
let exn = Network_error e in
245+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
246+
raise exn)
247+
; matcher = (function
248+
| Network_error e as exn ->
249+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
250+
Some e
251+
| exn ->
252+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
253+
Some (Internal_error (Printexc.to_string exn)))
254+
}
234255

235256
(** {2 API functions} *)
236257

v6/v6_interface.ml

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
open Rpc
1919
open Idl
2020

21+
module D = Debug.Make(struct let name = "v6_interface" end)
22+
open D
23+
2124
let service_name = "v6d"
2225
let queue_name = ref (Xcp_service.common_prefix ^ service_name)
2326
let default_sockets_dir = "/var/lib/xcp"
@@ -91,15 +94,33 @@ type errors =
9194
exception V6_error of errors
9295
[@@deriving rpcty]
9396

94-
(** handle exception generation and raising *)
95-
let err = Error.{
96-
def = errors;
97-
raiser = (fun e -> raise (V6_error e));
98-
matcher = (function
99-
| V6_error e -> Some e
100-
| e -> Some (Internal_error (Printexc.to_string e)))
101-
}
10297

98+
let () = (* register printer *)
99+
let sprintf = Printf.sprintf in
100+
let string_of_error e =
101+
Rpcmarshal.marshal errors.Rpc.Types.ty e |> Rpc.to_string in
102+
let printer = function
103+
| V6_error e ->
104+
Some (sprintf "V6_interface.V6_error(%s)" (string_of_error e))
105+
| _ -> None in
106+
Printexc.register_printer printer
107+
108+
(** handle exception generation and raising *)
109+
let err = Error.
110+
{ def = errors
111+
; raiser = (fun e ->
112+
log_backtrace ();
113+
let exn = V6_error e in
114+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
115+
raise exn)
116+
; matcher = (function
117+
| V6_error e as exn ->
118+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
119+
Some e
120+
| exn ->
121+
error "%s (%s)" (Printexc.to_string exn) __LOC__;
122+
Some (Internal_error (Printexc.to_string exn)))
123+
}
103124

104125
(** functor to autogenerate code using PPX *)
105126
module RPC_API(R : RPC) = struct

0 commit comments

Comments
 (0)