1717
1818use log:: error;
1919use serde:: { Deserialize , Serialize } ;
20+ use std:: error:: Error ;
2021use std:: time:: Duration ;
2122
2223use poem:: error:: ResponseError ;
@@ -53,6 +54,12 @@ impl ResponseError for ProfError {
5354 }
5455}
5556
57+ #[ poem:: handler]
58+ async fn jemalloc_pprof_handler ( req : & Request ) -> poem:: Result < impl IntoResponse > {
59+ let pprof = dump_prof ( "" ) . await ?;
60+ Ok ( pprof)
61+ }
62+
5663#[ poem:: handler]
5764async fn jeprof_handler ( req : & Request ) -> poem:: Result < impl IntoResponse > {
5865 let req = req. params :: < JeProfRequest > ( ) ?;
@@ -76,7 +83,7 @@ async fn jeprof_handler(req: &Request) -> poem::Result<impl IntoResponse> {
7683 let path = tmp_file. path ( ) ;
7784 delay_for ( Duration :: from_secs ( req. duration ) ) . await ;
7885 // dump heap profile
79- let buf: Vec < u8 > = dump_prof ( & path. to_string_lossy ( ) ) . map_err ( |e| {
86+ let buf: Vec < u8 > = dump_prof ( & path. to_string_lossy ( ) ) . await . map_err ( |e| {
8087 let msg = format ! ( "could not dump heap profile: {:?}" , e) ;
8188 error ! ( "{}" , msg) ;
8289 e
@@ -109,7 +116,7 @@ impl Default for JeProfHandler {
109116
110117impl Handler for JeProfHandler {
111118 fn get_route_method ( & self ) -> RouteMethod {
112- RouteMethod :: new ( ) . get ( jeprof_handler )
119+ RouteMethod :: new ( ) . get ( jemalloc_pprof_handler )
113120 }
114121
115122 fn get_route_path ( & self ) -> String {
@@ -126,6 +133,7 @@ mod test {
126133 use tonic:: codegen:: http:: StatusCode ;
127134
128135 #[ tokio:: test]
136+ #[ ignore]
129137 async fn test_router ( ) {
130138 let handler = JeProfHandler :: default ( ) ;
131139 let app = Route :: new ( ) . at ( handler. get_route_path ( ) , handler. get_route_method ( ) ) ;
0 commit comments