Skip to content

Commit

Permalink
Add thread execution timing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
nholland94 committed Mar 3, 2022
1 parent 6badc1d commit 2b746ee
Show file tree
Hide file tree
Showing 30 changed files with 1,869 additions and 1,549 deletions.
2 changes: 1 addition & 1 deletion scripts/pin-external-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# update and pin packages, used by CI

PACKAGES="ocaml-sodium capnp-ocaml rpc_parallel ocaml-extlib async_kernel coda_base58 graphql_ppx ppx_deriving_yojson"
PACKAGES="ocaml-sodium capnp-ocaml rpc_parallel ocaml-extlib async_kernel async_unix coda_base58 graphql_ppx ppx_deriving_yojson"

git submodule sync && git submodule update --init --recursive

Expand Down
153 changes: 79 additions & 74 deletions src/app/cli/src/init/coda_run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -491,86 +491,91 @@ let setup_local_server ?(client_trustlist = []) ?rest_server_port
server_description port)
in
Option.iter rest_server_port ~f:(fun rest_server_port ->
trace_task "full GraphQL server" (fun () ->
create_graphql_server
~bind_to_address:
Tcp.Bind_to_address.(
if insecure_rest_server then All_addresses else Localhost)
~schema:Mina_graphql.schema ~server_description:"GraphQL server"
rest_server_port)) ;
O1trace.time_execution "serving_graphql" (fun () ->
trace_task "full GraphQL server" (fun () ->
create_graphql_server
~bind_to_address:
Tcp.Bind_to_address.(
if insecure_rest_server then All_addresses else Localhost)
~schema:Mina_graphql.schema ~server_description:"GraphQL server"
rest_server_port))) ;
(*Second graphql server with limited queries exopsed*)
Option.iter limited_graphql_port ~f:(fun rest_server_port ->
trace_task "limited GraphQL server" (fun () ->
create_graphql_server
~bind_to_address:
Tcp.Bind_to_address.(
if open_limited_graphql_port then All_addresses else Localhost)
~schema:Mina_graphql.schema_limited
~server_description:"GraphQL server with limited queries"
rest_server_port)) ;
O1trace.time_execution "serving_graphql" (fun () ->
trace_task "limited GraphQL server" (fun () ->
create_graphql_server
~bind_to_address:
Tcp.Bind_to_address.(
if open_limited_graphql_port then All_addresses
else Localhost)
~schema:Mina_graphql.schema_limited
~server_description:"GraphQL server with limited queries"
rest_server_port))) ;
let where_to_listen =
Tcp.Where_to_listen.bind_to All_addresses
(On_port (Mina_lib.client_port coda))
in
trace_task "client RPC server" (fun () ->
Deferred.ignore_m
(Tcp.Server.create
~on_handler_error:
(`Call
(fun _net exn ->
[%log error]
"Exception while handling TCP server request: $error"
~metadata:
[ ("error", `String (Exn.to_string_mach exn))
; ("context", `String "rpc_tcp_server")
]))
where_to_listen
(fun address reader writer ->
let address = Socket.Address.Inet.addr address in
if
not
(Set.exists !client_trustlist ~f:(fun cidr ->
Unix.Cidr.does_match cidr address))
then (
[%log error]
!"Rejecting client connection from $address, it is not \
present in the trustlist."
~metadata:
[ ("$address", `String (Unix.Inet_addr.to_string address)) ] ;
Deferred.unit )
else
Rpc.Connection.server_with_close
~handshake_timeout:
(Time.Span.of_sec
Mina_compile_config.rpc_handshake_timeout_sec)
~heartbeat_config:
(Rpc.Connection.Heartbeat_config.create
~timeout:
(Time_ns.Span.of_sec
Mina_compile_config.rpc_heartbeat_timeout_sec)
~send_every:
(Time_ns.Span.of_sec
Mina_compile_config.rpc_heartbeat_send_every_sec)
())
reader writer
~implementations:
(Rpc.Implementations.create_exn
~implementations:(client_impls @ snark_worker_impls)
~on_unknown_rpc:`Raise)
~connection_state:(fun _ -> ())
~on_handshake_error:
(`Call
(fun exn ->
[%log warn]
"Handshake error while handling RPC server request \
from $address"
~metadata:
[ ("error", `String (Exn.to_string_mach exn))
; ("context", `String "rpc_server")
; ( "address"
, `String (Unix.Inet_addr.to_string address) )
] ;
Deferred.unit)))))
O1trace.time_execution "serving_client_rpcs" (fun () ->
trace_task "client RPC server" (fun () ->
Deferred.ignore_m
(Tcp.Server.create
~on_handler_error:
(`Call
(fun _net exn ->
[%log error]
"Exception while handling TCP server request: $error"
~metadata:
[ ("error", `String (Exn.to_string_mach exn))
; ("context", `String "rpc_tcp_server")
]))
where_to_listen
(fun address reader writer ->
let address = Socket.Address.Inet.addr address in
if
not
(Set.exists !client_trustlist ~f:(fun cidr ->
Unix.Cidr.does_match cidr address))
then (
[%log error]
!"Rejecting client connection from $address, it is not \
present in the trustlist."
~metadata:
[ ("$address", `String (Unix.Inet_addr.to_string address))
] ;
Deferred.unit )
else
Rpc.Connection.server_with_close
~handshake_timeout:
(Time.Span.of_sec
Mina_compile_config.rpc_handshake_timeout_sec)
~heartbeat_config:
(Rpc.Connection.Heartbeat_config.create
~timeout:
(Time_ns.Span.of_sec
Mina_compile_config.rpc_heartbeat_timeout_sec)
~send_every:
(Time_ns.Span.of_sec
Mina_compile_config.rpc_heartbeat_send_every_sec)
())
reader writer
~implementations:
(Rpc.Implementations.create_exn
~implementations:(client_impls @ snark_worker_impls)
~on_unknown_rpc:`Raise)
~connection_state:(fun _ -> ())
~on_handshake_error:
(`Call
(fun exn ->
[%log warn]
"Handshake error while handling RPC server \
request from $address"
~metadata:
[ ("error", `String (Exn.to_string_mach exn))
; ("context", `String "rpc_server")
; ( "address"
, `String (Unix.Inet_addr.to_string address) )
] ;
Deferred.unit))))))

let coda_crash_message ~log_issue ~action ~error =
let followup =
Expand Down
2 changes: 1 addition & 1 deletion src/app/cli/src/init/coda_tracing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ open Async

(** [start dir] starts writing the trace output to [dir ^/ "trace" ^/(current_pid ^ ".trace")]. *)
let start dir =
O1trace_webkit_event.forget_tid (fun () ->
O1trace.forget_tid (fun () ->
let trace_dir = dir ^/ "trace" in
let%bind () = File_system.create_dir trace_dir in
Writer.open_file ~append:true
Expand Down
4 changes: 2 additions & 2 deletions src/app/libp2p_helper/src/libp2p_helper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func main() {
Format: logging.JSONOutput,
Stderr: true,
Stdout: false,
Level: logging.LevelDebug,
Level: logging.LevelWarn,
File: "",
})
helperLog := logging.Logger("helper top-level JSON handling")
Expand Down Expand Up @@ -133,7 +133,7 @@ func main() {
setLogLevel("autonat", "debug")
setLogLevel("discovery", "debug")
setLogLevel("routing/record", "debug")
setLogLevel("pubsub", "debug") // Spammy about blacklisted peers, maybe should be info?
setLogLevel("pubsub", "info")
setLogLevel("badger", "debug")
setLogLevel("relay", "info") // Log relayed byte counts spammily
setLogLevel("routedhost", "debug")
Expand Down
2 changes: 1 addition & 1 deletion src/external/async_kernel
10 changes: 7 additions & 3 deletions src/lib/child_processes/child_processes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -258,16 +258,20 @@ let start_custom :
in
let terminated_ivar = Ivar.create () in
let stdout_pipe =
reader_to_strict_pipe (Process.stdout process) (name ^ "-stdout") stdout
O1trace.time_execution "in_libp2p_child_processes_stdout" (fun () ->
reader_to_strict_pipe (Process.stdout process) (name ^ "-stdout") stdout)
in
let stderr_pipe =
reader_to_strict_pipe (Process.stderr process) (name ^ "-stderr") stderr
O1trace.time_execution "in_libp2p_child_processes_stderr" (fun () ->
reader_to_strict_pipe (Process.stderr process) (name ^ "-stderr") stderr)
in
let t =
{ process
; stdout_pipe
; stderr_pipe
; stdin = Process.stdin process
; stdin =
O1trace.time_execution "in_libp2p_child_processes_stdin" (fun () ->
Process.stdin process)
; terminated_ivar
; killing = false
; termination_response = termination
Expand Down
Loading

0 comments on commit 2b746ee

Please sign in to comment.