[Pyroscope] Client Setup: Rust
Rust ํ๊ฒฝ์์ Pyroscope Client๋ฅผ ์ค์ ํ๋ ๋ฐฉ๋ฒ์ ๋ค๋ฃฌ๋ค.
๊ด๋ จ ํฌ์คํธ
https://blog.naver.com/sssang97/223415589139
์ ํ์ฌํญ
Rust์ ํ๋กํ์ผ๋ง์ ์ฃผ๋ก pprof-rs๋ฅผ ํตํด ์ด๋ฃจ์ด์ง๋ค.
๊ฑฐ์ Linux ํ๊ฒฝ์์๋ง ์ ๋๋ก ์ฌ์ฉ์ด ๊ฐ๋ฅํ๋ค.
๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉ๋ ๋ชจ๋ํฐ๋ง์ ์์ง ์ง์๋๋๊ฒ ์๋ ๋ชจ์์ด๋ค.
์ค์น
ํ์ํ ์ข
์์ฑ์ 2๊ฐ์ง๋ค.
์ค์นํด์ค๋ค.
cargo add pyroscope
cargo add pyroscope_pprofrs

์ด์ ๋๋ค.
์ฝ๋ ๊ตฌ์ฑ
์๋์ ๊ฐ์ axum ์๋ฒ ์ฝ๋์ pyroscope ํด๋ผ์ด์ธํธ๋ฅผ ๊ตฌ์ฑํด๋ณด๊ฒ ๋ค.

์ฝ๋ ํํ๋ ๋๋ต ๋ค์๊ณผ ๊ฐ๋ค.
fn setup_pyroscope() {
use pyroscope::PyroscopeAgent;
use pyroscope_pprofrs::{pprof_backend, PprofConfig};
// Configure profiling backend
let pprof_config = PprofConfig::new().sample_rate(100);
let backend_impl = pprof_backend(pprof_config);
// Configure Pyroscope Agent
let agent = PyroscopeAgent::builder("http://localhost:4040", "myapp")
.backend(backend_impl)
.build()
.unwrap();
agent.start().unwrap();
}
pprof ์ํ ์ฃผ๊ธฐ๋ฅผ ์ง์ ํ๊ณ , pyroscope ์๋ฒ์ ์ฑ ์ด๋ฆ์ ์ ํด์ ๋ฃ์ด์ฃผ๋ฉด ๋๋ค.
๊ทธ๋ฆฌ๊ณ start๋ก ์คํํ๋ค. ์ด ํจ์๋ nonblock์ด๋ผ์ ๊ฐ์ฅ ๋จผ์ ์คํํ๋ฉด ๋๋ค.
์ด๋ ๊ฒ
ํ์ธ
ํด๋ผ์ด์ธํธ ์์ฑ์ด ์ ๋๋ก ๋์๋ค๋ฉด ์คํ ์ดํ์ ์๋์ ๊ฐ์ด ํญ์ด ์์ฑ๋ ๊ฒ์ด๋ค.
์งํ๊ฐ ํ๋๋ฟ์ด๋ผ ์ข ๋จ์ถํ ํธ์ด๋ค.
๊ทธ๋ฆฌ๊ณ API๋ฅผ ๋ช๋ฒ ๋ ๋ ค๋ณด๋ฉด

์ด๋ ๊ฒ ๋ฐ์ดํฐ๋ค์ด ์์ธ๋ค.

์ข ์์ธํ ๋ณด๋ฉด
tokio:axum์ด ๋น๋๊ธฐ ํธ์ถ ์คํ๋๋ฌธ์ ์ข ๋ณด๊ธฐ๊ฐ ํ๋ ๋ถ๋ถ์ด ์๋๋ฐ, ์๋ฌดํผ ๋ณ๋ชฉ์ผ๋ก ์กํ๋ heavy ํจ์ ์์ฒด๋ ์ถ์ ์ด ๋๋ค.
์ด๋ ๊ฒ ์จ๋จน์ผ๋ฉด ๋๋ค.
์ฐธ์กฐ
https://grafana.com/docs/pyroscope/latest/configure-client/language-sdks/rust/