11//! Context and its utilities of server
22
3+ use chrono:: { DateTime , Local } ;
34use volo:: {
45 context:: { Context , Reusable , Role , RpcCx , RpcInfo } ,
56 net:: Address ,
@@ -8,7 +9,7 @@ use volo::{
89
910use crate :: {
1011 server:: param:: PathParamsVec ,
11- utils:: macros:: { impl_deref_and_deref_mut, impl_getter} ,
12+ utils:: macros:: { impl_deref_and_deref_mut, impl_getter, stat_impl } ,
1213} ;
1314
1415/// RPC context of http server
@@ -44,10 +45,38 @@ pub struct ServerCxInner {
4445 /// [`PathParamsMap`]: crate::server::param::PathParamsMap
4546 /// [`PathParams`]: crate::server::param::PathParams
4647 pub params : PathParamsVec ,
48+
49+ /// Statistics of the request
50+ pub stats : ServerStats ,
4751}
4852
4953impl ServerCxInner {
5054 impl_getter ! ( params, PathParamsVec ) ;
55+ impl_getter ! ( stats, ServerStats ) ;
56+ }
57+
58+ /// Statistics of server
59+ #[ derive( Debug , Default , Clone ) ]
60+ pub struct ServerStats {
61+ read_header_start : Option < DateTime < Local > > ,
62+ read_header_finish : Option < DateTime < Local > > ,
63+ read_body_start : Option < DateTime < Local > > ,
64+ read_body_finish : Option < DateTime < Local > > ,
65+ handle_start : Option < DateTime < Local > > ,
66+ handle_finish : Option < DateTime < Local > > ,
67+ write_start : Option < DateTime < Local > > ,
68+ write_finish : Option < DateTime < Local > > ,
69+ }
70+
71+ impl ServerStats {
72+ stat_impl ! ( read_header_start) ;
73+ stat_impl ! ( read_header_finish) ;
74+ stat_impl ! ( read_body_start) ;
75+ stat_impl ! ( read_body_finish) ;
76+ stat_impl ! ( handle_start) ;
77+ stat_impl ! ( handle_finish) ;
78+ stat_impl ! ( write_start) ;
79+ stat_impl ! ( write_finish) ;
5180}
5281
5382/// Configuration of the request
0 commit comments