Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid marshalling every packet to a string when not in debug mode #26

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/s.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ open Result
module type LOG = sig
(** Common logging functions *)

(** Performance hack to avoid generating too many strings if we aren't going
to print them. *)
val print_debug: bool ref

val debug : ('a, Format.formatter, unit, unit) format4 -> 'a
val info : ('a, Format.formatter, unit, unit) format4 -> 'a
val error : ('a, Format.formatter, unit, unit) format4 -> 'a
Expand Down
4 changes: 2 additions & 2 deletions lib/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module Make(Log: S.LOG)(FLOW: V1_LWT.FLOW) = struct
let after_disconnect t = t.shutdown_complete_t

let write_one_packet ?write_lock writer response =
debug "S %a" Response.pp response;
if !Log.print_debug then debug "S %a" Response.pp response;
let sizeof = Response.sizeof response in
let buffer = Cstruct.create sizeof in
Lwt.return (Response.write response buffer)
Expand All @@ -84,7 +84,7 @@ module Make(Log: S.LOG)(FLOW: V1_LWT.FLOW) = struct
| Error (`Msg ename) ->
Error (`Parse (ename, buffer))
| Ok (request, _) ->
debug "C %a" Request.pp request;
if !Log.print_debug then debug "C %a" Request.pp request;
Ok request
end

Expand Down