Skip to content

Commit d242e7d

Browse files
committed
No redundant output
1 parent 7188583 commit d242e7d

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

crates/observe/src/heap_dump_handler.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,25 @@ async fn handle_connection(listener: &UnixListener) {
6161
return;
6262
};
6363

64-
let _ = socket
65-
.write_all(b"heap dump handler ready. send 'dump' to generate profile\n")
66-
.await;
67-
6864
loop {
6965
let message = read_line(&mut socket).await;
7066

7167
match message.as_deref() {
7268
Some("") => {
73-
log(&mut socket, "client terminated connection".into()).await;
69+
tracing::debug!("client terminated connection");
7470
break;
7571
}
7672
None => {
77-
log(&mut socket, "failed to read message from socket".into()).await;
78-
continue;
73+
tracing::warn!("failed to read message from socket");
74+
break;
7975
}
8076
Some("dump") => {
8177
generate_and_stream_dump(&mut socket).await;
8278
break; // Close connection after sending dump
8379
}
8480
Some(unknown) => {
85-
log(
86-
&mut socket,
87-
format!("unknown command: {unknown:?}. use 'dump'"),
88-
)
89-
.await;
81+
tracing::warn!(?unknown, "unknown command received");
82+
break;
9083
}
9184
}
9285
}
@@ -99,9 +92,7 @@ async fn generate_and_stream_dump(socket: &mut UnixStream) {
9992
let prof_ctl = match jemalloc_pprof::PROF_CTL.as_ref() {
10093
Some(ctl) => ctl,
10194
None => {
102-
let error_msg = "jemalloc profiling not initialized\n";
103-
tracing::error!(error_msg);
104-
let _ = socket.write_all(error_msg.as_bytes()).await;
95+
tracing::error!("jemalloc profiling not initialized");
10596
return;
10697
}
10798
};
@@ -120,9 +111,7 @@ async fn generate_and_stream_dump(socket: &mut UnixStream) {
120111
}
121112
}
122113
Err(e) => {
123-
let error_msg = format!("error generating heap dump: {e:?}\n");
124114
tracing::error!(error = ?e, "failed to generate heap dump");
125-
let _ = socket.write_all(error_msg.as_bytes()).await;
126115
}
127116
}
128117
}
@@ -133,11 +122,3 @@ async fn read_line(socket: &mut UnixStream) -> Option<String> {
133122
reader.read_line(&mut buffer).await.ok()?;
134123
Some(buffer.trim().to_owned())
135124
}
136-
137-
/// Logs the message in this process' logs and reports it back to the
138-
/// connected socket.
139-
async fn log(socket: &mut UnixStream, message: String) {
140-
tracing::warn!(message);
141-
let _ = socket.write_all(message.as_bytes()).await;
142-
let _ = socket.write_all(b"\n").await;
143-
}

0 commit comments

Comments
 (0)